求助:为何 分账接收方格式错误
请求接口:
//请求URL
String url = "https://api.mch.weixin.qq.com/pay/profitsharingaddreceiver";
请求参数如下:
"<xml>
<appid>wxec72c6ba2f9e427c</appid>
<mch_id>1646523746</mch_id>
<nonce_str>nvSnHhXwrN8QnC7P82RRq73SGst3j7cw</nonce_str>
<sign>01CD8D40AF3CEBD37DC45CADDDBB97D2</sign>
<receiver><![CDATA[{\"name\":\"佛山市餐饮管理有限公司\",\"relation_type\":\"STORE\",\"type\":\"MERCHANT_ID\",\"account\":\"1722227523\"}]]></receiver>
</xml>"
返回参数如下:
"<xml>
\n<return_code><![CDATA[FAIL]]></return_code>
\n<return_msg><![CDATA[分账接收方格式错误]]></return_msg>
\n</xml>"
代码如下:
// 使用新的支付商户号
String mchId = "1648888746";
String mchSerialNo = "538F3EEF7BA2678888888888888888497926293E";
String fileName = "kpsmy2.pem";
String apiV3Key = "ASDfghj8888888888888iop123456"; // V3密钥 ASDfghjklz99999999999999999923456
//请求URL
String url = "https://api.mch.weixin.qq.com/pay/profitsharingaddreceiver";
String nonce_str = getRandomString(32);
String timeStamp = String.valueOf((System.currentTimeMillis() / 1000)); // 十位时间戳
JSONObject receiver = new JSONObject();
receiver.put("type",type);//"MERCHANT_ID"
receiver.put("account",account);//"1700827523"
receiver.put("name",name);//"佛山市管理有限公司"
receiver.put("relation_type",relation_type);//"STORE"
// receiver.put("custom_relation",custom_relation);
String uri = System.getProperty("user.dir") + "/" + fileName;
PrivateKey merchantPrivateKey = getPrivateKey(uri);
Map<String, String> data2 = new HashMap<>();
data2.put("mch_id", mchId);
data2.put("appid", appId);
data2.put("nonce_str", nonce_str);
data2.put("receiver",receiver.toJSONString());
// data2.put("sign_type", "HMAC-SHA256");
String paySign = WXPay1Util.generateSignature(data2, apiV3Key); //MD5加密
String xml ="<xml>" +
"<appid>" + appId +"</appid>" +
"<mch_id>" + mchId +"</mch_id>" +
"<nonce_str>" + nonce_str +"</nonce_str>" +
"<sign>" + paySign +"</sign>" +
// "<sign_type>HMAC-SHA256</sign_type>" +
"<receiver><![CDATA["+receiver.toJSONString()+"]]></receiver>" +
"</xml>";
System.out.println(JSON.toJSONString(xml));
String result = "" ;
try {
result = HttpRequest.post(url)
.body(xml)//表单内容
.timeout(30000)//超时,毫秒
.execute().body();
}catch (Exception e){
}
System.out.println(JSON.toJSONString(result));
给你个参考https://wechatpay.im/openapi/v2/pay/profitsharingaddreceiver