From e0a39c8d68323c1c84ffcbcdf8dd0b7b56793eeb Mon Sep 17 00:00:00 2001 From: LinZhaoguan <17186784453@163.com> Date: Sat, 17 Dec 2022 14:39:20 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20#2903=20=E3=80=90=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E3=80=91=E4=BC=98=E5=8C=96=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=95=86=E6=A8=A1=E5=BC=8F=E7=9A=84=E5=BE=AE=E4=BF=A1=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E5=88=86=E7=9B=B8=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.优化请求参数赋值逻辑 2.新增服务商模式的”授权/解除授权服务回调通知结果“实体类 --- .../payscore/WxPartnerPayScoreRequest.java | 19 ++++-- ...erUserAuthorizationStatusNotifyResult.java | 67 +++++++++++++++++++ .../wxpay/service/PartnerPayScoreService.java | 11 ++- .../wxpay/service/WxPayService.java | 7 ++ .../service/impl/BaseWxPayServiceImpl.java | 3 + .../impl/PartnerPayScoreServiceImpl.java | 51 ++++++++------ 6 files changed, 128 insertions(+), 30 deletions(-) create mode 100644 weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/WxPartnerUserAuthorizationStatusNotifyResult.java diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/WxPartnerPayScoreRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/WxPartnerPayScoreRequest.java index a125acf7f..e48080728 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/WxPartnerPayScoreRequest.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/WxPartnerPayScoreRequest.java @@ -3,20 +3,19 @@ package com.github.binarywang.wxpay.bean.payscore; import com.google.gson.annotations.SerializedName; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.experimental.Accessors; import lombok.experimental.SuperBuilder; import me.chanjar.weixin.common.util.json.WxGsonBuilder; -/** - * @author hallkk - * created on 2022/05/18 - */ + @Data @SuperBuilder @NoArgsConstructor @AllArgsConstructor @Accessors(chain = true) +@EqualsAndHashCode(callSuper = true) public class WxPartnerPayScoreRequest extends WxPayScoreRequest { private static final long serialVersionUID = 6269843192878112955L; @@ -24,15 +23,27 @@ public class WxPartnerPayScoreRequest extends WxPayScoreRequest { return WxGsonBuilder.create().toJson(this); } + /** + * 子商户appid + */ @SerializedName("sub_appid") private String subAppid; + /** + * 子商户mchid + */ @SerializedName("sub_mchid") private String subMchid; + /** + * [收付通子商户申请绑定支付分服务]的商户系统内部服务订单号 + */ @SerializedName("out_apply_no") private String outApplyNo; + /** + * [收付通子商户申请绑定支付分服务]的绑定结果通知地址 + */ @SerializedName("result_notify_url") private String resultNotifyUrl; diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/WxPartnerUserAuthorizationStatusNotifyResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/WxPartnerUserAuthorizationStatusNotifyResult.java new file mode 100644 index 000000000..feeabaac1 --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/WxPartnerUserAuthorizationStatusNotifyResult.java @@ -0,0 +1,67 @@ +package com.github.binarywang.wxpay.bean.payscore; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import me.chanjar.weixin.common.util.json.WxGsonBuilder; + +import java.io.Serializable; + +/** + * 授权/解除授权服务回调通知结果 + *
+ * 文档地址:https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter6_2_23.shtml + *+ */ +@Data +@NoArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class WxPartnerUserAuthorizationStatusNotifyResult extends UserAuthorizationStatusNotifyResult implements Serializable { + + private static final long serialVersionUID = 8809250065540275783L; + + /** + *
+ * 字段名:子商户应用ID + * 变量名:sub_appid + * 是否必填:是 + * 类型:string[1,32] + * 描述: + * 子商户申请的公众号或移动应用APPID。 + * 示例值:wxd678efh567hg6787 + *+ */ + @SerializedName(value = "sub_appid") + private String subAppId; + + /** + *
+ * 字段名:子商户的商户号 + * 变量名:sub_mchid + * 是否必填:是 + * 类型:string[1,32] + * 描述: + * 子商户商户号,由微信支付生成并下发。 + * 示例值:1230000109 + *+ */ + @SerializedName(value = "sub_mchid") + private String subMchId; + + /** + *
+ * 字段名:子商户公众号下openid + * 变量名:sub_mchid + * 是否必填:是 + * 类型:string[1,32] + * 描述: + * 微信用户在商户对应sub_appid下的唯一标识。(传了sub_appid的情况下则只返回sub_openid)。 + * 示例值:oUpF8uMuAJO_M2pxb1Q9zNjWeS6o + *+ */ + @SerializedName(value = "sub_openid") + private String subOpenid; + + +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/PartnerPayScoreService.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/PartnerPayScoreService.java index 4faa284aa..160992994 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/PartnerPayScoreService.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/PartnerPayScoreService.java @@ -1,10 +1,7 @@ package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader; -import com.github.binarywang.wxpay.bean.payscore.PayScoreNotifyData; -import com.github.binarywang.wxpay.bean.payscore.UserAuthorizationStatusNotifyResult; -import com.github.binarywang.wxpay.bean.payscore.WxPartnerPayScoreRequest; -import com.github.binarywang.wxpay.bean.payscore.WxPartnerPayScoreResult; +import com.github.binarywang.wxpay.bean.payscore.*; import com.github.binarywang.wxpay.exception.WxPayException; /** @@ -241,7 +238,7 @@ public interface PartnerPayScoreService { /** *
* 授权/解除授权服务回调数据处理
- * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter4_4.shtml
+ * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter6_2_23.shtml
*
*
* @param notifyData 通知数据
@@ -249,12 +246,12 @@ public interface PartnerPayScoreService {
* @return 解密后通知数据 return user authorization status notify result
* @throws WxPayException the wx pay exception
*/
- UserAuthorizationStatusNotifyResult parseUserAuthorizationStatusNotifyResult(String notifyData, SignatureHeader header) throws WxPayException;
+ WxPartnerUserAuthorizationStatusNotifyResult parseUserAuthorizationStatusNotifyResult(String notifyData, SignatureHeader header) throws WxPayException;
/**
*
* 支付分回调内容解析方法
- * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter5_2.shtml
+ * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter6_2_9.shtml
*
*
* @param data the data
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java
index ca5f5f1e3..9b2fb1e0c 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java
@@ -1370,4 +1370,11 @@ public interface WxPayService {
* @return the transfers service
*/
TransferService getTransferService();
+
+ /**
+ * 获取服务商支付分服务类
+ * @return the partner pay score service
+ */
+ PartnerPayScoreService getPartnerPayScoreService();
+
}
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java
index 42573659f..bbb4616a1 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java
@@ -118,6 +118,9 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
@Getter
private final TransferService transferService = new TransferServiceImpl(this);
+ @Getter
+ private final PartnerPayScoreService partnerPayScoreService = new PartnerPayScoreServiceImpl(this);
+
@Getter
private final MerchantTransferService merchantTransferService = new MerchantTransferServiceImpl(this);
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/PartnerPayScoreServiceImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/PartnerPayScoreServiceImpl.java
index 7ca51d1db..0e3746844 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/PartnerPayScoreServiceImpl.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/PartnerPayScoreServiceImpl.java
@@ -1,10 +1,7 @@
package com.github.binarywang.wxpay.service.impl;
import com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader;
-import com.github.binarywang.wxpay.bean.payscore.PayScoreNotifyData;
-import com.github.binarywang.wxpay.bean.payscore.UserAuthorizationStatusNotifyResult;
-import com.github.binarywang.wxpay.bean.payscore.WxPartnerPayScoreRequest;
-import com.github.binarywang.wxpay.bean.payscore.WxPartnerPayScoreResult;
+import com.github.binarywang.wxpay.bean.payscore.*;
import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.github.binarywang.wxpay.service.PartnerPayScoreService;
@@ -41,22 +38,24 @@ public class PartnerPayScoreServiceImpl implements PartnerPayScoreService {
request.setAppid(request.getAppid());
request.setServiceId(request.getServiceId());
WxPayConfig config = this.payService.getConfig();
- String permissionNotifyUrl = config.getPayScorePermissionNotifyUrl();
- if (StringUtils.isBlank(permissionNotifyUrl)) {
- throw new WxPayException("授权回调地址未配置");
+ if(StringUtils.isBlank(request.getAppid())){
+ request.setAppid(config.getAppId());
}
- String authorizationCode = request.getAuthorizationCode();
- if (StringUtils.isBlank(authorizationCode)) {
+ if(StringUtils.isBlank((request.getServiceId()))){
+ request.setServiceId(config.getServiceId());
+ }
+ if (StringUtils.isBlank(request.getNotifyUrl())) {
+ request.setNotifyUrl(config.getPayScorePermissionNotifyUrl());
+ }
+ if (StringUtils.isBlank(request.getAuthorizationCode())) {
throw new WxPayException("authorizationCode不允许为空");
}
- request.setNotifyUrl(permissionNotifyUrl);
String result = this.payService.postV3(url, request.toJson());
return WxPartnerPayScoreResult.fromJson(result);
}
@Override
- public WxPartnerPayScoreResult permissionsQueryByAuthorizationCode(String serviceId, String subMchid, String authorizationCode)
- throws WxPayException {
+ public WxPartnerPayScoreResult permissionsQueryByAuthorizationCode(String serviceId, String subMchid, String authorizationCode) throws WxPayException {
if (StringUtils.isBlank(authorizationCode)) {
throw new WxPayException("authorizationCode不允许为空");
}
@@ -163,7 +162,15 @@ public class PartnerPayScoreServiceImpl implements PartnerPayScoreService {
String url = this.payService.getPayBaseUrl() + "/v3/payscore/partner/serviceorder";
WxPayConfig config = this.payService.getConfig();
- request.setNotifyUrl(config.getPayScoreNotifyUrl());
+ if(StringUtils.isBlank(request.getAppid())){
+ request.setAppid(config.getAppId());
+ }
+ if(StringUtils.isBlank((request.getServiceId()))){
+ request.setServiceId(config.getServiceId());
+ }
+ if(StringUtils.isBlank((request.getNotifyUrl()))){
+ request.setNotifyUrl(config.getPayScoreNotifyUrl());
+ }
String result = this.payService.postV3(url, request.toJson());
return WxPartnerPayScoreResult.fromJson(result);
@@ -229,10 +236,14 @@ public class PartnerPayScoreServiceImpl implements PartnerPayScoreService {
public void completeServiceOrder(WxPartnerPayScoreRequest request) throws WxPayException {
String outOrderNo = request.getOutOrderNo();
String url = String.format("%s/v3/payscore/partner/serviceorder/%s/complete", this.payService.getPayBaseUrl(), outOrderNo);
- request.setAppid(request.getAppid());
- request.setServiceId(request.getServiceId());
+ WxPayConfig config = this.payService.getConfig();
+ if (StringUtils.isBlank(request.getServiceId())) {
+ request.setServiceId(config.getServiceId());
+ }
+ if (StringUtils.isBlank(request.getSubMchid())) {
+ request.setSubMchid(config.getSubMchId());
+ }
request.setOutOrderNo(null);
- request.setSubMchid(request.getSubMchid());
this.payService.postV3(url, request.toJson());
}
@@ -254,7 +265,9 @@ public class PartnerPayScoreServiceImpl implements PartnerPayScoreService {
public WxPartnerPayScoreResult syncServiceOrder(WxPartnerPayScoreRequest request) throws WxPayException {
String outOrderNo = request.getOutOrderNo();
String url = String.format("%s/v3/payscore/partner/serviceorder/%s/sync", this.payService.getPayBaseUrl(), outOrderNo);
- request.setAppid(this.payService.getConfig().getAppId());
+ if (StringUtils.isBlank(request.getAppid())) {
+ request.setAppid(this.payService.getConfig().getAppId());
+ }
request.setOutOrderNo(null);
String result = payService.postV3(url, request.toJson());
return WxPartnerPayScoreResult.fromJson(result);
@@ -284,7 +297,7 @@ public class PartnerPayScoreServiceImpl implements PartnerPayScoreService {
}
@Override
- public UserAuthorizationStatusNotifyResult parseUserAuthorizationStatusNotifyResult(String notifyData, SignatureHeader header) throws WxPayException {
+ public WxPartnerUserAuthorizationStatusNotifyResult parseUserAuthorizationStatusNotifyResult(String notifyData, SignatureHeader header) throws WxPayException {
PayScoreNotifyData response = parseNotifyData(notifyData, header);
PayScoreNotifyData.Resource resource = response.getResource();
String cipherText = resource.getCipherText();
@@ -293,7 +306,7 @@ public class PartnerPayScoreServiceImpl implements PartnerPayScoreService {
String apiV3Key = this.payService.getConfig().getApiV3Key();
try {
String result = AesUtils.decryptToString(associatedData, nonce, cipherText, apiV3Key);
- UserAuthorizationStatusNotifyResult notifyResult = GSON.fromJson(result, UserAuthorizationStatusNotifyResult.class);
+ WxPartnerUserAuthorizationStatusNotifyResult notifyResult = GSON.fromJson(result, WxPartnerUserAuthorizationStatusNotifyResult.class);
notifyResult.setRawData(response);
return notifyResult;
} catch (GeneralSecurityException | IOException e) {