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
//app.js
App({
url: 'https://www.koala-online.cn/compass/if/',
onLaunch: function () {
//调用wx用户登陆
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
this.checkUser(res.code, null);
}
})
var config = wx.getStorageSync('config');
var that = this;
//获取并保存用户的经纬度信息
wx.getLocation({
type: 'wgs84',
success: function (res) {
let location={
latitude: res.latitude,
longitude: res.longitude
};
wx.setStorage({
key: 'location',
data: location,
})
}
})
},
//判断用户是否已经注册
checkUser:function(code,openid){
wx.request({
url: this.url + 'ajax_check_user_registed.php',
data: {
openId: openid,
code: code
},
header: {
'content-type': 'application/json' // 默认值
},
success(res) {
//保存返回的openId和unionId
let config = {
openId: res.data.result.openId,
unionId: res.data.result.unionId,
registed: res.data.result.registed
};
wx.showToast({
title: "unionId=" + res.data.result.unionId,
icon: 'success',
duration: 2000
});
wx.setStorage({
key: 'config',
data: config,
});
},
fail: function (res) {
wx.showToast({
title: "失败",
icon: 'success',
duration: 2000
});
},
complete: function (res) {
},
})
},
globalData: {
userInfo: null
},
})