This is the fourth day of my participation in the August More text Challenge. For details, see:August is more challenging
Personal technical blog, wechat official account, video account and design portfolio of the blogger
1. Get the built-in browser id
WeChat: export function isWeixin () {var ua = window. The navigator. UserAgent. ToLowerCase (); if(ua.match(/MicroMessenger/i) == 'micromessenger'){ return true; } return false; }Copy the code
Pay treasure:export function isAlipay() {
var ua = window.navigator.userAgent.toLowerCase();
if(ua.match(/Alipay/i) = ="alipay") {return true;
}
return false;
}
Copy the code
2. Methods (data processing)
The couponOrder interface returns (the interface returns the required payment parameter information before calling the payment)
Wechat Pay (two methods) :
1. JSAPI Payment: There is a tutorial in the menu bar of wechat Pay. There is a small menu that uses the JS API to initiate payment requests
WeixinJSBridge.invoke()
- The WeixinJSBridge built-in object is not valid in other browsers.
- GetBrandWCPayRequest parameter and return value definition
WeixinJSBridge.invoke(
'getBrandWCPayRequest', {
'appId': response.appId, // Public id
'timeStamp': response.timeStamp, // The current timestamp
'nonceStr': response.nonceStr, // Pay the signature random string
'package': response.package, // Order details extension string, prepay_id=****
'signType': response.signType, // The default signature type is MD5
'paySign': response.paySign // Pay the signature
},
(res2) = >{
if (res2.err_msg === 'get_brand_wcpay_request:ok') {
this.toSuccess(code, payMoney, payTool);
} else if (res2.err_msg === 'get_brand_wcpay_request:fail') {
MessageBox('Error message'."Payment failure");
}else if (res2.err_msg === 'get_brand_wcpay_request:cancel') {
MessageBox('Error message'."Payment failure"); }});Copy the code
Reference: pay.weixin.qq.com/wiki/doc/ap…
2. Wechat JS-SDK description document initiates the request API of wechat Pay
Wx.choosewxpay () is called after signing
wx.chooseWXPay({
timestamp: 0.// Pay the signature time stamp,
nonceStr: ' '.// The payment signature is a random string, no longer than 32 bits
package: ' '.// Order details extension string
signType: ' '.// Signature mode, default is 'SHA1', to use the new version, pass 'MD5'
paySign: ' '.// Pay the signature
success: function (res) {
// The callback function for successful payment}});Copy the code
Alipay pays alipayJsbridge-call
AlipayJSBridge.call("tradePay", {
orderStr: response.ali
}, (result) = >{
let resultCode = result.resultCode;
// alert(JSON.stringify(result))
if(resultCode == "9000") {
this.toSuccess(code, payMoney, payTool);
}else if(resultCode == "4000"){
MessageBox('Error message'."Payment failure");
}else if(resultCode == "6001"){
MessageBox('Error message'."Cancellation of payment"); }})Copy the code
Reference: myjsapi.alipay.com/jsapi/nativ…