Skip to content

Commit 637754e

Browse files
committed
升级sdk版本为2.6.0
1 parent acd855b commit 637754e

File tree

3 files changed

+43
-25
lines changed

3 files changed

+43
-25
lines changed

pom.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<plugin.maven-compiler>3.1</plugin.maven-compiler>
1919

2020
<!-- lib versions -->
21-
<weixin-java-mp.version>2.4.5.BETA</weixin-java-mp.version>
21+
<weixin-java-tools.version>2.6.0</weixin-java-tools.version>
2222
<junit.version>4.12</junit.version>
2323
<slf4j.version>1.7.21</slf4j.version>
2424
<spring.version>4.2.6.RELEASE</spring.version>
@@ -119,7 +119,13 @@
119119
<dependency>
120120
<groupId>com.github.binarywang</groupId>
121121
<artifactId>weixin-java-mp</artifactId>
122-
<version>${weixin-java-mp.version}</version>
122+
<version>${weixin-java-tools.version}</version>
123+
</dependency>
124+
125+
<dependency>
126+
<groupId>com.github.binarywang</groupId>
127+
<artifactId>weixin-java-pay</artifactId>
128+
<version>${weixin-java-tools.version}</version>
123129
</dependency>
124130

125131
<!-- junit -->

src/main/java/com/github/config/MainConfig.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.github.config;
22

3+
import com.github.binarywang.wxpay.config.WxPayConfig;
4+
import com.github.binarywang.wxpay.service.WxPayService;
5+
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
36
import org.springframework.beans.factory.annotation.Value;
47
import org.springframework.context.annotation.Bean;
58
import org.springframework.context.annotation.Configuration;
@@ -66,8 +69,15 @@ public WxMpConfigStorage wxMpConfigStorage() {
6669
configStorage.setSecret(this.appsecret);
6770
configStorage.setToken(this.token);
6871
configStorage.setAesKey(this.aesKey);
69-
configStorage.setPartnerId(this.partenerId);
70-
configStorage.setPartnerKey(this.partenerKey);
72+
return configStorage;
73+
}
74+
75+
@Bean
76+
public WxPayConfig payConfig() {
77+
WxPayConfig configStorage = new WxPayConfig();
78+
configStorage.setAppId(this.appid);
79+
configStorage.setMchId(this.partenerId);
80+
configStorage.setMchKey(this.partenerKey);
7181
return configStorage;
7282
}
7383

@@ -78,4 +88,11 @@ public WxMpService wxMpService() {
7888
return wxMpService;
7989
}
8090

91+
@Bean
92+
public WxPayService payService() {
93+
WxPayService payService = new WxPayServiceImpl();
94+
payService.setConfig(payConfig());
95+
return payService;
96+
}
97+
8198
}

src/main/java/com/github/controller/PaymentController.java

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package 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;
48
import com.github.util.MD5Util;
59
import com.github.util.ReturnModel;
610
import com.github.util.Sha1Util;
711
import com.github.util.XMLUtil;
812
import com.google.gson.Gson;
913
import 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;
1414
import org.apache.http.HttpEntity;
1515
import org.apache.http.client.methods.CloseableHttpResponse;
1616
import org.apache.http.client.methods.HttpPost;
@@ -48,18 +48,15 @@
4848
@Controller
4949
@RequestMapping(value = "wxPay")
5050
public 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

Comments
 (0)