javascript - WeChat payment: H5 calls up the payment API and directly says that the payment failed
巴扎黑
巴扎黑 2017-05-17 10:04:16
0
4
701
  1. I am using java to develop WeChat’s official account payment function, using the internal payment function of the official account

In the first step, the unified ordering interface has been opened, and prepay_id can be obtained (the code will be posted below). However, when calling the payment API through JS,the direct return is failure., the window for calling WeChat payment flashes,In fact, the payment control is not called up at all, and I don’t know what went wrong. I can only call it on my mobile phone to view it, and I can’t conduct follow-up investigations. , the data from alert is a direct failure. The specific JS code is as follows

function onBridgeReady(){ var param = {}; param.openid = openid; param.orderAmount = 11; param.stageid = 2007; console.log(param); //通过下面接口获取统一下单接口参数 var url = puburl + "/wxpay/createOrderinfo"; var data = ajaxUtil.ajaxJson(url, JSON.stringify(param)); console.log(data); if(data.code != 0) { console.log(data); return false; } var result = data.data; alert(JSON.stringify(result)); //上面接口已经获取接口需要的数据, //根据微信官方提供的demo就是通过下面方式进行参数赋值 WeixinJSBridge.invoke( 'getBrandWCPayRequest', { "appId":result.appId, "timeStamp":result.timeStamp, "nonceStr":result.nonceStr, "package":result.prepay_id, "signType":result.signType, "paySign":result.paySign }, function(res){ //可是程序走到这一步 //打印出 res.err_msg的结果直接就是:get_brand_wcpay_request:fail //只能在手机上调试,无法查看具体错误原因 alert(res.err_msg); // 使用以上方式判断前端返回, //微信团队郑重提示:res.err_msg将在用户支付成功后返回ok, //但并不保证它绝对可靠。 if(res.err_msg == "get_brand_wcpay_request:ok" ) { alert("支付成功!") } else if(res.err_msg == "get_brand_wcpay_request:cancel") { alert("支付取消!"); } else if(res.err_msg == "get_brand_wcpay_request:fail") { alert("支付失败!"); } } ); } if (typeof WeixinJSBridge == "undefined"){ if( document.addEventListener ){ document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false); }else if (document.attachEvent){ document.attachEvent('WeixinJSBridgeReady', onBridgeReady); document.attachEvent('onWeixinJSBridgeReady', onBridgeReady); } }else{ onBridgeReady(); }

I hope you guys can see if there is any problem. If the specific description is not clear, please point it out and I will explain or post the code

Supplement: The configured payment authorization directory and the path to the payment page are consistent. This has been carefully confirmed and there are no problems!

巴扎黑
巴扎黑

reply all (4)
为情所困

Dear, is your WeChat payment authorization URL configured correctly? In addition, http and https must strictly match

    曾经蜡笔没有小新

    Did the Tune-in order be placed successfully? If successful, check to see if the signature is correct, and then check the payment directory configuration. What are the specific prompts returned by WeChat?

      phpcn_u1582

      In this case, either the signature is wrong or the payment path is wrong.
      In case of failure, type out the entire res, and WeChat will return other information, not just err_msg

      Is your package parameter wrong? The parameter value is prepay_id=xxx

        小葫芦

        timestamp: 0, // Payment signature timestamp. Note that all timestamp fields used in WeChat jssdk are lowercase. However, the timeStamp field name used by the latest version of the payment background to generate signatures needs to capitalize the S character

        I don’t know if it’s the case of the fields?

          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!