Skip to content

Commit e0a39c8

Browse files
authored
🎨 #2903 【微信支付】优化服务商模式的微信支付分相关代码
1.优化请求参数赋值逻辑 2.新增服务商模式的”授权/解除授权服务回调通知结果“实体类
1 parent 749f326 commit e0a39c8

File tree

6 files changed

+128
-30
lines changed

6 files changed

+128
-30
lines changed

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/WxPartnerPayScoreRequest.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,47 @@
33
import com.google.gson.annotations.SerializedName;
44
import lombok.AllArgsConstructor;
55
import lombok.Data;
6+
import lombok.EqualsAndHashCode;
67
import lombok.NoArgsConstructor;
78
import lombok.experimental.Accessors;
89
import lombok.experimental.SuperBuilder;
910
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
1011

11-
/**
12-
* @author hallkk
13-
* created on 2022/05/18
14-
*/
12+
1513
@Data
1614
@SuperBuilder
1715
@NoArgsConstructor
1816
@AllArgsConstructor
1917
@Accessors(chain = true)
18+
@EqualsAndHashCode(callSuper = true)
2019
public class WxPartnerPayScoreRequest extends WxPayScoreRequest {
2120
private static final long serialVersionUID = 6269843192878112955L;
2221

2322
public String toJson() {
2423
return WxGsonBuilder.create().toJson(this);
2524
}
2625

26+
/**
27+
* 子商户appid
28+
*/
2729
@SerializedName("sub_appid")
2830
private String subAppid;
2931

32+
/**
33+
* 子商户mchid
34+
*/
3035
@SerializedName("sub_mchid")
3136
private String subMchid;
3237

38+
/**
39+
* [收付通子商户申请绑定支付分服务]的商户系统内部服务订单号
40+
*/
3341
@SerializedName("out_apply_no")
3442
private String outApplyNo;
3543

44+
/**
45+
* [收付通子商户申请绑定支付分服务]的绑定结果通知地址
46+
*/
3647
@SerializedName("result_notify_url")
3748
private String resultNotifyUrl;
3849

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.github.binarywang.wxpay.bean.payscore;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
import lombok.NoArgsConstructor;
7+
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
8+
9+
import java.io.Serializable;
10+
11+
/**
12+
* 授权/解除授权服务回调通知结果
13+
* <pre>
14+
* 文档地址:https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter6_2_23.shtml
15+
* </pre>
16+
*/
17+
@Data
18+
@NoArgsConstructor
19+
@EqualsAndHashCode(callSuper = true)
20+
public class WxPartnerUserAuthorizationStatusNotifyResult extends UserAuthorizationStatusNotifyResult implements Serializable {
21+
22+
private static final long serialVersionUID = 8809250065540275783L;
23+
24+
/**
25+
* <pre>
26+
* 字段名:子商户应用ID
27+
* 变量名:sub_appid
28+
* 是否必填:是
29+
* 类型:string[1,32]
30+
* 描述:
31+
* 子商户申请的公众号或移动应用APPID。
32+
* 示例值:wxd678efh567hg6787
33+
* </pre>
34+
*/
35+
@SerializedName(value = "sub_appid")
36+
private String subAppId;
37+
38+
/**
39+
* <pre>
40+
* 字段名:子商户的商户号
41+
* 变量名:sub_mchid
42+
* 是否必填:是
43+
* 类型:string[1,32]
44+
* 描述:
45+
* 子商户商户号,由微信支付生成并下发。
46+
* 示例值:1230000109
47+
* </pre>
48+
*/
49+
@SerializedName(value = "sub_mchid")
50+
private String subMchId;
51+
52+
/**
53+
* <pre>
54+
* 字段名:子商户公众号下openid
55+
* 变量名:sub_mchid
56+
* 是否必填:是
57+
* 类型:string[1,32]
58+
* 描述:
59+
* 微信用户在商户对应sub_appid下的唯一标识。(传了sub_appid的情况下则只返回sub_openid)。
60+
* 示例值:oUpF8uMuAJO_M2pxb1Q9zNjWeS6o
61+
* </pre>
62+
*/
63+
@SerializedName(value = "sub_openid")
64+
private String subOpenid;
65+
66+
67+
}

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/PartnerPayScoreService.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package com.github.binarywang.wxpay.service;
22

33
import com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader;
4-
import com.github.binarywang.wxpay.bean.payscore.PayScoreNotifyData;
5-
import com.github.binarywang.wxpay.bean.payscore.UserAuthorizationStatusNotifyResult;
6-
import com.github.binarywang.wxpay.bean.payscore.WxPartnerPayScoreRequest;
7-
import com.github.binarywang.wxpay.bean.payscore.WxPartnerPayScoreResult;
4+
import com.github.binarywang.wxpay.bean.payscore.*;
85
import com.github.binarywang.wxpay.exception.WxPayException;
96

107
/**
@@ -241,20 +238,20 @@ WxPartnerPayScoreResult cancelServiceOrder(String serviceId, String appId, Strin
241238
/**
242239
* <pre>
243240
* 授权/解除授权服务回调数据处理
244-
* 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter4_4.shtml
241+
* 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter6_2_23.shtml
245242
* </pre>
246243
*
247244
* @param notifyData 通知数据
248245
* @param header 通知头部数据,不传则表示不校验头
249246
* @return 解密后通知数据 return user authorization status notify result
250247
* @throws WxPayException the wx pay exception
251248
*/
252-
UserAuthorizationStatusNotifyResult parseUserAuthorizationStatusNotifyResult(String notifyData, SignatureHeader header) throws WxPayException;
249+
WxPartnerUserAuthorizationStatusNotifyResult parseUserAuthorizationStatusNotifyResult(String notifyData, SignatureHeader header) throws WxPayException;
253250

254251
/**
255252
* <pre>
256253
* 支付分回调内容解析方法
257-
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter5_2.shtml
254+
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter6_2_9.shtml
258255
* </pre>
259256
*
260257
* @param data the data

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,4 +1370,11 @@ WxPayRefundQueryResult refundQuery(String transactionId, String outTradeNo, Stri
13701370
* @return the transfers service
13711371
*/
13721372
TransferService getTransferService();
1373+
1374+
/**
1375+
* 获取服务商支付分服务类
1376+
* @return the partner pay score service
1377+
*/
1378+
PartnerPayScoreService getPartnerPayScoreService();
1379+
13731380
}

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
118118
@Getter
119119
private final TransferService transferService = new TransferServiceImpl(this);
120120

