mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-10-27 20:14:52 +08:00
🎨 【微信支付】增加服务商模式下分账通知的解析方法
This commit is contained in:
@ -0,0 +1,138 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 字段名:服务商商户号
|
||||
* 是否必填:是
|
||||
* 描述:服务商模式分账发起商户。
|
||||
* </pre>
|
||||
*/
|
||||
@SerializedName("sp_mchid")
|
||||
private String spMchid;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 字段名:子商户号
|
||||
* 是否必填:是
|
||||
* 描述:服务商模式分账出资商户。
|
||||
* </pre>
|
||||
*/
|
||||
@SerializedName("sub_mchid")
|
||||
private String subMchid;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 字段名:微信订单号
|
||||
* 是否必填:是
|
||||
* 描述:微信支付订单号
|
||||
* </pre>
|
||||
*/
|
||||
@SerializedName("transaction_id")
|
||||
private String transactionId;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 字段名:微信分账/回退单号
|
||||
* 是否必填:是
|
||||
* 描述:微信分账/回退单号
|
||||
* </pre>
|
||||
*/
|
||||
@SerializedName("order_id")
|
||||
private String orderId;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 字段名:商户分账/回退单号
|
||||
* 是否必填:是
|
||||
* 描述:分账方系统内部的分账/回退单号
|
||||
* </pre>
|
||||
*/
|
||||
@SerializedName("out_order_no")
|
||||
private String outOrderNo;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 字段名:分账接收方
|
||||
* 是否必填:是
|
||||
* 描述:分账接收方对象
|
||||
* </pre>
|
||||
*/
|
||||
@SerializedName("receiver")
|
||||
private Receiver receiver;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 字段名:成功时间
|
||||
* 是否必填:是
|
||||
* 描述:成功时间,Rfc3339标准
|
||||
* </pre>
|
||||
*/
|
||||
@SerializedName("success_time")
|
||||
private String successTime;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public static class Receiver implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -931070141604645363L;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 字段名:分账接收方类型
|
||||
* 是否必填:是
|
||||
* 描述:MERCHANT_ID:商户号(mch_id或者sub_mch_id)
|
||||
* </pre>
|
||||
*/
|
||||
@SerializedName("type")
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 字段名:分账接收方账号
|
||||
* 是否必填:是
|
||||
* 描述:申请本功能商户号
|
||||
* </pre>
|
||||
*/
|
||||
@SerializedName("account")
|
||||
private String account;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 字段名:分账动账金额
|
||||
* 是否必填:是
|
||||
* 描述:分账动账金额,单位为分,只能为整数
|
||||
* </pre>
|
||||
*/
|
||||
@SerializedName("amount")
|
||||
private Integer amount;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 字段名:分账/回退描述
|
||||
* 是否必填:是
|
||||
* 描述:分账/回退描述
|
||||
* </pre>
|
||||
*/
|
||||
@SerializedName("description")
|
||||
private String description;
|
||||
}
|
||||
}
|
||||
@ -240,6 +240,23 @@ public interface ProfitSharingV3Service {
|
||||
*/
|
||||
ProfitSharingNotifyResult getProfitSharingNotifyResult(String notifyData, SignatureHeader header) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 分账动账通知-服务商
|
||||
*
|
||||
* 分账或分账回退成功后,微信会把相关变动结果发送给分账接收方(只支持商户)。
|
||||
* 对后台通知交互时,如果微信收到应答不是成功或超时,微信认为通知失败,微信会通过一定的策略定期重新发起通知,尽可能提高通知的成功率,但微信不保证通知最终能成功。
|
||||
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_1_10.shtml
|
||||
* </pre>
|
||||
*
|
||||
* @param notifyData 分账通知实体
|
||||
* @param header 分账通知头 {@link SignatureHeader}
|
||||
* @return {@link ProfitSharingNotifyData} 资源对象
|
||||
* @throws WxPayException the wx pay exception
|
||||
* @see <a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter8_1_10.shtml">微信文档</a>
|
||||
*/
|
||||
ProfitSharingPartnerNotifyResult getProfitSharingPartnerNotifyResult(String notifyData, SignatureHeader header) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 申请分账账单
|
||||
|
||||
@ -135,6 +135,22 @@ 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);
|
||||
return GSON.fromJson(result, ProfitSharingPartnerNotifyResult.class);
|
||||
} 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(),
|
||||
|
||||
Reference in New Issue
Block a user