//判斷是否微信瀏覽器
isWeiXin: function(){
let ua = window.navigator.userAgent.toLowerCase();
return ua.match(/MicroMessenger/i) == "micromessenger";
},
//微信授權
weixin(){
if(Util.isWeiXin()){
//在微信中打開
let banklink = encodeURIComponent(window.location.href);//提交時,網頁中
let link = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx70568d6c7bdeaa58&redirect_uri=' + banklink + '&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect';//測試
window.location.href = link;
}
},
//生命周期里的獲取code方法
let that=this;
that.code_weixin= Util.UrlSearch('code');
if(that.code_weixin){ //(如果有這個code則執行下面的)
localStorage.setItem('code_weixin',that.code_weixin); //(儲存code)
that.registerForWechatUserByH5({appType:'H5',code:that.code_weixin}); //方法調接口1
axios.post('/接口地址/',{appType:'H5',code:codeWeixin傳參 //直接調用接口2
}).then(()=>{});
}else{
that.weixin(); //(如果沒有就執行上面的微信授權方法)
}