...
|
...
|
@@ -121,44 +121,7 @@ function wechatUserIsBind(unionID, nickName) { |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取unionID、如果用户拒绝授权则无法获得unionID
|
|
|
* @param srd_session
|
|
|
* @param showMsg
|
|
|
* @returns {Promise.<T>}
|
|
|
*/
|
|
|
function getUnionID(srd_session, showMsg) {
|
|
|
let nickName;
|
|
|
let app = getApp();
|
|
|
|
|
|
return wx.getUserInfo()
|
|
|
.then(res => {
|
|
|
let userInfo = res.userInfo;
|
|
|
|
|
|
nickName = userInfo.nickName;
|
|
|
return accountModel.decodeUserInfo(srd_session, res.encryptedData, res.iv);
|
|
|
})
|
|
|
.then(data => {
|
|
|
if (data.data.union_id) {
|
|
|
app.setUnionID(data.data.union_id);
|
|
|
return wechatUserIsBind(data.data.union_id, nickName);
|
|
|
}
|
|
|
})
|
|
|
.catch(() => {
|
|
|
let msg = {
|
|
|
succeed: false,
|
|
|
message: '使用微信小程序登录需要微信授权,您已经拒绝了该请求,请删除小程序重新进入。'
|
|
|
};
|
|
|
|
|
|
if (showMsg) {
|
|
|
msg.code = 10001;
|
|
|
}
|
|
|
return Promise.reject(msg);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 微信授权登录
|
|
|
* @param showMsg
|
|
|
* @returns {Promise.<T>}
|
|
|
*/
|
|
|
function wechatAuthLogin() { // showMsg: 是否显示拒绝授权提示
|
...
|
...
|
@@ -188,7 +151,6 @@ function wechatAuthLogin() { // showMsg: 是否显示拒绝授权提示 |
|
|
// change: 微信不再支持直接调用wx.getUserInfo
|
|
|
// return getUnionID(data.srd_session, showMsg);
|
|
|
} else {
|
|
|
wx.getUserInfo();
|
|
|
app.setUnionID(data.unionid);
|
|
|
return wechatUserIsBind(data.unionid, '');
|
|
|
}
|
...
|
...
|
@@ -200,63 +162,6 @@ function wechatAuthLogin() { // showMsg: 是否显示拒绝授权提示 |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 用户手动点击登录
|
|
|
* @returns {Promise.<T>}
|
|
|
*/
|
|
|
function tapToLogin() {
|
|
|
let app = getApp();
|
|
|
let router = global.router;
|
|
|
|
|
|
if (wx.getSetting) {
|
|
|
return wx.getSetting()
|
|
|
.then(res => {
|
|
|
if (res.authSetting['scope.userInfo']) {
|
|
|
return router.go('bindMobile');
|
|
|
} else {
|
|
|
return wx.showModal({
|
|
|
title: '',
|
|
|
content: '检测到您未打开微信用户信息授权,开启后即可进行登录',
|
|
|
confirmText: '去开启',
|
|
|
confirmColor: '#000000'
|
|
|
});
|
|
|
}
|
|
|
})
|
|
|
.then(res => {
|
|
|
if (res.confirm) {
|
|
|
return wx.openSetting();
|
|
|
}
|
|
|
|
|
|
if (res.cancel) {
|
|
|
return router.go('bindMobile');
|
|
|
}
|
|
|
})
|
|
|
.then(res => {
|
|
|
if (res.authSetting['scope.userInfo'] && res.authSetting['scope.userInfo'] === true) {
|
|
|
return getUnionID(app.getWechatThirdSession());
|
|
|
}
|
|
|
})
|
|
|
.then(res => {
|
|
|
if (res.code === 10003) { // 已经绑定手机号
|
|
|
app.setUserInfo(res.data);
|
|
|
app.setSessionKey(res.data.sessionKey);
|
|
|
event.emit('user-login-success');
|
|
|
event.emit('login-type-report', {LOGIN_TYPE: 4});
|
|
|
}
|
|
|
|
|
|
if (res.code === 10004) { // 手动授权登录未绑定强制绑定
|
|
|
return router.go('bindMobile');
|
|
|
}
|
|
|
})
|
|
|
.catch(() => {});
|
|
|
} else {
|
|
|
return wx.showModal({
|
|
|
title: '提示',
|
|
|
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* open-type获取用户信息登录绑定
|
|
|
*/
|
|
|
function getUserInfoLogin(e) {
|
...
|
...
|
@@ -392,7 +297,6 @@ export { |
|
|
isNeedImgCheck,
|
|
|
getVerifyCode,
|
|
|
bindMobileAction,
|
|
|
tapToLogin,
|
|
|
verifySessionKey,
|
|
|
getPhoneNumber,
|
|
|
getUserInfoLogin
|
...
|
...
|
|