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
|
//index.js
//获取应用实例
const app = getApp()
Page({
data: {
city: '' ,
country: '' ,
nickName: '' ,
province: ''
},
//发起http请求
login: function (){
wx.login({
success: function (res){
console.log(res.code)
//发送请求
wx.request({
url: '自己的域名' , //仅为示例,并非真实的接口地址
data: {
code:res.code
},
header: {
'content-type' : 'application/json' // 默认值
},
success(res) {
console.log(res)
}
})
}
})
},
//验证登录是否过期
checksession: function (){
wx.checkSession({
success: function (res){
console.log(res, '登录未过期' )
wx.showToast({
title: '登录未过期啊' ,
})
},
fail: function (res){
console.log(res, '登录过期了' )
wx.showModal({
title: '提示' ,
content: '你的登录信息过期了,请重新登录' ,
})
//再次调用wx.login()
wx.login({
success: function (res) {
console.log(res.code)
//发送请求
wx.request({
url: '自己的域名' , //仅为示例,并非真实的接口地址
data: {
code: res.code
},
header: {
'content-type' : 'application/json' // 默认值
},
success(res) {
console.log(res)
}
})
}
})
}
})
},
//获取用户的信息
info: function (){
var that= this
wx.getUserInfo({
success: function (res){
console.log(res.userInfo)
var city = res.userInfo.city
var country = res.userInfo.country
var nickName = res.userInfo.nickName
var province = res.userInfo.province
that.setData({
city:city,
country:country,
nickName:nickName,
province:province
})
}
})
}
})
|
请发表评论