Payment products supported by wechat

Through this figure, it can be clearly seen that wechat has covered a variety of payment scenarios through a total of five products. Here I want to focus on sorting out the payment scenariosThe JSAPI pay,H5 payandJSSDKPay for severalwebPayment method.

The JSAPI pay

Usage scenario: In the wechat environment, use the built-in object to initiate payment, so be sure to use the page opened by the wechat browser. JSAPI payment example code is as follows:

Function onBridgeReady(){weixinjsbridge.invoke ('getBrandWCPayRequest', {"appId":" wx2421b1C4370ec43b ", "TimeStamp ":"1395712654", Since 1970, the number of seconds "nonceStr" : "e61463f8efa94090b1f366cccfbbb444", / / a random string of "package" : "prepay_id = u802345jgfjsdfgsdg888", "SignType ":"MD5", // "PaySign" : "70 ea570631e4bb79628fbca90534c63ff7fadd89" / / WeChat signature}, Function (res){if(res.err_msg == "get_brand_wcpay_request: OK "){if(res.err_msg == "get_brand_wcpay_request: OK "){ //res.err_msg will return OK after the user has paid successfully, but it is not guaranteed to be absolutely reliable. }}); } 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(); }Copy the code

Pay JSSDK `

Usage scenario: In the wechat environment, this is not an independent payment method in the strict sense, but the JSSDK file contains a payment ability, so you can use JSAPI payment or JSSDK payment under the wechat public account, but if you do not use other SDK capabilities, it will be easier to use JSAPI payment. Document address: wechat Payment Sample code:

Wx.choosewxpay ({timestamp: 0, // Payment signature timestamp, note that all using timestamp fields in wechat JSSDK are lowercase. However, the latest version of the payment background generates the signature using the timeStamp field name needs to be capitalized with the S character nonceStr: ", // payment signature random string, not longer than 32 bits package: ", // the prepay_id parameter returned by the unified payment interface is submitted in the following format: prepay_id=\*\* * *) signType: ", // the incoming format of wechat pay V3 is RSA, and the incoming format of wechat pay V2 is the same as the signature format of V2 unified order paySign: Function (res) {}});Copy the code

H5 pay

Usage scenario: non-wechat environment, such as third-party browser or webview embedded in APP (this method is not officially advocated, but can be used, there is no problem in use, of course, it is best to access APP payment if conditions exist)

Const {requestURI} = payData; // redirect_url = payData; window.location.href = `${requestURI}&redirect_url=${encodeURIComponent(redirect_url)}`;Copy the code

conclusion

  • If theH5If you want to initiate wechat payment in the page, it can be divided according to the scene of initiating payment. If you are in wechat, you can chooseJSAPIandJSSDKPayment; If outside wechat, it can only be usedH5 pay
  • In the small programwebviewBecause the authorities blocked the payment function,JSAPIandJSSDKNeither of the two payment methods can be used, you can only jump back to the mini program page and use wechat mini program to pay.