|
@@ -49,6 +49,7 @@ export const getUserInfo = async (e) => { |
|
@@ -49,6 +49,7 @@ export const getUserInfo = async (e) => { |
49
|
|
49
|
|
50
|
export const getPhoneNumber = async (e) => {
|
50
|
export const getPhoneNumber = async (e) => {
|
51
|
const event = global.event;
|
51
|
const event = global.event;
|
|
|
52
|
+ const app = getApp();
|
52
|
try {
|
53
|
try {
|
53
|
if (e.detail.errMsg === 'getPhoneNumber:ok') {
|
54
|
if (e.detail.errMsg === 'getPhoneNumber:ok') {
|
54
|
const srd_session = wx.getStorageSync('srd_session') || '';
|
55
|
const srd_session = wx.getStorageSync('srd_session') || '';
|
|
@@ -60,11 +61,54 @@ export const getPhoneNumber = async (e) => { |
|
@@ -60,11 +61,54 @@ export const getPhoneNumber = async (e) => { |
60
|
}
|
61
|
}
|
61
|
const bindResult = await login.bindMiniAppByAuto(union_id, phoneNumber, countryCode);
|
62
|
const bindResult = await login.bindMiniAppByAuto(union_id, phoneNumber, countryCode);
|
62
|
console.log(bindResult);
|
63
|
console.log(bindResult);
|
|
|
64
|
+ if (bindResult && bindResult.is_register === 0) {
|
|
|
65
|
+ const newUserInfo = {
|
|
|
66
|
+ is_bind: bindResult.is_bind,
|
|
|
67
|
+ mobile: bindResult.profile,
|
|
|
68
|
+ session_key: bindResult.session_key,
|
|
|
69
|
+ uid: bindResult.uid,
|
|
|
70
|
+ ssouid: bindResult.ssouid,
|
|
|
71
|
+ union_id: union_id,
|
|
|
72
|
+ vip: bindResult.vip
|
|
|
73
|
+ };
|
|
|
74
|
+
|
|
|
75
|
+ let userInfo = wx.getStorageSync('userInfo');
|
|
|
76
|
+ userInfo = Object.assign(userInfo, newUserInfo);
|
|
|
77
|
+ await setStorageWithValueForKey('userInfo', userInfo);
|
|
|
78
|
+ await setStorageWithValueForKey('sessionkey', result.session_key);
|
|
|
79
|
+
|
|
|
80
|
+ app.globalData.userInfo = userInfo;
|
|
|
81
|
+ event.emit('wechat-login-success');
|
|
|
82
|
+ event.emit('user-login-success', newUserInfo);
|
|
|
83
|
+ wx.showToast({
|
|
|
84
|
+ icon: 'none',
|
|
|
85
|
+ title: '手机号授权成功!\r\n为享受更多权益,已为您注册有货会员!',
|
|
|
86
|
+ duration: 3000
|
|
|
87
|
+ });
|
|
|
88
|
+ } else if (bindResult && bindResult.is_register === 2) {
|
|
|
89
|
+ const newUserInfo = {
|
|
|
90
|
+ is_bind: bindResult.is_bind,
|
|
|
91
|
+ mobile: bindResult.profile,
|
|
|
92
|
+ session_key: bindResult.session_key,
|
|
|
93
|
+ uid: bindResult.uid,
|
|
|
94
|
+ ssouid: bindResult.ssouid,
|
|
|
95
|
+ union_id: union_id,
|
|
|
96
|
+ vip: bindResult.vip
|
|
|
97
|
+ };
|
|
|
98
|
+
|
|
|
99
|
+ let userInfo = wx.getStorageSync('userInfo');
|
|
|
100
|
+ userInfo = Object.assign(userInfo, newUserInfo);
|
|
|
101
|
+ await setStorageWithValueForKey('userInfo', userInfo);
|
|
|
102
|
+ await setStorageWithValueForKey('sessionkey', result.session_key);
|
|
|
103
|
+
|
|
|
104
|
+ app.globalData.userInfo = userInfo;
|
|
|
105
|
+ event.emit('wechat-login-success');
|
|
|
106
|
+ event.emit('user-login-success', newUserInfo);
|
|
|
107
|
+ }
|
63
|
} else {
|
108
|
} else {
|
64
|
throw new Error('手机号获取失败,请使用手机号登录');
|
109
|
throw new Error('手机号获取失败,请使用手机号登录');
|
65
|
}
|
110
|
}
|
66
|
} catch (error) {
|
111
|
} catch (error) {
|
67
|
- console.log(error);
|
|
|
68
|
event.emit('wechat-login-error', error);
|
112
|
event.emit('wechat-login-error', error);
|
69
|
}
|
113
|
}
|
70
|
}
|
114
|
}
|
|
@@ -86,10 +130,10 @@ const wechatUnionIdIsBind = async (union_id, userInfo) => { |
|
@@ -86,10 +130,10 @@ const wechatUnionIdIsBind = async (union_id, userInfo) => { |
86
|
const newUserInfo = Object.assign(userInfo, { mobile, session_key, uid, ssouid });
|
130
|
const newUserInfo = Object.assign(userInfo, { mobile, session_key, uid, ssouid });
|
87
|
await setStorageValueForKey('userInfo', newUserInfo);
|
131
|
await setStorageValueForKey('userInfo', newUserInfo);
|
88
|
await setStorageValueForKey('sessionkey', session_key);
|
132
|
await setStorageValueForKey('sessionkey', session_key);
|
|
|
133
|
+
|
|
|
134
|
+ // 赋值全局变量
|
89
|
globalData.sessionkey = session_key;
|
135
|
globalData.sessionkey = session_key;
|
90
|
globalData.userInfo = userInfo;
|
136
|
globalData.userInfo = userInfo;
|
91
|
- // 赋值全局变量
|
|
|
92
|
-
|
|
|
93
|
// 上传保存头像
|
137
|
// 上传保存头像
|
94
|
login.sendWeChatUserData(uid, userInfo.nickName, userInfo.avatarUrl).catch(error => {});
|
138
|
login.sendWeChatUserData(uid, userInfo.nickName, userInfo.avatarUrl).catch(error => {});
|
95
|
// 触发事件登录成功
|
139
|
// 触发事件登录成功
|