微信递归授权

体验之上的产品实现

先进行静默授权,为收录资料的用户再请求显式授权,尽量优化用户的使用体验

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
verityWx () {
let href = window.location.href;
if (href.match("code=")) {
let code = href.split("code=")[1].split("&")[0];
// alert("获取到的code:" + code);
axios.get(this.serveAPI.wxLogin + code).then(res => {
if (res.data.error) {
alert(res.data.error)
} else {
// alert(JSON.stringify(res.data.object));
if (!res.data.object.wxnickName) {
// alert('新用户,进行显式授权,当前URL:' + href.split('?')[0])
window.location.href =
"https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
this.wxApp.appId +
"&redirect_uri=" +
encodeURIComponent(href.split("?")[0]) +
"&response_type=code&scope=" +
this.wxApp.scopeInfo +
"#wechat_redirect&connect_redirect=1";
} else {
// alert('授权信息' + JSON.stringify(res.data.object))
if (res.data.object.calfKey) {
// alert('已绑定的key:' + res.data.object.calfKey)
store.commit("upload", {
prope: "calfKey",
data: res.data.object.calfKey
});
this.getInviteList();
}
}
}
});
} else {
// alert('进行静默授权,当前URL:' + href)
window.location.href =
"https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
this.wxApp.appId +
"&redirect_uri=" +
encodeURIComponent(href) +
"&response_type=code&scope=" +
this.wxApp.scopeBase +
"#wechat_redirect&connect_redirect=1";
}
},