| @@ -23,6 +23,7 @@ App({ | |||||
| // // 发送 res.code 到后台换取 openId, sessionKey, unionId | // // 发送 res.code 到后台换取 openId, sessionKey, unionId | ||||
| // } | // } | ||||
| // }) | // }) | ||||
| this.loginGettoken() | this.loginGettoken() | ||||
| }, | }, | ||||
| globalData: { | globalData: { | ||||
| @@ -32,6 +33,8 @@ App({ | |||||
| //登录-获取token | //登录-获取token | ||||
| loginGettoken(){ | loginGettoken(){ | ||||
| let that = this | let that = this | ||||
| wx.setStorageSync('token', '') | |||||
| wx.setStorageSync('userInfo', '') | |||||
| wx.login({ | wx.login({ | ||||
| success (res) { | success (res) { | ||||
| if (res.code) { | if (res.code) { | ||||
| @@ -46,7 +49,6 @@ App({ | |||||
| }, | }, | ||||
| success(res1) { | success(res1) { | ||||
| if (res1.statusCode == 200) { | if (res1.statusCode == 200) { | ||||
| let userInfo = res1.data.user_info | |||||
| that.globalData.token = res1.data.access_token | that.globalData.token = res1.data.access_token | ||||
| that.globalData.userInfo = res1.data.user_info | that.globalData.userInfo = res1.data.user_info | ||||
| // console.log(that.globalData.token) | // console.log(that.globalData.token) | ||||
| @@ -57,7 +57,6 @@ Page({ | |||||
| }, | }, | ||||
| shouquan(){ | shouquan(){ | ||||
| let userInfo = wx.getStorageSync('userInfo') | |||||
| if(userInfo.phone){ | if(userInfo.phone){ | ||||
| wx.showToast({ | wx.showToast({ | ||||
| icon: 'none', | icon: 'none', | ||||
| @@ -87,64 +86,6 @@ Page({ | |||||
| url: '/pages/out/index?index=1&userid='+ this.data.userid+'&gameid=1'+'&type=2', | url: '/pages/out/index?index=1&userid='+ this.data.userid+'&gameid=1'+'&type=2', | ||||
| }) | }) | ||||
| }, | }, | ||||
| //登录-获取token | |||||
| loginGettoken(){ | |||||
| let that = this | |||||
| wx.login({ | |||||
| success (res) { | |||||
| if (res.code) { | |||||
| //发起网络请求 | |||||
| wx.request({ | |||||
| url:'https://cktest.2weisou.com/meta/auth/mobile/token/social?grant_type=mobil&mobile=MINI_C@'+res.code+'@'+'', | |||||
| method: "POST", | |||||
| data: { | |||||
| }, | |||||
| header: { | |||||
| Authorization: "Basic YXBwbGV0OmFwcGxldA==", | |||||
| }, | |||||
| success(res1) { | |||||
| if (res1.statusCode == 200) { | |||||
| let userInfo = res1.data.user_info | |||||
| that.setData({ | |||||
| token: res1.data.access_token, | |||||
| userid: userInfo.id, | |||||
| userInfo: userInfo | |||||
| }) | |||||
| wx.setStorageSync('token', res1.data.access_token) | |||||
| wx.setStorageSync('userInfo', userInfo) | |||||
| if(!!userInfo.userWxName&&!!userInfo.phone){ | |||||
| that.leave() | |||||
| return; | |||||
| } | |||||
| if(!userInfo.userWxName||!userInfo.phone){ | |||||
| that.setData({ | |||||
| showBg: true | |||||
| }) | |||||
| }else{ | |||||
| that.setData({ | |||||
| showBg: false | |||||
| }) | |||||
| } | |||||
| that.setData({ | |||||
| avatarModal: !!userInfo.userWxName?false:true, | |||||
| phoneModal1: !!userInfo.phone?false:true, | |||||
| step: 1 | |||||
| }) | |||||
| if(!that.data.avatarModal){ | |||||
| that.setData({ | |||||
| step: 2, | |||||
| phoneModal: that.data.phoneModal1 | |||||
| }) | |||||
| } | |||||
| } | |||||
| } | |||||
| }) | |||||
| } else { | |||||
| console.log('登录失败!' + res.errMsg) | |||||
| } | |||||
| } | |||||
| }) | |||||
| }, | |||||
| // 绑定用户头像信息 | // 绑定用户头像信息 | ||||
| bindNickname(obj) { | bindNickname(obj) { | ||||
| let that = this | let that = this | ||||
| @@ -1,4 +1,5 @@ | |||||
| // pages/out/index.js | |||||
| Page({ | Page({ | ||||
| /** | /** | ||||
| @@ -13,10 +14,8 @@ Page({ | |||||
| }, | }, | ||||
| closeShare(){ | closeShare(){ | ||||
| // wx.navigateBack({ | |||||
| // delta: 1 | |||||
| // }) | |||||
| let userInfo = wx.getStorageSync('userInfo') | |||||
| let userInfo = getApp().globalData.userInfo | |||||
| console.log(userInfo) | |||||
| wx.navigateTo({ | wx.navigateTo({ | ||||
| url: `/pages/out/index?index=1&userid=${userInfo.id}&gameid=1&type=2`, | url: `/pages/out/index?index=1&userid=${userInfo.id}&gameid=1&type=2`, | ||||
| }) | }) | ||||
| @@ -76,7 +75,7 @@ Page({ | |||||
| } | } | ||||
| }, | }, | ||||
| shareFun(){ | shareFun(){ | ||||
| let token = wx.getStorageSync('token') | |||||
| let token = getApp().globalData.token | |||||
| wx.request({ | wx.request({ | ||||
| url: 'https://cktest.2weisou.com/meta/ar/user/share', | url: 'https://cktest.2weisou.com/meta/ar/user/share', | ||||
| method: "POST", | method: "POST", | ||||