From 645151c6251a4981c89fa41f476829f3c2b51ebb Mon Sep 17 00:00:00 2001 From: linyaqiang <172617707@qq.com> Date: Tue, 1 Aug 2023 10:10:10 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=86=E8=B4=A6?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E6=9C=8D=E5=8A=A1=E5=95=86=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=EF=BC=8C=E5=90=8C=E6=97=B6=E5=9C=A8result=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v3/ProfitSharingPartnerNotifyResult.java | 151 ++++++++++++++++++ .../wxpay/service/ProfitSharingV3Service.java | 17 ++ .../impl/ProfitSharingV3ServiceImpl.java | 19 +++ 3 files changed, 187 insertions(+) create mode 100644 weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/v3/ProfitSharingPartnerNotifyResult.java diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/v3/ProfitSharingPartnerNotifyResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/v3/ProfitSharingPartnerNotifyResult.java new file mode 100644 index 000000000..bcdee975f --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/v3/ProfitSharingPartnerNotifyResult.java @@ -0,0 +1,151 @@ +package com.github.binarywang.wxpay.bean.profitsharing.v3; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * + * 微信V3接口-服务商 + * 分账动账通知解密后数据实体 + * + * @author linyaqiang + * @since 2023-08-01 + */ +@Data +@NoArgsConstructor +public class ProfitSharingPartnerNotifyResult implements Serializable { + private static final long serialVersionUID = -2875006651351414624L; + + /** + *
+ * 字段名:服务商商户号 + * 是否必填:是 + * 描述:服务商模式分账发起商户。 + *+ */ + @SerializedName("sp_mchid") + private String spMchid; + + /** + *
+ * 字段名:子商户号 + * 是否必填:是 + * 描述:服务商模式分账出资商户。 + *+ */ + @SerializedName("sub_mchid") + private String subMchid; + + /** + *
+ * 字段名:微信订单号 + * 是否必填:是 + * 描述:微信支付订单号 + *+ */ + @SerializedName("transaction_id") + private String transactionId; + + /** + *
+ * 字段名:微信分账/回退单号 + * 是否必填:是 + * 描述:微信分账/回退单号 + *+ */ + @SerializedName("order_id") + private String orderId; + + /** + *
+ * 字段名:商户分账/回退单号 + * 是否必填:是 + * 描述:分账方系统内部的分账/回退单号 + *+ */ + @SerializedName("out_order_no") + private String outOrderNo; + + /** + *
+ * 字段名:分账接收方 + * 是否必填:是 + * 描述:分账接收方对象 + *+ */ + @SerializedName("receiver") + private Receiver receiver; + + /** + *
+ * 字段名:成功时间 + * 是否必填:是 + * 描述:成功时间,Rfc3339标准 + *+ */ + @SerializedName("success_time") + private String successTime; + + /** + *
+ * 字段名:通知类型 + * 是否必填:是 + * 描述:通知的类型: + * PROFITSHARING.SUCCESS:分账 + * PROFITSHARING.RETURN :分账回退 + * 备注:由于分账通知和分账退回通知共用一个接口,需增加一个字段区分通知类型 + *+ */ + @SerializedName("event_type") + private String eventType; + + @Data + @NoArgsConstructor + public static class Receiver implements Serializable { + + private static final long serialVersionUID = -931070141604645363L; + + /** + *
+ * 字段名:分账接收方类型 + * 是否必填:是 + * 描述:MERCHANT_ID:商户号(mch_id或者sub_mch_id) + *+ */ + @SerializedName("type") + private String type; + + /** + *
+ * 字段名:分账接收方账号 + * 是否必填:是 + * 描述:申请本功能商户号 + *+ */ + @SerializedName("account") + private String account; + + /** + *
+ * 字段名:分账动账金额 + * 是否必填:是 + * 描述:分账动账金额,单位为分,只能为整数 + *+ */ + @SerializedName("amount") + private Integer amount; + + /** + *
+ * 字段名:分账/回退描述 + * 是否必填:是 + * 描述:分账/回退描述 + *+ */ + @SerializedName("description") + private String description; + } +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/ProfitSharingV3Service.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/ProfitSharingV3Service.java index af0276d92..edca327db 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/ProfitSharingV3Service.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/ProfitSharingV3Service.java @@ -240,6 +240,23 @@ public interface ProfitSharingV3Service { */ ProfitSharingNotifyResult getProfitSharingNotifyResult(String notifyData, SignatureHeader header) throws WxPayException; + /** + *
+ * 分账动账通知-服务商 + * + * 分账或分账回退成功后,微信会把相关变动结果发送给分账接收方(只支持商户)。 + * 对后台通知交互时,如果微信收到应答不是成功或超时,微信认为通知失败,微信会通过一定的策略定期重新发起通知,尽可能提高通知的成功率,但微信不保证通知最终能成功。 + * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_1_10.shtml + *+ * + * @param notifyData 分账通知实体 + * @param header 分账通知头 {@link SignatureHeader} + * @return {@link ProfitSharingNotifyData} 资源对象 + * @throws WxPayException the wx pay exception + * @see 微信文档 + */ + ProfitSharingPartnerNotifyResult getProfitSharingPartnerNotifyResult(String notifyData, SignatureHeader header) throws WxPayException; + /** *
* 申请分账账单 diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/ProfitSharingV3ServiceImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/ProfitSharingV3ServiceImpl.java index e64559980..71d475189 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/ProfitSharingV3ServiceImpl.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/ProfitSharingV3ServiceImpl.java @@ -135,6 +135,25 @@ public class ProfitSharingV3ServiceImpl implements ProfitSharingV3Service { } } + @Override + public ProfitSharingPartnerNotifyResult getProfitSharingPartnerNotifyResult(String notifyData, SignatureHeader header) throws WxPayException { + ProfitSharingNotifyData response = parseNotifyData(notifyData, header); + ProfitSharingNotifyData.Resource resource = response.getResource(); + String cipherText = resource.getCipherText(); + String associatedData = resource.getAssociatedData(); + String nonce = resource.getNonce(); + String apiV3Key = this.payService.getConfig().getApiV3Key(); + try { + String result = AesUtils.decryptToString(associatedData, nonce, cipherText, apiV3Key); + ProfitSharingPartnerNotifyResult profitSharingPartnerNotifyResult = GSON.fromJson(result, ProfitSharingPartnerNotifyResult.class); + //由于分账通知和分账退回通知共用一个接口,需增加一个字段区分通知类型 + profitSharingPartnerNotifyResult.setEventType(response.getEventType()); + return profitSharingPartnerNotifyResult; + } catch (GeneralSecurityException | IOException e) { + throw new WxPayException("解析报文异常!", e); + } + } + @Override public ProfitSharingBillResult getProfitSharingBill(ProfitSharingBillRequest request) throws WxPayException { String url = String.format("%s/v3/profitsharing/bills?bill_date=%s", this.payService.getPayBaseUrl(), -- Gitee From c699f316eae26c97d13704b7d21fcdc41323ae49 Mon Sep 17 00:00:00 2001 From: linyaqiang <172617707@qq.com> Date: Wed, 2 Aug 2023 11:37:19 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v3/ProfitSharingPartnerNotifyResult.java | 13 ------------- .../service/impl/ProfitSharingV3ServiceImpl.java | 5 +---- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/v3/ProfitSharingPartnerNotifyResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/v3/ProfitSharingPartnerNotifyResult.java index bcdee975f..77f628cff 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/v3/ProfitSharingPartnerNotifyResult.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/v3/ProfitSharingPartnerNotifyResult.java @@ -89,19 +89,6 @@ public class ProfitSharingPartnerNotifyResult implements Serializable { @SerializedName("success_time") private String successTime; - /** - *- * 字段名:通知类型 - * 是否必填:是 - * 描述:通知的类型: - * PROFITSHARING.SUCCESS:分账 - * PROFITSHARING.RETURN :分账回退 - * 备注:由于分账通知和分账退回通知共用一个接口,需增加一个字段区分通知类型 - *- */ - @SerializedName("event_type") - private String eventType; - @Data @NoArgsConstructor public static class Receiver implements Serializable { diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/ProfitSharingV3ServiceImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/ProfitSharingV3ServiceImpl.java index 71d475189..cd0d0255c 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/ProfitSharingV3ServiceImpl.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/ProfitSharingV3ServiceImpl.java @@ -145,10 +145,7 @@ public class ProfitSharingV3ServiceImpl implements ProfitSharingV3Service { String apiV3Key = this.payService.getConfig().getApiV3Key(); try { String result = AesUtils.decryptToString(associatedData, nonce, cipherText, apiV3Key); - ProfitSharingPartnerNotifyResult profitSharingPartnerNotifyResult = GSON.fromJson(result, ProfitSharingPartnerNotifyResult.class); - //由于分账通知和分账退回通知共用一个接口,需增加一个字段区分通知类型 - profitSharingPartnerNotifyResult.setEventType(response.getEventType()); - return profitSharingPartnerNotifyResult; + return GSON.fromJson(result, ProfitSharingPartnerNotifyResult.class); } catch (GeneralSecurityException | IOException e) { throw new WxPayException("解析报文异常!", e); } -- Gitee