|
|
@@ -152,46 +152,56 @@ Component({
|
|
|
showLoading: true,
|
|
|
disableCommitBtn: true,
|
|
|
});
|
|
|
- wx.request({
|
|
|
- url: `${homeApi_empower}/wxlogin`,
|
|
|
- data: {
|
|
|
- code: that.data.wxCode,
|
|
|
- token: token_empower,
|
|
|
- nickname: that.data.nickName,
|
|
|
- encryptphone: that.data.encryptphone
|
|
|
- },
|
|
|
- method: 'POST',
|
|
|
- success: function (loginRes) {
|
|
|
- console.log('loginRes=' + JSON.stringify(loginRes));
|
|
|
- console.log('loginRes.data=' + JSON.stringify(loginRes.data));
|
|
|
- if (loginRes.data.codes && loginRes.data.codes == 'success') {
|
|
|
- console.log('123123123');
|
|
|
- console.log('loginRes.data.back.unionid=' + loginRes.data.back.unionid);
|
|
|
- console.log('loginRes.data.back.openid=' + loginRes.data.back.openid);
|
|
|
- wx.setStorageSync('unionid', loginRes.data.back.unionid);
|
|
|
- wx.setStorageSync('openid', loginRes.data.back.openid);
|
|
|
- // 获取后台授权
|
|
|
- that.startInterval();
|
|
|
- // 可以在这里提示用户进行手机号授权
|
|
|
- that.setData({
|
|
|
- unionid: loginRes.data.back.unionid,
|
|
|
- openid: loginRes.data.back.openid,
|
|
|
- session_key: loginRes.data.back.session_key,
|
|
|
- });
|
|
|
- } else {
|
|
|
- that.setData({ showLoading: false });
|
|
|
- wx.showToast({
|
|
|
- title: '后台授权失败',
|
|
|
- icon: 'none'
|
|
|
+ wx.login({
|
|
|
+ success: res => {
|
|
|
+ if (res.code) {
|
|
|
+ // 发送 code 到服务器换取 session_key, openid
|
|
|
+ console.log('res.code==' + res.code);
|
|
|
+ that.setData({ wxCode: res.code })
|
|
|
+
|
|
|
+ wx.request({
|
|
|
+ url: `${homeApi_empower}/wxlogin`,
|
|
|
+ data: {
|
|
|
+ code: that.data.wxCode,
|
|
|
+ token: token_empower,
|
|
|
+ nickname: that.data.nickName,
|
|
|
+ encryptphone: that.data.encryptphone
|
|
|
+ },
|
|
|
+ method: 'POST',
|
|
|
+ success: function (loginRes) {
|
|
|
+ console.log('loginRes=' + JSON.stringify(loginRes));
|
|
|
+ console.log('loginRes.data=' + JSON.stringify(loginRes.data));
|
|
|
+ if (loginRes.data.codes && loginRes.data.codes == 'success') {
|
|
|
+ console.log('123123123');
|
|
|
+ console.log('loginRes.data.back.unionid=' + loginRes.data.back.unionid);
|
|
|
+ console.log('loginRes.data.back.openid=' + loginRes.data.back.openid);
|
|
|
+ wx.setStorageSync('unionid', loginRes.data.back.unionid);
|
|
|
+ wx.setStorageSync('openid', loginRes.data.back.openid);
|
|
|
+ // 获取后台授权
|
|
|
+ that.startInterval();
|
|
|
+ // 可以在这里提示用户进行手机号授权
|
|
|
+ that.setData({
|
|
|
+ unionid: loginRes.data.back.unionid,
|
|
|
+ openid: loginRes.data.back.openid,
|
|
|
+ session_key: loginRes.data.back.session_key,
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ that.setData({ showLoading: false });
|
|
|
+ wx.showToast({
|
|
|
+ title: '后台授权失败',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: function () {
|
|
|
+ that.setData({ showLoading: false });
|
|
|
+ wx.showToast({
|
|
|
+ title: '后台授权失败',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
- },
|
|
|
- fail: function () {
|
|
|
- that.setData({ showLoading: false });
|
|
|
- wx.showToast({
|
|
|
- title: '后台授权失败',
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
}
|
|
|
});
|
|
|
|