const app = getApp() var http = require("../../utils/config.js"); Page({ data: { //测试. versions: false, token:'' }, onLoad: function (options) { var that = this; wx.removeStorageSync('token'); wx.login({ success: function (res) { var arr = []; wx.getSystemInfo({ success(res) { console.log(arr) arr = [{ label: '品牌', type: 'brand', value: res.brand }, { label: '型号', type: 'model', value: res.model }, { label: '系统平台', type: 'platform', value: res.platform }, { label: '系统版本', type: 'system', value: res.system }, { label: '微信版本', type: 'version', value: res.version }, { label: '小程序版本', type: 'SDKVersion', value: res.SDKVersion }, { label: '定位状态', type: 'locationEnabled', value: res.locationEnabled ? '开' : '关' }, { label: '定位授权', type: 'locationAuthorized', value: res.locationAuthorized ? '已授权' : '未授权' } ] } }) // 发送 res.code 到后台换取 openId, sessionKey, unionId wx.request({ url: http.url + '/auth/weapp-login', data: { 'code': res.code, 'appid': 'wx573623a9b7a7ed34', 'phone_detail': JSON.stringify(arr), 'invite_user_id':app.globalData.id }, header: { 'content-type': 'application/x-www-form-urlencoded', }, method: 'POST', success: function (res) { console.log(res) wx.setStorageSync('token', res.data.token); wx.setStorageSync('session_key', res.data.session_key); wx.setStorageSync('token_time', res.data.exp); wx.setStorageSync('user_ID', res.data.user.id); that.setData({token:res.data.token}) } }) } }) }, onGotUserInfo: function (e) { console.log(e) wx.showLoading({ title: '登陆中请稍等...', mask: true }) var that = this; if (e.detail.rawData) { var data = e.detail.userInfo wx.setStorageSync('userInfo', data) if (wx.getStorageSync('home').id != undefined) { data.area_id = wx.getStorageSync('home').id } console.log(data) wx.request({ url: http.url + '/auth/weapp-userinfo-sync', data: data, header: { 'content-type': 'application/x-www-form-urlencoded', 'Authorization':this.data.token }, method: 'POST', success: function (res) { if (res.statusCode == 200) { wx.showToast({ title: '授权成功', icon: 'none' }) wx.setStorageSync('userInfo', res.data) // wx.navigateBack() if(app.globalData.compatible){ console.log(app.globalData.compatible) wx.redirectTo({ url: '/pages/compatible/index/index', }) }else{ wx.redirectTo({ url: '/pages/index/index', }) } } else { wx.showToast({ title: '登陆失败请重试', icon: 'none' }) } } }) } else { wx.showToast({ title: '授权失败', icon: 'none' }) } }, agreement: function () { wx.navigateTo({ url: '/pages/personal/privacy/privacy', }) }, mobile_login(){ wx.navigateTo({ url: '/pages/mobile_login/mobile_login', }) }, //用户隐私协议 handleAgreePrivacyAuthorization(){}, onReady: function () { }, onShow: function () { wx.hideHomeButton() }, onHide: function () { }, onUnload: function () { }, onPullDownRefresh: function () { }, onReachBottom: function () { }, onShareAppMessage: function () { } })