created() {
let vm = this;
/**如果扫码进入,后端会在地址传openid;
* */
if (this.$route.query.openid !== "" || Cookies.get('SESSION')) {
return
}
let code=this.getUrlKey("code");
if (!code) {
this.getCodeApi("123");
} else {
  /*调取接口查看是否登录*/
userLogin({code:code}).then((res) => {
window.localStorage.setItem("loginState", '1');
}).catch((err)=> {
/*说明没登录*/
window.localStorage.setItem("loginState", '0');
vm.$_toast(err.message)
})
}

}
getUrlKey(name){// 获取url 参数
return decodeURIComponent((new RegExp('[?|&]'+name+'='+'([^&;]+?)(&|#|;|$)').exec(location.href)||[,""])[1].replace(/\+/g,'%20'))||null;
}
getCodeApi(state){// 获取code
let urlNow=window.location.href;
let scope='snsapi_base'; // snsapi_userinfo //静默授权 用户无感知
let appid=appId;
let url=`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${urlNow}&response_type=code&scope=${scope}&state=${state}#wechat_redirect`;
window.location.replace(url);
}

相关文章:

  • 2021-12-31
  • 2021-12-02
  • 2021-06-25
  • 2021-12-11
  • 2021-06-06
  • 2022-02-08
猜你喜欢
  • 2021-10-20
  • 2021-08-24
  • 2021-06-14
  • 2021-05-12
  • 2021-12-12
  • 2022-12-23
  • 2021-05-22
相关资源
相似解决方案