Skip to content

Commit 1b10bbd

Browse files
committed
微信V3版本接入直连接口,自测通过
1 parent b731154 commit 1b10bbd

21 files changed

Lines changed: 1025 additions & 62 deletions

File tree

pay-java-common/src/main/java/com/egzosn/pay/common/api/BasePayService.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public abstract class BasePayService<PC extends PayConfigStorage> implements Pay
5858
* 支付消息拦截器
5959
*/
6060
protected List<PayMessageInterceptor<PayMessage, PayService>> interceptors = new ArrayList<PayMessageInterceptor<PayMessage, PayService>>();
61-
;
61+
6262

6363
/**
6464
* 设置支付配置
@@ -101,9 +101,15 @@ public BasePayService(PC payConfigStorage) {
101101
public BasePayService(PC payConfigStorage, HttpConfigStorage configStorage) {
102102
setPayConfigStorage(payConfigStorage);
103103
setRequestTemplateConfigStorage(configStorage);
104+
initAfter();
104105
}
105106

107+
/**
108+
* 初始化之后执行
109+
*/
110+
protected void initAfter(){
106111

112+
}
107113
/**
108114
* Generate a Base64 encoded String from user , password
109115
*

pay-java-common/src/main/java/com/egzosn/pay/common/util/MapGen.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.egzosn.pay.common.util;
22

3+
import java.util.HashMap;
4+
import java.util.LinkedHashMap;
35
import java.util.Map;
46

57
/**
@@ -21,6 +23,9 @@ public MapGen(K key, V value) {
2123
}
2224

2325
public MapGen<K, V> keyValue(K key, V value) {
26+
if (null == attr){
27+
attr = new LinkedHashMap<>();
28+
}
2429
attr.put(key, value);
2530
return this;
2631
}

pay-java-common/src/main/java/com/egzosn/pay/common/util/str/StringUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public static String tryTrim(String str) {
153153
public static String joining(String separator, String... str) {
154154
StringBuilder builder = new StringBuilder();
155155
for (String s : str) {
156-
if (StringUtils.isEmpty(s)) {
156+
if (null == s) {
157157
continue;
158158
}
159159

pay-java-demo/src/main/java/com/egzosn/pay/demo/controller/WxV3PayController.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717
import org.springframework.web.bind.annotation.RestController;
1818

1919
import com.egzosn.pay.common.bean.CertStoreType;
20-
import com.egzosn.pay.common.bean.NoticeRequest;
2120
import com.egzosn.pay.common.bean.PayOrder;
2221
import com.egzosn.pay.common.bean.RefundOrder;
2322
import com.egzosn.pay.common.bean.TransferOrder;
2423
import com.egzosn.pay.demo.request.QueryOrder;
25-
import com.egzosn.pay.demo.service.handler.WxPayMessageHandler;
24+
import com.egzosn.pay.demo.service.handler.WxV3PayMessageHandler;
2625
import com.egzosn.pay.web.support.HttpRequestNoticeParams;
2726
import com.egzosn.pay.wx.bean.WxBank;
2827
import com.egzosn.pay.wx.bean.WxTransferType;
@@ -48,31 +47,27 @@ public class WxV3PayController {
4847

4948

5049

51-
public WxV3PayController() {
5250

53-
54-
}
55-
56-
@PostConstruct
51+
@PostConstruct //没有证书的情况下注释掉,避免启动报错
5752
public void init() {
58-
53+
System.out.println("v3 init");
5954
WxPayConfigStorage wxPayConfigStorage = new WxPayConfigStorage();
60-
wxPayConfigStorage.setAppId("wxc7b993ff15a9f271");
61-
wxPayConfigStorage.setMchId("1602947765");
62-
// wxPayConfigStorage.setKeyPublic("转账公钥,转账时必填");
55+
wxPayConfigStorage.setAppId("wxc7b993ff15a9f27c");
56+
wxPayConfigStorage.setMchId("1602947766");
6357
//V3密钥 https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay3_2.shtml
64-
wxPayConfigStorage.setSecretKey("V3密钥");
65-
wxPayConfigStorage.setNotifyUrl("https://pay.egzosn.com/payback");
66-
wxPayConfigStorage.setReturnUrl("https://pay.egzosn.com/payback");
58+
wxPayConfigStorage.setV3ApiKey("9bd8f0e7af4841299d782406b7774f56");
59+
wxPayConfigStorage.setNotifyUrl("http://sailinmu.iok.la/wxV3/payBack.json");
60+
wxPayConfigStorage.setReturnUrl("http://sailinmu.iok.la/wxV3/payBack.json");
6761
wxPayConfigStorage.setInputCharset("utf-8");
62+
//使用证书时设置为true
6863
wxPayConfigStorage.setCertSign(true);
6964
//商户API证书 https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay3_1.shtml
70-
wxPayConfigStorage.setApiClientKeyP12("商户API证书.p12");
65+
wxPayConfigStorage.setApiClientKeyP12("E:\\Documents\\gitee\\支付\\yifenli_mall.p12");
7166
wxPayConfigStorage.setCertStoreType(CertStoreType.PATH);
7267
service = new WxPayService(wxPayConfigStorage);
7368
//设置回调消息处理
7469
//TODO {@link com.egzosn.pay.demo.controller.WxPayController#payBack}
75-
service.setPayMessageHandler(new WxPayMessageHandler(null));
70+
service.setPayMessageHandler(new WxV3PayMessageHandler());
7671
}
7772

7873

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.egzosn.pay.demo.service.handler;
2+
3+
import java.util.Map;
4+
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
8+
import com.alibaba.fastjson.JSON;
9+
import com.egzosn.pay.common.api.DefaultPayMessageHandler;
10+
import com.egzosn.pay.common.api.PayMessageHandler;
11+
import com.egzosn.pay.common.api.PayService;
12+
import com.egzosn.pay.common.bean.PayOutMessage;
13+
import com.egzosn.pay.common.exception.PayErrorException;
14+
import com.egzosn.pay.wx.v3.bean.response.WxPayMessage;
15+
16+
/**
17+
* 微信支付回调处理器
18+
* Created by ZaoSheng on 2016/6/1.
19+
*/
20+
public class WxV3PayMessageHandler implements PayMessageHandler<WxPayMessage, PayService> {
21+
22+
private final Logger LOG = LoggerFactory.getLogger(DefaultPayMessageHandler.class);
23+
24+
@Override
25+
public PayOutMessage handle(WxPayMessage payMessage, Map<String, Object> context, PayService payService) throws PayErrorException {
26+
LOG.info("回调支付消息处理器,回调消息:{}", JSON.toJSONString(payMessage));
27+
return payService.successPayOutMessage(payMessage);
28+
}
29+
}

