forked from colakang/nyis_ask_wechat_plugin_frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
executable file
·50 lines (43 loc) · 1.26 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
//app.js
var utils = require('/utils/util.js')
var loginUrl = 'http://ask.nyis.com/api/v1/wx';
var questionUrl = 'http:/ask.nyis.com/api/v1/q2a/questions';
var debugUrl = '?XDEBUG_SESSION_START=16415';
/**
* 全局信息,运行时加载
* 发送code
* 获取token,qauserid并储存
*/
App({
onLaunch: function () {
wx.login({
success: function (res) {
var code = res.code;
var token = wx.getStorageSync('token');
console.log('code');
console.log(code);
wx.request({
url: loginUrl + '/tokens',
data: {
code: code,
token:token
},
method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
success: function (res) {
console.log(res.data);
//console.log(res.data["0"].token);
wx.setStorageSync('token', res.data["0"].token);
wx.setStorageSync('qauserid', res.data["0"].qauserid);
console.log('token');
console.log(wx.getStorageSync('token'));
console.log('qauserid');
console.log(wx.getStorageSync('qauserid'));
},
fail: function (res) {
console.log(res.data);
}
})
}
})
}
})