-
Notifications
You must be signed in to change notification settings - Fork 19
/
查快递_Bncr.js
207 lines (197 loc) · 5.05 KB
/
查快递_Bncr.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
/**作者
* @author 薛定谔的大灰机
* @name 查快递
* @origin 大灰机
* @version 1.0.4
* @description 查询快递
* @platform tgBot qq ssh HumanTG wxQianxun wxXyo
* @rule ^(快递|查快递)$
* @rule ^(快递|查快递)([^ \n]+)$
* @admin false
* @disable false
*/
/**
说明:
查询快递token注册地址(https://admin.alapi.cn/user/register)
*/
const mo = require('./mod/subassembly') // 此脚本依赖仓库模块,请拉取全部文件
const axios = require("axios")
const sysdb = new BncrDB('API')
const api_kd = `https://v2.alapi.cn/api/kd`
const fold = true // 折叠
module.exports = async s => {
token = (await sysdb.get('ALAPI'))?.Token || `` // 可以通过`set ALAPI Token *****`设置Token,或者在此行的||后面填入Token
let order = `desc` // 查询结果排序方式[desc, asc]
let data = {
order,
token,
}
if (!token) {
set(s, data)
} else {
main(s, data)
}
}
async function main(s, data) {
if (s.param(2)) {
data.number = s.param(2)
} else {
s.delMsg(s.getMsgId())
if (number = await mo.again(s, `快递单号`)) {
data.number = number
} else {
return
}
}
if (date = (await post(api_kd, data)).data) {
if (date.code == 200 && date.data && date.data.info.length > 0) {
let msgid = await s.reply(kd_msg(date.data, fold))
if ((msg = await mo.again(s, `输入Y展开`)) && (msg == `y` || msg == `Y`)) {
s.delMsg(msgid, { wait: 10 })
s.reply(kd_msg(date.data, false))
}
} else if (date.code == 422) {
if (com = getCodeByMsg(await mo.again(s, `快递公司(有字母则大写)`))) {
data.com = com
} else {
return
}
if (date = (await post(api_kd, data)).data) {
if (date.code == 200 && date.data && date.data.info.length > 0) {
let msgid = await s.reply(kd_msg(date.data, fold))
if ((msg = await mo.again(s, `Y展开`)) && (msg == `y` || msg == `Y`)) {
s.delMsg(msgid, { wait: 10 })
s.reply(kd_msg(date.data, false))
}
} else {
s.reply(date.msg)
}
}
}
}
}
async function set(s, data) {
set_json = {
"TIP": [
"输入ALAPI_Token",
],
"param": {
"Token": ""
}
}
for (let i = 0; i < set_json.TIP.length; i++) {
if (api_key = await mo.again(s, set_json.TIP[i])) {
set_json.param.Token = api_key
s.delMsg(await s.reply(await sysdb.set('ALAPI', set_json.param, { def: '设置成功' })), { wait: 2 })
data.token = api_key
main(s, data)
} else {
return
}
}
}
function kd_msg(data, num) {
if (num) {
num = 1
} else {
num = data.info.length
}
state = ["快递状态", "正常", "派送中", "已签收", "退回", "其他问题"]
msg = `快递状态:${data.status_desc}`
msg += `\n快递公司:${getCodeByMsg(data.com, true)}\n`
for (let i = 0; i < num; i++) {
msg += `\n${data.info[i].content}`
msg += `\n${data.info[i].time}\n`
// msg += `\n:${}`
}
return msg
}
function getCodeByMsg(msg, reverse) {
for (let i = 0; i < expressList.length; i++) {
const express = expressList[i];
if (express.name.includes(msg) || express.code.includes(msg)) {
if (reverse) {
return express.name;
} else {
return express.code;
}
}
}
return null;
}
// post请求
async function post(url, data) {
var data = await axios({
url: url,
method: "post",
data: data,
});
if (data.status === 200) {
return data
} else {
return
}
}
// 快递编号列表
const expressList = [
{
"name": "中通快递",
"code": "zto"
},
{
"name": "申通快递",
"code": "sto"
},
{
"name": "圆通速递",
"code": "yto"
},
{
"name": "天天快递",
"code": "tiantian"
},
{
"name": "EMS快递",
"code": "ems"
},
{
"name": "韵达快递",
"code": "yunda"
},
{
"name": "优速快递",
"code": "yousu"
},
{
"name": "百世快运",
"code": "800best"
},
{
"name": "百世汇通快递",
"code": "huitong"
},
{
"name": "宅急送快递",
"code": "zhaijisong"
},
{
"name": "龙邦快递",
"code": "longbang"
},
{
"name": "苏宁快递",
"code": "suning"
},
{
"name": "国通快递",
"code": "guotong"
},
{
"name": "邮政",
"code": "pingyou"
},
{
"name": "顺丰",
"code": "shunfeng"
}
]