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 0000000000000000000000000000000000000000..bcdee975fc91e3366fda0a58d1d813dc0e614615 --- /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 af0276d92ae0c8c6f6d3383949422a791a263bd5..edca327db558de832a07975bd4d33b43a238ed7a 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 e645599808e0d18fa3cf4a8d8a185e1cc6b2d20a..71d47518927496ac30b14651e5e7e532efd9bd70 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(),