之前的一篇文章已经详细介绍了微信公众号支付(微信公众号支付(JSAPI)对接备忘),这篇文章分析一下微信公众号支付交易的数据报文。
请求报文:
1 <xml> 2 <body><![CDATA[狄克酸奶店]]></body> 3 <callback_url><![CDATA[http://eyoukeapp.emaxcard.com/emax-travel-web/callback/paySuccess/6267964708862559233/1/0]]></callback_url> 4 <is_raw><![CDATA[1]]></is_raw> 5 <mch_create_ip><![CDATA[223.104.3.130]]></mch_create_ip> 6 <mch_id><![CDATA[102540884712]]></mch_id> 7 <nonce_str><![CDATA[D2B6428E-322B-4002-B8D5-E54019B7]]></nonce_str> 8 <notify_url><![CDATA[http://pcenter.shenbianhui.cn/QingdaoCitic/PayNotify.ashx]]></notify_url> 9 <out_trade_no><![CDATA[KB2017051000000140]]></out_trade_no> 10 <service><![CDATA[pay.weixin.jspay]]></service> 11 <sub_openid><![CDATA[o48_Ct5YigM7JDZ6x3Havr4kgzQQ]]></sub_openid> 12 <total_fee><![CDATA[1]]></total_fee> 13 <sign><![CDATA[90DD990BB86255B4D7237877070103D3]]></sign> 14 </xml>
响应报文:
1 <xml> 2 <appid><![CDATA[wx290ce4878c94369d]]></appid> 3 <charset><![CDATA[UTF-8]]></charset> 4 <mch_id><![CDATA[102540884712]]></mch_id> 5 <nonce_str><![CDATA[D2B6428E-322B-4002-B8D5-E54019B7]]></nonce_str> 6 <pay_info><![CDATA[{"appId":"wx290ce4878c94369d","timeStamp":"1494399370652","status":"0","signType":"MD5","package":"prepay_id=wx201705101456106519a1fec60778026692","callback_url":"http://eyoukeapp.emaxcard.com/emax-travel-web/callback/paySuccess/6267964708862559233/1/0","nonceStr":"1494399370652","paySign":"557EFEB8F947AF4B56D09CF4E0903C8E"}]]></pay_info> 7 <result_code><![CDATA[0]]></result_code> 8 <sign><![CDATA[C0E37C1E9805033B6A6C6227A20FE150]]></sign> 9 <sign_type><![CDATA[MD5]]></sign_type> 10 <status><![CDATA[0]]></status> 11 <token_id><![CDATA[289caaf3d0fcde3b353c300820e173f18]]></token_id> 12 <version><![CDATA[2.0]]></version> 13 </xml>
is_raw取值为1, 返回值会同时有pay_info和token_id
is_raw为1,表示是“原生态js 支付接口”。pay_info里包含了支付所需的js信息
token_id用于封装形式(“公众账号JS 支付接口”)。该请求参数为http queryString,即: https://pay.swiftpass.cn/pay/jspay?token_id=xxx。在服务号中点击这个链接就可调起支付(用户点击页面中的微信支付按钮时实际上就是点击的这个链接,此种方式无需配置支付授权目录,也不用像原生态jsapi 支付那样获取那些参数后续的操作
pay_info里最终要的两个参数是package和paySign。微信官方开发者文档里“统一下单”接口,对于公众号支付(trade_type=JSAPI)请求时,返回值即包含prepay_id,然后商户端通过对prepay_id、appid等参数加上支付密钥生成paySign。详见《签名生成算法》
{ "appId": "wx290ce4878c94369d", "timeStamp": "1494399370652", "status": "0", "signType": "MD5", "package": "prepay_id=wx201705101456106519a1fec60778026692", "callback_url": "http://eyoukeapp.emaxcard.com/emax-travel-web/callback/paySuccess/6267964708862559233/1/0", "nonceStr": "1494399370652", "paySign": "557EFEB8F947AF4B56D09CF4E0903C8E" }