电商收付通系列⑨,分账之添加分账接收方和请求分账

2021-02-04 10:02:46 浏览数 (2)

1、添加分账接收方

1.1、介绍

文档地址:

https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/profitsharing/chapter3_7.shtml

电商平台可通过此接口添加分账接收方,建立分账接收方列表。后续通过发起分账请求,将电商平台下的二级商户结算后的资金,分给分账接收方列表中具体的分账接收方。注意,目前只支持添加商户为分账接收方

1.2、参数实体ReceiverAddParam

代码语言:javascript复制
@Data
public class ReceiverAddParam {
    private String type;
    private String account;
    private String name;
    private String relation_type;
}

1.3、发送请求receiversAdd

代码语言:javascript复制
public static JSONObject receiversAdd() {
 ReceiverAddParam param = new ReceiverAddParam();
 param.setType("MERCHANT_ID");
 param.setAccount("分账接收方的商户号");
 param.setName("分账接收方的名称");
 param.setRelation_type("OTHERS");
 String requestParam = JSON.toJSONString(param);
 logger.info("receiversAdd param:{}",requestParam);
 HttpResponse response = HttpUtils.v3HttpExecute("POST", ProfitsharingUrl.RECEIVERS_ADD,
                "自己系统的应用名称","服务商商户号","商户API证书序列号","平台证书序列号",requestParam,"商户API证书位置.pem",null);
 JSONObject body = JSONObject.parseObject(response.body());
 logger.info("receiversAdd heads result:{}",response.headers());
 logger.info("receiversAdd body result:{}",body);
 return body;
 }

1.4、结果

代码语言:javascript复制
添加分账接收方成功 Response Body: 
    {"account":"1766445801","type":"MERCHANT_ID"}

2、分账

2.1、介绍

文档地址:

https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/profitsharing/chapter3_1.shtml

微信订单支付成功后,由电商平台发起分账请求,将结算后的资金分给分账接收方。

2.2、参数实体OrdersParam

代码语言:javascript复制
@Data
public class OrdersParam {
    private String sub_mchid;
    private String transaction_id;
    private String out_order_no;
    private List<Receiver> receivers;
    private Boolean finish;
}

2.3、参数实体Receiver

代码语言:javascript复制
@Data
public class Receiver {
    private String receiver_mchid;
    private Integer amount;
    private String description;
}

2.4、发送请求orders

代码语言:javascript复制
public static JSONObject orders() {
OrdersParam param = new OrdersParam();
param.setSub_mchid("1644580761");
param.setTransaction_id("4326600000477222420921012027");
param.setOut_order_no(System.currentTimeMillis()   "");
Receiver receiver = new Receiver();
receiver.setAmount(3);
receiver.setReceiver_mchid("1766445801");
receiver.setDescription("分给商户" receiver.getReceiver_mchid());
List<Receiver> receivers = new ArrayList<>();
receivers.add(receiver);
param.setReceivers(receivers);
param.setFinish(false);
String requestParam = JSON.toJSONString(param);
logger.info("orders param:{}",requestParam);
HttpResponse response = HttpUtils.v3HttpExecute("POST", ProfitsharingUrl.ORDERS,
                "自己系统的应用名称","服务商商户号","商户API证书序列号","平台证书序列号",requestParam,"商户API证书位置.pem",null);
JSONObject body = JSONObject.parseObject(response.body());
 logger.info("orders heads result:{}",response.headers());
 logger.info("orders body result:{}",body);
 return body;
}

2.5、结果

代码语言:javascript复制
分账成功   Response Body: 
{"order_id":"30008200140008956302003220428","out_order_no":"1524484842044","sub_mchid":"1644580761","transaction_id":"4326600000477222420921012027"}

上一篇:电商收付通系列⑧,合单下单之支付通知

0 人点赞