getPhone.js
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// 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 (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
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": '13691224349',//必传,随便写一个
"sms_code": '1234',//必传,随便写一个
"wx_open_id": app.globalData.wx_open_id, //可选,如果传了,绑定到对应的微信号
"tenant_id": app.globalData.tenant_id,
"source": "wx_app::" + phone + ":" + iv,
"scope": "expert"
},
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;
wx.reLaunch({
url: '../tabbar/home/home'
})
} else {
wx.showToast({
title: '登录失败,请重新登录',
})
}
},
fail: function (res) {
console.log("fail ", res.data)
},
complete:function (res){
wx.reLaunch({
url: '../tabbar/home/home'
})
}
})
},
phoneLogin: function () {
wx.navigateTo({
url: '../login/login',
})
},
})