...
|
...
|
@@ -49,6 +49,7 @@ export const getUserInfo = async (e) => { |
|
|
|
|
|
export const getPhoneNumber = async (e) => {
|
|
|
const event = global.event;
|
|
|
const app = getApp();
|
|
|
try {
|
|
|
if (e.detail.errMsg === 'getPhoneNumber:ok') {
|
|
|
const srd_session = wx.getStorageSync('srd_session') || '';
|
...
|
...
|
@@ -60,11 +61,54 @@ export const getPhoneNumber = async (e) => { |
|
|
}
|
|
|
const bindResult = await login.bindMiniAppByAuto(union_id, phoneNumber, countryCode);
|
|
|
console.log(bindResult);
|
|
|
if (bindResult && bindResult.is_register === 0) {
|
|
|
const newUserInfo = {
|
|
|
is_bind: bindResult.is_bind,
|
|
|
mobile: bindResult.profile,
|
|
|
session_key: bindResult.session_key,
|
|
|
uid: bindResult.uid,
|
|
|
ssouid: bindResult.ssouid,
|
|
|
union_id: union_id,
|
|
|
vip: bindResult.vip
|
|
|
};
|
|
|
|
|
|
let userInfo = wx.getStorageSync('userInfo');
|
|
|
userInfo = Object.assign(userInfo, newUserInfo);
|
|
|
await setStorageWithValueForKey('userInfo', userInfo);
|
|
|
await setStorageWithValueForKey('sessionkey', result.session_key);
|
|
|
|
|
|
app.globalData.userInfo = userInfo;
|
|
|
event.emit('wechat-login-success');
|
|
|
event.emit('user-login-success', newUserInfo);
|
|
|
wx.showToast({
|
|
|
icon: 'none',
|
|
|
title: '手机号授权成功!\r\n为享受更多权益,已为您注册有货会员!',
|
|
|
duration: 3000
|
|
|
});
|
|
|
} else if (bindResult && bindResult.is_register === 2) {
|
|
|
const newUserInfo = {
|
|
|
is_bind: bindResult.is_bind,
|
|
|
mobile: bindResult.profile,
|
|
|
session_key: bindResult.session_key,
|
|
|
uid: bindResult.uid,
|
|
|
ssouid: bindResult.ssouid,
|
|
|
union_id: union_id,
|
|
|
vip: bindResult.vip
|
|
|
};
|
|
|
|
|
|
let userInfo = wx.getStorageSync('userInfo');
|
|
|
userInfo = Object.assign(userInfo, newUserInfo);
|
|
|
await setStorageWithValueForKey('userInfo', userInfo);
|
|
|
await setStorageWithValueForKey('sessionkey', result.session_key);
|
|
|
|
|
|
app.globalData.userInfo = userInfo;
|
|
|
event.emit('wechat-login-success');
|
|
|
event.emit('user-login-success', newUserInfo);
|
|
|
}
|
|
|
} else {
|
|
|
throw new Error('手机号获取失败,请使用手机号登录');
|
|
|
}
|
|
|
} catch (error) {
|
|
|
console.log(error);
|
|
|
event.emit('wechat-login-error', error);
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -86,10 +130,10 @@ const wechatUnionIdIsBind = async (union_id, userInfo) => { |
|
|
const newUserInfo = Object.assign(userInfo, { mobile, session_key, uid, ssouid });
|
|
|
await setStorageValueForKey('userInfo', newUserInfo);
|
|
|
await setStorageValueForKey('sessionkey', session_key);
|
|
|
|
|
|
// 赋值全局变量
|
|
|
globalData.sessionkey = session_key;
|
|
|
globalData.userInfo = userInfo;
|
|
|
// 赋值全局变量
|
|
|
|
|
|
// 上传保存头像
|
|
|
login.sendWeChatUserData(uid, userInfo.nickName, userInfo.avatarUrl).catch(error => {});
|
|
|
// 触发事件登录成功
|
...
|
...
|
|