-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapp.js
234 lines (213 loc) · 5.02 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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
//app.js
//author:丢失的橘子
//github:https://github.com/TangerineSpecter/CatToolBox
var config = require('utils/config.js');
var Base64 = require('utils/base64.modified.js');
var MD5 = require('/utils/md5.js')
App({
onLaunch: function () {
// 展示本地存储能力
var logs = wx.getStorageSync('logs') || []
//logs.unshift(Date.now())
//wx.setStorageSync('logs', logs)
console.log('工具箱启动');
// 登录
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
}
})
// 获取用户信息
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({
success: res => {
// 可以将 res 发送给后台解码出 unionId
this.globalData.userInfo = res.userInfo
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (this.userInfoReadyCallback) {
this.userInfoReadyCallback(res)
}
}
})
}
}
})
},
globalData: {
userInfo: null
},
//物流查询
getExpressInfo: function (nu, type, cb) {
var apikey = config.logistics_key;
var jsonData = {
'LogisticCode': nu,
'ShipperCode': type
}
var sign = JSON.stringify(jsonData) + apikey;
var DataSign = Base64.encode(MD5.hexMD5(sign));
var RequestData = escape(JSON.stringify(jsonData));
wx.request({
url: config.logistics_address,
data: {
'EBusinessID': config.EBusinessID,
'RequestData': RequestData,
'RequestType': '1002',
'DataSign': DataSign,
'DataType': '2'
},
header: {
},
success: function (res) {
cb(res.data)
}
})
},
//星座查询
getConstInfo: function (star, cb) {
wx.request({
url: config.const_url,
data: {
'showapi_appid': config.showapi_appid,
'showapi_sign': config.showapi_sign,
'star': star
},
header: {
},
success: function (res) {
//console.log(res);
cb(res.data)
}
})
},
//笑话查询
getJokeInfo: function (page, cb) {
var pageSize = 1;
wx.request({
url: config.joke_url,
data: {
'showapi_appid': config.showapi_appid,
'showapi_sign': config.showapi_sign,
'page': page,
'maxResult': pageSize
},
header: {
},
success: function (res) {
console.log(res);
cb(res.data)
}
})
},
//图灵机器人
getRebotInfo: function (info, cb) {
wx.request({
url: config.rebot_url,
data: {
'showapi_appid': config.showapi_appid,
'showapi_sign': config.showapi_sign,
'info': info,
'userid': 'userid'
},
header: {
},
success: function (res) {
//console.log(res);
cb(res.data)
}
})
},
//历史上的今天
getHistoryInfo: function (cb) {
wx.request({
url: config.history_url,
data: {
'showapi_appid': config.showapi_appid,
'showapi_sign': config.showapi_sign
},
header: {
},
success: function (res) {
//console.log(res);
cb(res.data)
}
})
},
//空气质量
getAirQualityInfo: function (cb) {
wx.request({
url: config.airquality_url,
data: {
'showapi_appid': config.showapi_appid,
'showapi_sign': config.showapi_sign,
'city': '深圳'
},
header: {
},
success: function (res) {
//console.log(res);
cb(res.data)
}
})
},
//黄历运势
getAlmanacInfo: function (date, cb) {
wx.request({
url: config.almanac_url,
data: {
'date': date,
'showapi_appid': config.showapi_appid,
'showapi_sign': config.showapi_sign
},
header: {
},
success: function (res) {
//console.log(res);
cb(res.data)
}
})
},
//每日壁纸
getWallpaperInfo: function (page, cb) {
wx.request({
url: config.wallpaper_url,
data: {
'format': 'js',
'idx': page,
'n': 8
},
header: {
},
success: function (res) {
//console.log(res);
cb(res.data)
}
})
},
//百度翻译
getTranslateInfo: function (text, to, cb) {
var salt = new Date().getTime();
var sign = MD5.hexMD5(config.baidu_appid + text + salt + config.baidu_key);
//console.log(sign)
wx.request({
url: config.translate_url,
data: {
'q': text,
'from': 'auto',
'to': to,
'appid': config.baidu_appid,
'salt': salt,
'sign': sign
},
header: {
},
success: function (res) {
//console.log(res);
cb(res.data)
}
})
}
})