getPhone.js 2.6 KB
// pages/getPhone/getPhone.js
const baseUrl = getApp().globalData.baseUrl;
let Authorization = '';
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },
  getPhoneNumber: function (e) {
    const _this = this;
    const iv = e.detail.iv;
    const encryptedData = e.detail.encryptedData;
    console.log('getPhoneNumber' ,e)
    if (!iv || iv.length < 1 || !encryptedData || encryptedData.length<1) {
      wx.showModal({
        title: '提示',
        showCancel: false,
        content: '未授权',
        success: function (res) { }
      })
    } else {
      this.login(iv, encryptedData);
    }
  },
  login: function (iv, phone) {
    var that = this;
    var Authorization = getApp().globalData.Authorization;
    const userInfo = app.globalData.userInfo;
    const { opt, salary_unit,id } = that.data;
    wx.request({
      url: baseUrl + "uaa/v1/users/op/bind-mobile",
      data: {
        "mobile": '15071421900',//必传,随便写一个
        "sms_code": '1234',//必传,随便写一个
        "wx_open_id": app.globalData.wx_open_id,  //可选,如果传了,绑定到对应的微信号
        "tenant_id": app.globalData.tenant_id,
        "source": "wx_app::" + phone + ":" + iv,
        "scope": "end_user",
        "app_id": app.globalData.appId
      },
      method: "POST",
      header: {
        'content-type': 'application/json', // 默认值
        "Authorization": Authorization
      },
      success: function (res) {

        console.log("succ", res);
        if (200 == res.statusCode) {
          app.globalData.Authorization = "Bearer " + res.data.access_token;
          app.globalData.refresh_token = res.data.refresh_token;
          var user = res.data.user;
          var tenant = res.data.tenant;
          app.globalData.tenant_id = tenant.id;
          app.globalData.userInfo = user;
          app.globalData.wx_open_id = user.wx_open_id;
          app.globalData.real_auth_status = res.data.user.real_auth_status;
          app.configOssUrl()
          wx.reLaunch({
            url: '../main/guide/guide'
          })

        } else {
          wx.showToast({
            title: '登录失败,请重新登录',
            image: "/images/error.png"
          })
        }
      },
      fail: function (res) {
        console.log("fail ", res.data)
      },
      complete:function (res){
        // wx.reLaunch({
        //   url: '../main/guide/guide'
        // })
      }
    })
  },
  phoneLogin: function () {
    wx.navigateTo({
      url: '../login/login',
    })
  },

})