1. 在需要授权登录的页面中
if (this.$route.query.uuid) {
this.wxOpenId = this.$route.query.uuid;
};
let isWeixin = this.isWeixin();
if (isWeixin && !this.wxOpenId) {//如果是在微信浏览器端并且没有获取过权限才发起授权
this.getWxPermission();
}
// 判断是否是微信浏览器
isWeixin(){
var ua = navigator.userAgent.toLowerCase();
if(ua.match(/MicroMessenger/i)=="micromessenger") {
return true;
} else {
return false;
}
},
getWxPermission() {
wxmpLoginuUrl().then(({data}) => {
if (data.code == 0) {
window.location.href = data.data;
//data.data = "https://open.weixin.qq.com/connect/oauth2/authorize?
//appid=XXXXXXXX&redirect_uri=" +
//encodeURIComponent(local) +
//"&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect";
} else {
this.$notify({
type: "warning",
message: data.msg,
});
}
});
},
2.发起授权之后会跳转到redirect_uri页面,在redirect_uri页面通过code和state获取uuid,获取成功之后跳转到需要授权登录的页面
3693




被折叠的 条评论
为什么被折叠?



