123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- 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 () {
-
- }
- })
|