pay-java-demo/src/main/resources/applicationContext.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
<context:annotation-config />
1212

13-
<context:component-scan base-package="com.egzosn.pay.demo" />
13+
<context:component-scan base-package="com.egzosn.pay.demo">
14+
<context:exclude-filter type="regex" expression="com.egzosn.pay.demo.controller.*"/>
15+
</context:component-scan>
1416

1517

1618

pay-java-web-support/pom.xml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,9 @@
2626
<dependency>
2727
<groupId>javax.servlet</groupId>
2828
<artifactId>javax.servlet-api</artifactId>
29-
<scope>provided</scope>
3029
<version>3.1.0</version>
3130
</dependency>
32-
<dependency>
33-
<groupId>javax.servlet</groupId>
34-
<artifactId>jsp-api</artifactId>
35-
<version>2.0</version>
36-
<scope>provided</scope>
37-
</dependency>
31+
3832

3933
</dependencies>
4034

pay-java-wx/src/main/java/com/egzosn/pay/wx/v3/api/DefaultWxPayAssistService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public void refreshCertificate() {
162162
String associatedData = encryptCertificate.getString("associated_data");
163163
String nonce = encryptCertificate.getString("nonce");
164164
String ciphertext = encryptCertificate.getString("ciphertext");
165-
String publicKey = AntCertificationUtil.decryptToString(associatedData, nonce, ciphertext, payConfigStorage.getSecretKey(), payConfigStorage.getInputCharset());
165+
String publicKey = AntCertificationUtil.decryptToString(associatedData, nonce, ciphertext, payConfigStorage.getV3ApiKey(), payConfigStorage.getInputCharset());
166166
ByteArrayInputStream inputStream = new ByteArrayInputStream(publicKey.getBytes(StandardCharsets.UTF_8));
167167
AntCertificationUtil.loadCertificate(certificate.getString("serial_no"), inputStream);
168168
}

