|
@@ -43,17 +43,20 @@ export default {
|
|
|
if (code === wechatLoginKey.code) {
|
|
|
this.getUserInfo(wechatLoginKey.openId);
|
|
|
} else {
|
|
|
- this.handleGetWXInfo(this.code);
|
|
|
+ // this.handleGetWXInfo(this.code);
|
|
|
+ this.handleGetWxOpenId(this.code);
|
|
|
}
|
|
|
} else {
|
|
|
- this.handleGetWXInfo(this.code);
|
|
|
+ // this.handleGetWXInfo(this.code);
|
|
|
+ this.handleGetWxOpenId(this.code);
|
|
|
}
|
|
|
} else {
|
|
|
+ // scope (snsapi_userinfo 获取用户基本信息 snsapi_base 只获取OpenId)
|
|
|
location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?
|
|
|
appid=${this.config.wxAppid}&
|
|
|
redirect_uri=${encodeURIComponent(local)}&
|
|
|
response_type=code&
|
|
|
- scope=snsapi_userinfo&
|
|
|
+ scope=snsapi_base&
|
|
|
state=STATE#wechat_redirect`;
|
|
|
}
|
|
|
},
|
|
@@ -81,6 +84,33 @@ export default {
|
|
|
uni.hideLoading();
|
|
|
});
|
|
|
},
|
|
|
+ /**
|
|
|
+ * @description: 通过code获取OpenId
|
|
|
+ * @param {*} code
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+ handleGetWxOpenId(code) {
|
|
|
+ this.$u.api
|
|
|
+ .getWxOpenidApi({ code })
|
|
|
+ .then((res) => {
|
|
|
+ if (res.code === 200) {
|
|
|
+ this.$u.vuex('vuex_wxinfo', res.data);
|
|
|
+ localStorage.setItem(
|
|
|
+ 'wechatLoginKey',
|
|
|
+ JSON.stringify({
|
|
|
+ code,
|
|
|
+ openId: res.data.openId
|
|
|
+ })
|
|
|
+ );
|
|
|
+ this.getUserInfo(res.data.openId);
|
|
|
+ } else {
|
|
|
+ uni.hideLoading();
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((err) => {
|
|
|
+ uni.hideLoading();
|
|
|
+ });
|
|
|
+ },
|
|
|
/**
|
|
|
* 通过openId获取token
|
|
|
* @param {Object} openId
|