-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
66 lines (58 loc) · 1.47 KB
/
app.js
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
//app.js
App({
onLaunch() {
this.getopenidByPromise().then(this.printOpenid);
},
globalData: {
openid:"000"
},
getopenidByPromise: function(){
let promise = new Promise((resolve,reject)=>{
let that = this
console.log("请求前")
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
//console.log(res.code)
wx.request({
url: 'https://www.pkula.xyz/getopenid',
method:'POST',
data: {
'code': res.code
},
header: {
'content-type': 'application/json' // 默认值
},
success (res) {
console.log(res.data)
console.log('111')
if(res.data.openid){
that.globalData.openid = res.data.openid
resolve("成功了");
}else
reject('失败了')
}
})
}
})
})
console.log("请求后")
return promise;
},
printOpenid: function (res) {
console.log("返回的信息为:"+res)
console.log(this.globalData.openid)
let that = this
wx.request({
url: 'https://www.pkula.xyz/getopenid2',
method:'POST',
data: {
openid: that.globalData.openid
},
success (res) {
console.log(res.data)
console.log('完成查询或插入')
}
})
},
})