1、添加分账接收方
1.1、介绍
文档地址:
https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/profitsharing/chapter3_7.shtml
电商平台可通过此接口添加分账接收方,建立分账接收方列表。后续通过发起分账请求,将电商平台下的二级商户
结算后的资金,分给分账接收方列表中具体的分账接收方。
1.2、参数实体ReceiverAddParam
public class ReceiverAddParam {
private String type;
private String account;
private String name;
private String relation_type;
}
1.3、发送请求receiversAdd
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、结果
{"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
@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
@Data
public class Receiver {
private String receiver_mchid;
private Integer amount;
private String description;
}
2.4、发送请求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、结果
{"order_id":"30008200140008956302003220428","out_order_no":"1524484842044","sub_mchid":"1644580761","transaction_id":"4326600000477222420921012027"}
山水有相逢,来日皆可期,谢谢阅读,我们再会
我手中的金箍棒,上能通天,下能探海