// index.js // 获取应用实例 const app = getApp() Page({ data: { ischecked: true, token: '' }, onLoad() { }, backGame(){ wx.navigateTo({ url: '' }) }, checkFun(){ this.setData({ ischecked: !this.data.ischecked }) }, // 绑定用户头像信息 bindNickname(obj) { let that = this let params = { headPortrait: obj.avatarUrl, nickName: obj.nickName, sex: obj.gender, //1男 2女 region: (obj.province&&obj.city)?(obj.province + ' ' + obj.city): '' } wx.request({ url: 'http://49.232.159.78:9999/coupon/c/person/bindNickname', method: "POST", data: params, header: { Authorization: 'bearer '+ that.data.token }, success(res) { if (res.statusCode == 200) { console.log('绑定用户头像信息成功') } } }) }, getUserInfo(){ if(!this.data.ischecked){ wx.showToast({ title: '请勾选协议', icon: 'none', duration: 2000 }) return; } let that = this wx.getUserProfile({ desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: (res) => { console.log(res) wx.login({ success (res1) { if (res1.code) { //发起网络请求 wx.request({ url: 'http://49.232.159.78:9999/auth/mobile/token/social?grant_type=mobil&mobile=MINI_C@' + res1.code, method: "POST", data: { }, header: { Authorization: "Basic YXBwbGV0OmFwcGxldA==", }, success(res2) { console.log(33) if (res2.statusCode == 200) { console.log(res2) that.setData({ token: res2.data.access_token }) that.bindNickname(res.userInfo) } } }) } else { console.log('登录失败!' + res.errMsg) } } }) } }) }, // 授权手机号 getPhoneNumber(e) { console.log(e); let that = this if (e.detail.errMsg == "getPhoneNumber:ok") { const { iv, encryptedData } = e.detail; wx.request({ url: 'http://49.232.159.78:9999/coupon/c/person/bindMini', method: "POST", data: { encrypted: encryptedData, iv }, header: { Authorization: 'bearer '+ that.data.token }, success(res) { console.log(res) if (res.statusCode == 200) { // console.log(res) } } }) // that.$u.api.bindMini({ // encrypted: encryptedData, // iv // }).then((res) => { // 绑定手机号 // console.log(res); // let userinfo = that.vuex_userInfo // userinfo.phone = res.data // that.$u.vuex("vuex_userInfo", userinfo); // uni.setStorageSync('userInfo', userinfo) // that.islogin = true // }) } else { uni.showToast({ icon: "none", title: "请授权手机号" }) } } })