diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ProfitSharingRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ProfitSharingRequest.java new file mode 100644 index 0000000000..aaec33bd07 --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ProfitSharingRequest.java @@ -0,0 +1,192 @@ +package com.github.binarywang.wxpay.bean.ecommerce; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * 请求分账 对象 + *
+ *   文档地址:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/profitsharing/chapter3_1.shtml
+ * 
+ * @author: f00lish + * @date: 2020/09/12 + */ +@Data +@NoArgsConstructor +public class ProfitSharingRequest implements Serializable { + + private static final long serialVersionUID = -8662837652326828377L; + /** + *
+   * 字段名:公众账号ID
+   * 变量名:appid
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  微信分配的公众账号ID。
+   *  示例值:wx8888888888888888
+   * 
+ */ + @SerializedName(value = "appid") + private String appid; + + /** + *
+   * 字段名:二级商户号
+   * 变量名:sub_mchid
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  分账出资的电商平台二级商户,填写微信支付分配的商户号。
+   *  示例值:1900000109
+   * 
+ */ + @SerializedName(value = "sub_mchid") + private String subMchid; + + /** + *
+   * 字段名:微信订单号
+   * 变量名:transaction_id
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  微信支付订单号。
+   *  示例值:4208450740201411110007820472
+   * 
+ */ + @SerializedName(value = "transaction_id") + private String transactionId; + + /** + *
+   * 字段名:商户分账单号
+   * 变量名:out_order_no
+   * 是否必填:是
+   * 类型:string(64)
+   * 描述:
+   *  商户系统内部的分账单号,在商户系统内部唯一(单次分账、多次分账、完结分账应使用不同的商户分账单号),同一分账单号多次请求等同一次。
+   *  示例值:P20150806125346
+   * 
+ */ + @SerializedName(value = "out_order_no") + private String outOrderNo; + + /** + *
+   * 字段名:分账接收方列表
+   * 变量名:receivers
+   * 是否必填:是
+   * 类型:array
+   * 描述:
+   *  分账接收方列表,支持设置出资商户作为分账接收方,单次分账最多可有5个分账接收方
+   * 
+ */ + @SerializedName(value = "receivers") + private Receiver[] receivers; + + /** + *
+   * 字段名:是否分账完成
+   * 变量名:finish
+   * 是否必填:是
+   * 类型:bool
+   * 描述:
+   *  是否完成分账
+   *  1、如果为true,该笔订单剩余未分账的金额会解冻回电商平台二级商户;
+   *  2、如果为false,该笔订单剩余未分账的金额不会解冻回电商平台二级商户,可以对该笔订单再次进行分账。
+   *  示例值:true
+   * 
+ */ + @SerializedName(value = "finish") + private Boolean finish; + + @Data + @NoArgsConstructor + public static class Receiver implements Serializable { + + private static final long serialVersionUID = 8995144356011793136L; + + /** + *
+     * 字段名:分账接收方类型
+     * 变量名:type
+     * 是否必填:否
+     * 类型:string(32)
+     * 描述:
+     *  分账接收方类型,枚举值:
+     *  MERCHANT_ID:商户
+     *  PERSONAL_OPENID:个人
+     *  示例值:MERCHANT_ID
+     * 
+ */ + @SerializedName(value = "type") + private String type; + + /** + *
+     * 字段名:分账接收方账号
+     * 变量名:receiver_account
+     * 是否必填:是
+     * 类型:string(32)
+     * 描述:
+     *  分账接收方账号:
+     *  类型是MERCHANT_ID时,是商户ID
+     *  类型是PERSONAL_OPENID时,是个人openid,openid获取方法 https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/guide/chapter2_1.shtml#menu1
+     *  示例值:1900000109
+     * 
+ */ + @SerializedName(value = "receiver_account") + private String receiverAccount; + + /** + *
+     * 字段名:分账金额
+     * 变量名:amount
+     * 是否必填:是
+     * 类型:int
+     * 描述:
+     *  分账金额,单位为分,只能为整数,不能超过原订单支付金额及最大分账比例金额。
+     *  示例值:190
+     * 
+ */ + @SerializedName(value = "amount") + private Integer amount; + + /** + *
+     * 字段名:分账描述
+     * 变量名:description
+     * 是否必填:是
+     * 类型:string(180)
+     * 描述:
+     *  分账的原因描述,分账账单中需要体现。
+     *  示例值:分给商户1900000109
+     * 
+ */ + @SerializedName(value = "description") + private String description; + + /** + *
+     * 字段名:分账个人姓名
+     * 变量名:receiver_name
+     * 是否必填:否
+     * 类型:string(10240)
+     * 描述:
+     *  可选项,在接收方类型为个人的时可选填,若有值,会检查与 receiver_name 是否实名匹配,不匹配会拒绝分账请求
+     *  1、分账接收方类型是PERSONAL_OPENID时,是个人姓名的密文(选传,传则校验) 此字段的加密方法详见:敏感信息加密说明
+     *  2、使用微信支付平台证书中的公钥
+     *  3、使用RSAES-OAEP算法进行加密
+     *  4、将请求中HTTP头部的Wechatpay-Serial设置为证书序列号
+     *  示例值:hu89ohu89ohu89o
+     * 
+ */ + @SerializedName(value = "receiver_name") + private String receiverName; + + } +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ProfitSharingResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ProfitSharingResult.java new file mode 100644 index 0000000000..4a79586654 --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ProfitSharingResult.java @@ -0,0 +1,71 @@ +package com.github.binarywang.wxpay.bean.ecommerce; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +/** + * 请求分账 结果响应 + * @author: f00lish + * @date: 2020/09/12 + */ +public class ProfitSharingResult implements Serializable { + + private static final long serialVersionUID = 9026456165403642050L; + /** + *
+   * 字段名:二级商户号
+   * 变量名:sub_mchid
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  分账出资的电商平台二级商户,填写微信支付分配的商户号。
+   *  示例值:1900000109
+   * 
+ */ + @SerializedName(value = "sub_mchid") + private String subMchid; + + /** + *
+   * 字段名:微信订单号
+   * 变量名:transaction_id
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  微信支付订单号。
+   *  示例值:4208450740201411110007820472
+   * 
+ */ + @SerializedName(value = "transaction_id") + private String transactionId; + + /** + *
+   * 字段名:商户分账单号
+   * 变量名:out_order_no
+   * 是否必填:是
+   * 类型:string(64)
+   * 描述:
+   *  商户系统内部的分账单号,在商户系统内部唯一(单次分账、多次分账、完结分账应使用不同的商户分账单号),同一分账单号多次请求等同一次。
+   *  示例值:P20150806125346
+   * 
+ */ + @SerializedName(value = "out_order_no") + private String outOrderNo; + + /** + *
+   * 字段名:微信分账单号
+   * 变量名:order_id
+   * 是否必填:是
+   * 类型:string (64)
+   * 描述:
+   *  微信分账单号,微信系统返回的唯一标识。
+   *  示例值:6754760740201411110007865434
+   * 
+ */ + @SerializedName(value = "order_id") + private String orderId; + +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java index 095865067e..e2d6199cd6 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java @@ -174,4 +174,16 @@ public interface EcommerceService { * @return 返回数据 */ FundBalanceResult subDayEndBalance(String subMchid, String date) throws WxPayException; + + /** + *
+   * 请求分账API
+   * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/profitsharing/chapter3_1.shtml
+   * 
+ * + * @param request 分账请求 + * @return 返回数据 + */ + ProfitSharingResult profitSharing(ProfitSharingRequest request) throws WxPayException; + } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImpl.java index c0d45e87e5..07cd559cfd 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImpl.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImpl.java @@ -148,6 +148,13 @@ public FundBalanceResult subDayEndBalance(String subMchid, String date) throws W return GSON.fromJson(response, FundBalanceResult.class); } + @Override + public ProfitSharingResult profitSharing(ProfitSharingRequest request) throws WxPayException { + String url = String.format("%s/v3/ecommerce/profitsharing/orders", this.payService.getPayBaseUrl()); + String response = this.payService.postV3(url, GSON.toJson(request)); + return GSON.fromJson(response, ProfitSharingResult.class); + } + private boolean verifyNotifySign(SignatureHeader header, String data) { String beforeSign = String.format("%s\n%s\n%s\n", header.getTimeStamp(),