python - 微信支付一直提示XML格式错误,哪怕是使用官方的模板。
天蓬老师
天蓬老师 2017-04-17 17:29:27
0
2
944

微信支付的统一下单接口要求这样的格式(摘自官方文档):

<xml>
   <appid>wx2421b1c4370ec43b</appid>
   <attach>支付测试</attach>
   <body>JSAPI支付测试</body>
   <mch_id>10000100</mch_id>
   <nonce_str>1add1a30ac87aa2db72f57a2375d8fec</nonce_str>
   <notify_url>http://wxpay.weixin.qq.com/pub_v2/pay/notify.v2.php</notify_url>
   <openid>oUpF8uMuAJO_M2pxb1Q9zNjWeS6o</openid>
   <out_trade_no>1415659990</out_trade_no>
   <spbill_create_ip>14.23.150.211</spbill_create_ip>
   <total_fee>1</total_fee>
   <trade_type>JSAPI</trade_type>
   <sign>0CB01533B8C1EF103065174F50BCA001</sign>
</xml> 

我POST的数据如下:

<xml>
   <appid>wx(打个码)</appid>
   <attach>支付测试</attach>
   <body>树屋树递快递到寝配送服务</body>
   <detail>树屋树递快递到寝配送服务</detail>
   <device_info>WEB</device_info>
   <fee_type>CNY</fee_type>
   <mch_id>(打个码)</mch_id>
   <nonce_str><![CDATA[7&-1ib26HO5lWFoavTwe^]]></nonce_str>
   <notify_url><![CDATA[http://www.treehouses.cn/front-4ae1dacda1f197bbfbc57ec9fbb4911f/api/wxpayresponse]]></notify_url>
   <openid><![CDATA[o8nXct499ctQzioUQt93-vyq9hgM]]></openid>
   <out_trade_no><![CDATA[60065]]></out_trade_no>
   <product_id>0001</product_id>
   <spbill_create_ip><![CDATA[49.140.188.1]]></spbill_create_ip>
   <total_fee>1</total_fee>
   <trade_type>JSAPI</trade_type>
   <sign><![CDATA[F88FABC7BFD25B726864DC6D6FC8313B]]></sign>
</xml>

微信服务器返回的结果是:

<xml><return_code><![CDATA[FAIL]]></return_code>
<return_msg><![CDATA[XML格式错误]]></return_msg>
</xml>
天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
洪涛

I tried it based on your data, but it didn’t prompt that the XML format was incorrect, only that the signature was wrong.

So check the code again.
Check out any coding issues in Python.

This can be tested and passed:

<xml>
   <appid>wx2421b1c4370ec43b</appid>
   <attach>支付测试</attach>
   <body>树屋树递快递到寝配送服务</body>
   <detail>树屋树递快递到寝配送服务</detail>
   <device_info>WEB</device_info>
   <fee_type>CNY</fee_type>
   <mch_id>10000100</mch_id>
   <nonce_str><![CDATA[7&-1ib26HO5lWFoavTwe^]]></nonce_str>
   <notify_url><![CDATA[http://www.treehouses.cn/front-4ae1dacda1f197bbfbc57ec9fbb4911f/api/wxpayresponse]]></notify_url>
   <openid><![CDATA[o8nXct499ctQzioUQt93-vyq9hgM]]></openid>
   <out_trade_no><![CDATA[60065]]></out_trade_no>
   <product_id>0001</product_id>
   <spbill_create_ip><![CDATA[49.140.188.1]]></spbill_create_ip>
   <total_fee>1</total_fee>
   <trade_type>JSAPI</trade_type>
   <sign><![CDATA[F88FABC7BFD25B726864DC6D6FC8313B]]></sign>
</xml>
洪涛

1.<product_id>0001</product_id> The official template does not have this record

2. Even if it can be written like this, it cannot be 0001. This is the octal writing method. You should write 1 instead of 0001

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!