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 {
const { appid, time_stamp, nonce_str, package_value, sign_type, sign } = data // 服务器返回的参数
WeixinJSBridge.invoke(
'getBrandWCPayRequest', {
appId: appid,
timeStamp: time_stamp,
nonceStr: nonce_str,
package: package_value,
signType: sign_type,
paySign: sign
},
function (res) {
if (res.err_msg === "get_brand_wcpay_request:ok") {
Toast.info('支付成功', 1, () => {
// TODO 支付成功
})
} else if (res.err_msg === "get_brand_wcpay_request:cancel") {
Toast.info('用户取消支付', 1)
} else if (res.err_msg === "get_brand_wcpay_request:fail") {
Toast.info('支付失败', 1)
}
}
)
}
/**
* 是否是微信浏览器
*/
global.isWeixin = navigator.userAgent.toLowerCase().indexOf('micromessenger') !== -1