const app = getApp() var arr = []; Page({ data: { //测试. versions: false, token: '', img: app.globalData.imgUrl, title: app.globalData.title, logoUrl: '', bind_mobile: 0, session_key: '' }, onLoad: function (options) { var that = this; my.setNavigationBar({ title: app.globalData.title }) this.setData({ logoUrl: app.globalData.logoUrl }) my.removeStorageSync({key:'token'}); my.getAuthCode({ success: function (res) { my.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 console.log(app.globalData.appid, 'appid') var data = { 'code': res.authCode, 'appid': app.globalData.appid, 'type': 1 }; app.request("/auth/weapp-login", data, "POST").then(res => { console.log(res, '登录') my.setStorageSync({ 'key': 'token', data: res.data.token }); my.setStorageSync({ 'key': 'session_key', data: res.data.session_key }); my.setStorageSync({ 'key': 'token_time', data: res.data.exp }); my.setStorageSync({ 'key': 'user_ID', data: res.data.user.id }); that.setData({ token: res.data.token, session_key: res.data.session_key }) app.request("/user/status", '', "GET").then(res => { console.log(res) if (res.status == 200) { that.setData({ bind_mobile: res.data.is_bind_mobile }) } }) }) } }) }, skipXieyi:function(){ my.navigateTo({ url: '/pages/agreement/agreement', }) }, onGotUserInfo: function (e) { console.log(e) if (e.detail.errMsg == "getUserInfo:fail auth deny") { my.showToast({ content: '授权失败请重试', icon: 'none' }) } else { my.showLoading({ content: '登陆中请稍等...', mask: true }) if (e.detail.rawData) { var data = e.detail.userInfo my.setStorageSync({ 'key': 'userInfo', data: data }) if (my.getStorageSync({ 'key': 'home' }).data.id != undefined) { data.area_id = my.getStorageSync({ 'key': 'home' }).data.id } console.log(data) app.request("/auth/weapp-userinfo-sync", data, "POST").then(res => { if (res.status == 200) { my.showToast({ content: '授权成功', icon: 'none' }) my.setStorageSync({ 'key': 'userInfo', data: res.data }) // my.navigateBack() if (app.globalData.compatible) { console.log(app.globalData.compatible) my.redirectTo({ url: '/pages/compatible/index/index', }) } else { my.redirectTo({ url: '/pages/index/index', }) } } else { my.showToast({ content: '登陆失败请重试', icon: 'none' }) my.redirectTo({ url: '/pages/index/index', }) } }) } else { my.showToast({ content: '授权失败', icon: 'none' }) } } }, onAuthError: function () { my.showToast({ content: '授权失败请重试', type: 'none' }); }, getUserPhoneNumber: function (e) { console.log(e) my.getPhoneNumber({ success: (res) => { console.log(res, "KKKKKKKKKKK") let encryptedData = JSON.parse(res.response).response; //userObject.phoneInfo = res.response; console.log(encryptedData); //手机号解密请求 // phoneAuth(res.response); // my.alert({ // title: encryptedData, // });4nbLCy+uBSvO8waRPGv3/EsHNqpa68oN8bPAyJqGjCT6UAVIaMuwChCdRsJkrsKRT3lGHdqyaET7YL2IptOLp7pZYW6w4wl9BHDLmx6V9kRindBZMBTYKzp7ov99o/E6rG3fZZCXSNA59aiKMojMA+JIzMRuo3GRBOcq0YEml6I= if (encryptedData.length == 172) return; let data = { phone_detail: JSON.stringify(arr), type: '3', session_key: encryptedData, auth_id: this.data.auth_id } app.request('/auth/mobileLogin', data, 'POST', app.globalData.req).then(res => { console.log(res, "PPPPppp") my.setStorageSync({ key: 'userInfo', data: res.data.user }) my.setStorageSync({ key: 'token', data: res.data.token }); console.log(my.getStorageSync({ key: 'token' })) // my.setStorageSync('token', res.data.token) // my.setStorageSync('token_time', res.data.exp) // my.setStorageSync('userInfo', res.data.user) my.reLaunch({ url: '/pages/index/index', }) }) }, fail: (res) => { console.log(res, "error"); } }) }, //手机号登陆 phoneLogin: function () { my.navigateTo({ url: '/pages/phonelogin/phonelogin', }) }, //暂不登录 noSign: function () { my.reLaunch({ url: '/pages/index/index', }) }, onReady: function () { }, onShow: function () { my.hideBackHome() }, onHide: function () { }, onUnload: function () { }, onPullDownRefresh: function () { }, onReachBottom: function () { }, onShareAppMessage: function () { } })