我已经是按照示例的格式了,分账金额参数也确定是int,我已经试了各种方法了,请帮忙指点一下哪里有错误,着急。。。请帮忙,谢谢!
以下是相关代码:
url = "https://api.mch.weixin.qq.com/secapi/pay/multiprofitsharing"
params = {
"appid" : APP_ID,
"mch_id": WECHAT_MCH_ID,
"sub_appid" : sub_appid,
"sub_mch_id": sub_mch_id,
"nonce_str": nonce_str_gen(),
"key": WECHAT_MCH_KEY,
}
key = WECHAT_MCH_KEY
sign_str = params_sign_HMAC_SHA256(params, key)
params['sign'] = sign_str
params['sign_type'] = 'HMAC-SHA256'
notify_res = notify_res
nPos = notify_res.find('transaction_id')
if nPos == -1:
dbg('no transaction_id')
else:
transaction_id = notify_res[nPos+18:len(notify_res)-2]
params['transaction_id'] = transaction_id
params['out_order_no'] = out_order_no
receivers = [
{'amount': 20, 'type': 'PERSONAL_WECHATID', 'account': 'jiangff666', 'description': 'agent_id:39'},
{'amount': 20, 'type': 'PERSONAL_WECHATID', 'account': 'chargerqiao', 'description': 'agent_id:41'},
{'amount': 50, 'type': 'PERSONAL_WECHATID', 'account': 'yongkundz', 'description': 'agent_id:42'}
]
params['receivers'] = receivers
xml_data = dict_to_xml(params).encode('utf-8')
cert = (
os.path.join(wechat_config['key_path'], 'apiclient_cert.pem'),
os.path.join(wechat_config['key_path'], 'apiclient_key.pem'),
)
dbg(xml_data)
r = requests.post(url, data=xml_data, cert=cert)
dbg(r)
以下是打印出的日志:
DEBUG:root:b"<xml>\n\t<transaction_id>4200000336201906154647921096</transaction_id>\n\t<receivers>[{'description': 'agent_id:39', 'account': 'jiangff666', 'type': 'PERSONAL_WECHATID', 'amount': 20}, {'description': 'agent_id:41', 'account': 'chargerqiao', 'type': 'PERSONAL_WECHATID', 'amount': 20}, {'description': 'agent_id:42', 'account': 'yongkundz', 'type': 'PERSONAL_WECHATID', 'amount': 50}]</receivers>\n\t<appid>wxfa5ecad659af258a</appid>\n\t<out_order_no>44201906151431350548</out_order_no>\n\t<sub_appid>wxebf6dac1e54f5b17</sub_appid>\n\t<sign>FBA8F708F25838C5B62884DDCC904C4810B7923BA684032144BBF9C6A31B8E62</sign>\n\t<mch_id>1533360331</mch_id>\n\t<nonce_str>NPXQMQEGZ0DR7EP3</nonce_str>\n\t<sub_mch_id>1534018591</sub_mch_id>\n\t<key>qiaoluoekejf9er3k4390234823o4p11</key>\n\t<sign_type>HMAC-SHA256</sign_type>\n</xml>\n"
INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): api.mch.weixin.qq.com
DEBUG:requests.packages.urllib3.connectionpool:"POST /secapi/pay/multiprofitsharing HTTP/1.1" 200 127
DEBUG:root:<Response [200]>
DEBUG:root:{'return_msg': '分账接收方列表格式错误', 'return_code': 'FAIL'}
盼指点,感谢!
请参看分账问题指引https://developers.weixin.qq.com/community/pay/doc/000284823e8460aada68dacca5b008?blockType=8
看了啊,只有一个相关的,回复是:“分账金额参数的类型为int才对。” 我检查我的'amount'参数类型确实是int,所以没有帮助,才来提问的,请帮忙,谢谢
分账 的amount 是以分为单位还是元为单位
解决了,receivers变为字符串就可以了