11package com .github .controller ;
22
3- import com .github .service .CoreService ;
3+ import com .github .binarywang .wxpay .bean .request .WxPayUnifiedOrderRequest ;
4+ import com .github .binarywang .wxpay .bean .result .WxPayUnifiedOrderResult ;
5+ import com .github .binarywang .wxpay .config .WxPayConfig ;
6+ import com .github .binarywang .wxpay .service .WxPayService ;
7+ import com .github .binarywang .wxpay .util .SignUtils ;
48import com .github .util .MD5Util ;
59import com .github .util .ReturnModel ;
610import com .github .util .Sha1Util ;
711import com .github .util .XMLUtil ;
812import com .google .gson .Gson ;
913import me .chanjar .weixin .common .exception .WxErrorException ;
10- import me .chanjar .weixin .mp .api .WxMpConfigStorage ;
11- import me .chanjar .weixin .mp .api .WxMpService ;
12- import me .chanjar .weixin .mp .bean .pay .request .WxPayUnifiedOrderRequest ;
13- import me .chanjar .weixin .mp .bean .pay .result .WxPayUnifiedOrderResult ;
1414import org .apache .http .HttpEntity ;
1515import org .apache .http .client .methods .CloseableHttpResponse ;
1616import org .apache .http .client .methods .HttpPost ;
4848@ Controller
4949@ RequestMapping (value = "wxPay" )
5050public class PaymentController extends GenericController {
51-
52-
5351 //企业向个人转账微信API路径
5452 private static final String ENTERPRISE_PAY_URL = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers" ;
5553 //apiclient_cert.p12证书存放路径
5654 private static final String CERTIFICATE_LOCATION = "" ;
55+
5756 @ Autowired
58- protected WxMpConfigStorage configStorage ;
59- @ Autowired
60- protected WxMpService wxMpService ;
57+ protected WxPayConfig payConfig ;
6158 @ Autowired
62- protected CoreService coreService ;
59+ protected WxPayService payService ;
6360
6461 /**
6562 * 用于返回预支付的结果 WxMpPrepayIdResult,一般不需要使用此接口
@@ -80,9 +77,8 @@ public void getPrepayId(HttpServletResponse response,
8077 payInfo .setSpbillCreateIp (request .getParameter ("spbill_create_ip" ));
8178 payInfo .setNotifyURL ("" );
8279 this .logger
83- .info ("PartnerKey is :" + this .configStorage .getPartnerKey ());
84- WxPayUnifiedOrderResult result = this .wxMpService .getPayService ()
85- .unifiedOrder (payInfo );
80+ .info ("PartnerKey is :" + this .payConfig .getMchKey ());
81+ WxPayUnifiedOrderResult result = this .payService .unifiedOrder (payInfo );
8682 this .logger .info (new Gson ().toJson (result ));
8783 renderString (response , result );
8884 }
@@ -109,8 +105,7 @@ public void getJSSDKPayInfo(HttpServletResponse response,
109105 prepayInfo .setNotifyURL ("" );
110106
111107 try {
112- Map <String , String > payInfo = this .wxMpService .getPayService ()
113- .getPayInfo (prepayInfo );
108+ Map <String , String > payInfo = this .payService .getPayInfo (prepayInfo );
114109 returnModel .setResult (true );
115110 returnModel .setDatum (payInfo );
116111 renderString (response , returnModel );
@@ -134,8 +129,8 @@ public void getJSSDKCallbackData(HttpServletRequest request,
134129 try {
135130 synchronized (this ) {
136131 Map <String , String > kvm = XMLUtil .parseRequestXmlToMap (request );
137- if (this . wxMpService . getPayService () .checkSign (kvm ,
138- configStorage . getPartnerKey ())) {
132+ if (SignUtils .checkSign (kvm ,
133+ this . payConfig . getMchKey ())) {
139134 if (kvm .get ("result_code" ).equals ("SUCCESS" )) {
140135 //TODO(user) 微信服务器通知此回调接口支付成功后,通知给业务系统做处理
141136 logger .info ("out_trade_no: " + kvm .get ("out_trade_no" ) + " pay SUCCESS!" );
@@ -162,8 +157,8 @@ public void getJSSDKCallbackData(HttpServletRequest request,
162157 public void payToIndividual (HttpServletResponse response ,
163158 HttpServletRequest request ) {
164159 TreeMap <String , String > map = new TreeMap <String , String >();
165- map .put ("mch_appid" , this .configStorage .getAppId ());
166- map .put ("mchid" , this .configStorage . getPartnerId ());
160+ map .put ("mch_appid" , this .payConfig .getAppId ());
161+ map .put ("mchid" , this .payConfig . getMchId ());
167162 map .put ("nonce_str" , Sha1Util .getNonceStr ());
168163 map .put ("partner_trade_no" , request .getParameter ("partner_trade_no" ));
169164 map .put ("openid" , request .getParameter ("openid" ));
@@ -173,7 +168,7 @@ public void payToIndividual(HttpServletResponse response,
173168 map .put ("spbill_create_ip" , request .getParameter ("spbill_create_ip" ));
174169 try {
175170 Map <String , String > returnMap = enterprisePay (map ,
176- this .configStorage . getPartnerKey (), CERTIFICATE_LOCATION ,
171+ this .payConfig . getMchKey (), CERTIFICATE_LOCATION ,
177172 ENTERPRISE_PAY_URL );
178173 if ("SUCCESS" .equals (returnMap .get ("result_code" ).toUpperCase ())
179174 && "SUCCESS"
0 commit comments