1.首先判断它是否是微信浏览器,只有在微信浏览器才能拉去微信支付,其他的需要走H5支付流程
// 判断是否是微信浏览器
isWx() {
let uAgent = navigator.userAgent.toLowerCase();
return /micromessenger/.test(uAgent) ? true : false;
},
2.需要后端接口提供你一个openId
// 支付按钮
async goPay() {
if (this.isWx()) {
let data1 = await getOpenId();
if (data1.data == "") {
let url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx284cfd5aae6b9a3a&redirect_uri=${encodeURIComponent(
window.location.href
)}&response_type=code&scope=snsapi_userinfo&state=2#wechat_redirect`;
window.location.href = url;
console.log(window.location.href);
// return false;
} else {
//微信支付流程
this.WXPay();
}
} else {
//