pay-java-wx/src/main/java/com/egzosn/pay/wx/v3/api/WxPayConfigStorage.java

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ public class WxPayConfigStorage extends BasePayConfigStorage {
5151
* 微信支付分配的子商户号,开发者模式下必填 合作者id
5252
*/
5353
private String subMchId;
54+
/**
55+
* V2 Api密钥
56+
*/
57+
private String apiKey;
5458

5559
/**
5660
* 商户API证书
@@ -111,19 +115,33 @@ public String getMchId() {
111115

112116
public void setMchId(String mchId) {
113117
this.mchId = mchId;
118+
addAttr("mchId", mchId);
114119
}
115120

116121
/**
117122
* 为商户平台设置的密钥key
118123
*
119-
* @return 微信密钥
124+
* @return 微信v2密钥
120125
*/
121-
public String getSecretKey() {
122-
return getKeyPrivate();
126+
public String getApiKey() {
127+
return apiKey;
123128
}
124129

125-
public void setSecretKey(String secretKey) {
126-
setKeyPrivate(secretKey);
130+
public void setApiKey(String apiKey) {
131+
this.apiKey = apiKey;
132+
addAttr("apiKey", apiKey);
133+
}
134+
135+
public void setV3ApiKey(String v3ApiKey) {
136+
setKeyPrivate(v3ApiKey);
137+
}
138+
/**
139+
* 为商户平台设置的密钥key
140+
*
141+
* @return 微信v3密钥
142+
*/
143+
public String getV3ApiKey() {
144+
return getKeyPrivate();
127145
}
128146

129147
public void setAppId(String appId) {
@@ -147,6 +165,7 @@ public String getSubAppId() {
147165

148166
public void setSubAppId(String subAppId) {
149167
this.subAppId = subAppId;
168+
addAttr("subAppId", subAppId);
150169
}
151170

152171
public String getSpAppId() {
@@ -155,6 +174,7 @@ public String getSpAppId() {
155174

156175
public void setSpAppId(String spAppId) {
157176
this.spAppId = spAppId;
177+
addAttr("spAppId", spAppId);
158178
}
159179

160180
public String getSpMchId() {
@@ -163,6 +183,7 @@ public String getSpMchId() {
163183

164184
public void setSpMchId(String spMchId) {
165185
this.spMchId = spMchId;
186+
addAttr("spMchId", spMchId);
166187
}
167188

168189
/**
@@ -180,6 +201,7 @@ public String getSubAppid() {
180201
@Deprecated
181202
public void setSubAppid(String subAppid) {
182203
this.subAppId = subAppid;
204+
addAttr("subAppId", subAppId);
183205
}
184206

185207

@@ -189,6 +211,7 @@ public String getSubMchId() {
189211

190212
public void setSubMchId(String subMchId) {
191213
this.subMchId = subMchId;
214+
addAttr("subMchId", subMchId);
192215
}
193216

194217
public Object getApiClientKeyP12() {
@@ -197,6 +220,7 @@ public Object getApiClientKeyP12() {
197220

198221
public void setApiClientKeyP12(Object apiClientKeyP12) {
199222
this.apiClientKeyP12 = apiClientKeyP12;
223+
addAttr("apiClientKeyP12", apiClientKeyP12);
200224
}
201225

202226
public CertStoreType getCertStoreType() {
@@ -205,6 +229,7 @@ public CertStoreType getCertStoreType() {
205229

206230
public void setCertStoreType(CertStoreType certStoreType) {
207231
this.certStoreType = certStoreType;
232+
addAttr("certStoreType", certStoreType);
208233
}
209234

210235
public CertEnvironment getCertEnvironment() {

0 commit comments

Comments
 (0)