Skip to content

Commit e3463a0

Browse files
authored
🎨 #3686 【微信支付】付款码支付接口添加服务商模式支持
1 parent f249450 commit e3463a0

File tree

2 files changed

+85
-8
lines changed

2 files changed

+85
-8
lines changed

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayCodepayRequest.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,58 @@ public class WxPayCodepayRequest implements Serializable {
4545
*/
4646
@SerializedName(value = "mchid")
4747
protected String mchid;
48+
/**
49+
* <pre>
50+
* 字段名:服务商应用ID
51+
* 变量名:sp_appid
52+
* 是否必填:否
53+
* 类型:string[1,32]
54+
* 描述:
55+
* 服务商模式下使用,由微信生成的应用ID,全局唯一。
56+
* 示例值:wxd678efh567hg6787
57+
* </pre>
58+
*/
59+
@SerializedName(value = "sp_appid")
60+
protected String spAppid;
61+
/**
62+
* <pre>
63+
* 字段名:服务商商户号
64+
* 变量名:sp_mchid
65+
* 是否必填:否
66+
* 类型:string[1,32]
67+
* 描述:
68+
* 服务商模式下使用,服务商商户号,由微信支付生成并下发。
69+
* 示例值:1230000109
70+
* </pre>
71+
*/
72+
@SerializedName(value = "sp_mchid")
73+
protected String spMchid;
74+
/**
75+
* <pre>
76+
* 字段名:子商户应用ID
77+
* 变量名:sub_appid
78+
* 是否必填:否
79+
* 类型:string[1,32]
80+
* 描述:
81+
* 服务商模式下使用,由微信生成的应用ID,全局唯一。
82+
* 示例值:wxd678efh567hg6787
83+
* </pre>
84+
*/
85+
@SerializedName(value = "sub_appid")
86+
protected String subAppid;
87+
/**
88+
* <pre>
89+
* 字段名:子商户商户号
90+
* 变量名:sub_mchid
91+
* 是否必填:否
92+
* 类型:string[1,32]
93+
* 描述:
94+
* 服务商模式下使用,子商户商户号,由微信支付生成并下发。
95+
* 示例值:1230000109
96+
* </pre>
97+
*/
98+
@SerializedName(value = "sub_mchid")
99+
protected String subMchid;
48100
/**
49101
* <pre>
50102
* 字段名:商品描述

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

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,15 +1201,40 @@ public WxPayMicropayResult micropay(WxPayMicropayRequest request) throws WxPayEx
12011201

12021202
@Override
12031203
public WxPayCodepayResult codepay(WxPayCodepayRequest request) throws WxPayException {
1204-
if (StringUtils.isBlank(request.getAppid())) {
1205-
request.setAppid(this.getConfig().getAppId());
1206-
}
1207-
if (StringUtils.isBlank(request.getMchid())) {
1208-
request.setMchid(this.getConfig().getMchId());
1204+
// 判断是否为服务商模式:如果设置了sp_appid或sp_mchid或sub_mchid中的任何一个,则认为是服务商模式
1205+
boolean isPartnerMode = StringUtils.isNotBlank(request.getSpAppid())
1206+
|| StringUtils.isNotBlank(request.getSpMchid())
1207+
|| StringUtils.isNotBlank(request.getSubMchid());
1208+
1209+
if (isPartnerMode) {
1210+
// 服务商模式
1211+
if (StringUtils.isBlank(request.getSpAppid())) {
1212+
request.setSpAppid(this.getConfig().getAppId());
1213+
}
1214+
if (StringUtils.isBlank(request.getSpMchid())) {
1215+
request.setSpMchid(this.getConfig().getMchId());
1216+
}
1217+
if (StringUtils.isBlank(request.getSubAppid())) {
1218+
request.setSubAppid(this.getConfig().getSubAppId());
1219+
}
1220+
if (StringUtils.isBlank(request.getSubMchid())) {
1221+
request.setSubMchid(this.getConfig().getSubMchId());
1222+
}
1223+
String url = String.format("%s/v3/pay/partner/transactions/codepay", this.getPayBaseUrl());
1224+
String body = this.postV3WithWechatpaySerial(url, GSON.toJson(request));
1225+
return GSON.fromJson(body, WxPayCodepayResult.class);
1226+
} else {
1227+
// 直连商户模式
1228+
if (StringUtils.isBlank(request.getAppid())) {
1229+
request.setAppid(this.getConfig().getAppId());
1230+
}
1231+
if (StringUtils.isBlank(request.getMchid())) {
1232+
request.setMchid(this.getConfig().getMchId());
1233+
}
1234+
String url = String.format("%s/v3/pay/transactions/codepay", this.getPayBaseUrl());
1235+
String body = this.postV3WithWechatpaySerial(url, GSON.toJson(request));
1236+
return GSON.fromJson(body, WxPayCodepayResult.class);
12091237
}
1210-
String url = String.format("%s/v3/pay/transactions/codepay", this.getPayBaseUrl());
1211-
String body = this.postV3WithWechatpaySerial(url, GSON.toJson(request));
1212-
return GSON.fromJson(body, WxPayCodepayResult.class);
12131238
}
12141239

12151240
@Override

0 commit comments

Comments
 (0)