121+
@Getter
122+
private final PartnerPayScoreService partnerPayScoreService = new PartnerPayScoreServiceImpl(this);
123+
121124
@Getter
122125
private final MerchantTransferService merchantTransferService = new MerchantTransferServiceImpl(this);
123126

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/PartnerPayScoreServiceImpl.java

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package com.github.binarywang.wxpay.service.impl;
22

33
import com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader;
4-
import com.github.binarywang.wxpay.bean.payscore.PayScoreNotifyData;
5-
import com.github.binarywang.wxpay.bean.payscore.UserAuthorizationStatusNotifyResult;
6-
import com.github.binarywang.wxpay.bean.payscore.WxPartnerPayScoreRequest;
7-
import com.github.binarywang.wxpay.bean.payscore.WxPartnerPayScoreResult;
4+
import com.github.binarywang.wxpay.bean.payscore.*;
85
import com.github.binarywang.wxpay.config.WxPayConfig;
96
import com.github.binarywang.wxpay.exception.WxPayException;
107
import com.github.binarywang.wxpay.service.PartnerPayScoreService;
@@ -41,22 +38,24 @@ public WxPartnerPayScoreResult permissions(WxPartnerPayScoreRequest request) thr
4138
request.setAppid(request.getAppid());
4239
request.setServiceId(request.getServiceId());
4340
WxPayConfig config = this.payService.getConfig();
44-
String permissionNotifyUrl = config.getPayScorePermissionNotifyUrl();
45-
if (StringUtils.isBlank(permissionNotifyUrl)) {
46-
throw new WxPayException("授权回调地址未配置");
41+
if(StringUtils.isBlank(request.getAppid())){
42+
request.setAppid(config.getAppId());
4743
}
48-
String authorizationCode = request.getAuthorizationCode();
49-
if (StringUtils.isBlank(authorizationCode)) {
44+
if(StringUtils.isBlank((request.getServiceId()))){
45+
request.setServiceId(config.getServiceId());
46+
}
47+
if (StringUtils.isBlank(request.getNotifyUrl())) {
48+
request.setNotifyUrl(config.getPayScorePermissionNotifyUrl());
49+
}
50+
if (StringUtils.isBlank(request.getAuthorizationCode())) {
5051
throw new WxPayException("authorizationCode不允许为空");
5152
}
52-
request.setNotifyUrl(permissionNotifyUrl);
5353
String result = this.payService.postV3(url, request.toJson());
5454
return WxPartnerPayScoreResult.fromJson(result);
5555
}
5656

5757
@Override
58-
public WxPartnerPayScoreResult permissionsQueryByAuthorizationCode(String serviceId, String subMchid, String authorizationCode)
59-
throws WxPayException {
58+
public WxPartnerPayScoreResult permissionsQueryByAuthorizationCode(String serviceId, String subMchid, String authorizationCode) throws WxPayException {
6059
if (StringUtils.isBlank(authorizationCode)) {
6160
throw new WxPayException("authorizationCode不允许为空");
6261
}
@@ -163,7 +162,15 @@ public WxPartnerPayScoreResult createServiceOrder(WxPartnerPayScoreRequest reque
163162
String url = this.payService.getPayBaseUrl() + "/v3/payscore/partner/serviceorder";
164163

165164
WxPayConfig config = this.payService.getConfig();
166-
request.setNotifyUrl(config.getPayScoreNotifyUrl());
165+
if(StringUtils.isBlank(request.getAppid())){
166+
request.setAppid(config.getAppId());
167+
}
168+
if(StringUtils.isBlank((request.getServiceId()))){
169+
request.setServiceId(config.getServiceId());
170+
}
171+
if(StringUtils.isBlank((request.getNotifyUrl()))){
172+
request.setNotifyUrl(config.getPayScoreNotifyUrl());
173+
}
167174
String result = this.payService.postV3(url, request.toJson());
168175

169176
return WxPartnerPayScoreResult.fromJson(result);
@@ -229,10 +236,14 @@ public WxPartnerPayScoreResult modifyServiceOrder(WxPartnerPayScoreRequest reque
229236
public void completeServiceOrder(WxPartnerPayScoreRequest request) throws WxPayException {
230237
String outOrderNo = request.getOutOrderNo();
231238
String url = String.format("%s/v3/payscore/partner/serviceorder/%s/complete", this.payService.getPayBaseUrl(), outOrderNo);
232-
request.setAppid(request.getAppid());
233-
request.setServiceId(request.getServiceId());
239+
WxPayConfig config = this.payService.getConfig();
240+
if (StringUtils.isBlank(request.getServiceId())) {
241+
request.setServiceId(config.getServiceId());
242+
}
243+
if (StringUtils.isBlank(request.getSubMchid())) {
244+
request.setSubMchid(config.getSubMchId());
245+
}
234246
request.setOutOrderNo(null);
235-
request.setSubMchid(request.getSubMchid());
236247
this.payService.postV3(url, request.toJson());
237248
}
238249

@@ -254,7 +265,9 @@ public WxPartnerPayScoreResult payServiceOrder(String serviceId, String appId, S
254265
public WxPartnerPayScoreResult syncServiceOrder(WxPartnerPayScoreRequest request) throws WxPayException {
255266
String outOrderNo = request.getOutOrderNo();
256267
String url = String.format("%s/v3/payscore/partner/serviceorder/%s/sync", this.payService.getPayBaseUrl(), outOrderNo);
257-
request.setAppid(this.payService.getConfig().getAppId());
268+
if (StringUtils.isBlank(request.getAppid())) {
269+
request.setAppid(this.payService.getConfig().getAppId());
270+
}
258271
request.setOutOrderNo(null);
259272
String result = payService.postV3(url, request.toJson());
260273
return WxPartnerPayScoreResult.fromJson(result);
@@ -284,7 +297,7 @@ public WxPartnerPayScoreResult queryServiceAccountState(String outApplyNo) throw
284297
}
285298

286299
@Override
287-
public UserAuthorizationStatusNotifyResult parseUserAuthorizationStatusNotifyResult(String notifyData, SignatureHeader header) throws WxPayException {
300+
public WxPartnerUserAuthorizationStatusNotifyResult parseUserAuthorizationStatusNotifyResult(String notifyData, SignatureHeader header) throws WxPayException {
288301
PayScoreNotifyData response = parseNotifyData(notifyData, header);
289302
PayScoreNotifyData.Resource resource = response.getResource();
290303
String cipherText = resource.getCipherText();
@@ -293,7 +306,7 @@ public UserAuthorizationStatusNotifyResult parseUserAuthorizationStatusNotifyRes
293306
String apiV3Key = this.payService.getConfig().getApiV3Key();
294307
try {
295308
String result = AesUtils.decryptToString(associatedData, nonce, cipherText, apiV3Key);
296-
UserAuthorizationStatusNotifyResult notifyResult = GSON.fromJson(result, UserAuthorizationStatusNotifyResult.class);
309+
WxPartnerUserAuthorizationStatusNotifyResult notifyResult = GSON.fromJson(result, WxPartnerUserAuthorizationStatusNotifyResult.class);
297310
notifyResult.setRawData(response);
298311
return notifyResult;
299312
} catch (GeneralSecurityException | IOException e) {

0 commit comments

Comments
 (0)