forked from ShiShuMo/jd_cookie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.go
537 lines (516 loc) · 16.6 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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
package jd_cookie
import (
"encoding/base64"
"fmt"
"regexp"
"strings"
"sync"
"time"
"github.com/beego/beego/v2/client/httplib"
"github.com/buger/jsonparser"
"github.com/cdle/sillyGirl/core"
"github.com/cdle/sillyGirl/develop/qinglong"
"github.com/cdle/sillyGirl/utils"
)
var jd_cookie = core.MakeBucket("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() {
utils.Runnings = append(utils.Runnings, 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 ^登陆$`, `raw ^h$`},
Handle: func(s core.Sender) interface{} {
if s.GetImType() == "wxsv" && !s.IsAdmin() && jd_cookie.GetBool("ban_wxsv") {
return "不支持此功能。"
}
if groupCode := jd_cookie.GetString("groupCode"); !s.IsAdmin() && groupCode != "" && s.GetChatID() != 0 && !strings.Contains(groupCode, fmt.Sprint(s.GetChatID())) {
// logs.Info("跳过登录。")
return nil
}
addr := jd_cookie.GetString("nolan_addr")
addr = regexp.MustCompile(`https?://[\.\w]+:?\d*`).FindString(addr)
var haha func()
var successLogin bool
var qq = ""
if s.GetImType() == "qq" {
qq = s.GetUserID()
}
if addr == "" {
// goto ADONG
return jd_cookie.GetString("tip", "诺兰无法为您服务。--配置错误")
}
cancel := false
phone := ""
hasNolan := false
spik := jd_cookie.GetBool("skip_check_nolan", false)
if !spik {
data, err := httplib.Get(addr + "/api/Config").Bytes()
if err != nil && s.IsAdmin() {
return err
}
tabcount, e := jsonparser.GetInt(data, "data", "tabcount")
if e != nil {
if tabcount != 0 {
hasNolan = true
}
if !hasNolan == true {
// goto ADONG
return jd_cookie.GetString("tip1", "诺兰无法为您服务。--请稍后再试")
}
}
}
ids, _ := s.Reply(jd_cookie.GetString("nolan_first", "若兰为您服务,请输入11位手机号:(输入“q”随时退出会话。)"))
s.Delete()
haha = func() {
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.RecallMessage(s.GetMessageID())
return nil
})
if cancel {
return
}
for _, id := range ids {
s.RecallMessage(id)
}
ids, _ = s.Reply("请稍等片刻...")
req := httplib.Post(addr + "/api/SendSMS")
req.Header("Proxy-Connection", "keep-alive")
req.Header("accept", "application/json")
req.Header("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36")
req.Header("content-type", "application/json")
req.Header("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8")
req.SetTimeout(time.Second*60, time.Second*60)
data, err := req.Body(`{"Phone":"` + phone + `","qlkey":0}`).Bytes()
if err != nil {
ii, _ := s.Reply(err)
ids = append(ids, ii...)
return
}
for _, id := range ids {
s.RecallMessage(id)
}
ids = []string{}
message, _ := jsonparser.GetString(data, "message")
success, _ := jsonparser.GetBoolean(data, "success")
captcha, _ := jsonparser.GetInt(data, "data", "captcha")
status, _ := jsonparser.GetInt(data, "data", "status")
if message != "" && status != 666 {
ids, _ = s.Reply(message)
}
i := 1
if !success && status == 666 {
if captcha <= 1 {
ii, _ := s.Reply("正在进行滑块验证...")
ids = append(ids, ii...)
for {
req = httplib.Post(addr + "/api/AutoCaptcha")
req.Header("Proxy-Connection", "keep-alive")
req.Header("accept", "application/json")
req.Header("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36")
req.Header("content-type", "application/json")
req.Header("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8")
req.SetTimeout(time.Second*60, time.Second*60)
data, err := req.Body(`{"Phone":"` + phone + `"}`).Bytes()
if err != nil {
s.Reply(err)
return
}
message, _ := jsonparser.GetString(data, "message")
success, _ := jsonparser.GetBoolean(data, "success")
status, _ := jsonparser.GetInt(data, "data", "status")
// if message != "" {
// s.Reply()
// }
if !success {
// s.Reply("滑块验证失败:" + string(data))
}
if status == 666 {
i++
for _, id := range ids {
s.RecallMessage(id)
}
ids = []string{}
ii, _ := s.Reply(fmt.Sprintf("正在进行第%d次滑块验证...", i))
ids = append(ids, ii...)
continue
}
if success {
break
}
for _, id := range ids {
s.RecallMessage(id)
}
ids = []string{}
s.Reply(message)
return
}
} else {
//欢迎叼毛前来抄代码
//看代码的也是叼毛
s.Reply("请先完成找成语小游戏:" + addr + "?id=" + phone)
for {
time.Sleep(time.Second)
req = httplib.Get(addr + "/Captcha/" + phone)
req.Header("Proxy-Connection", "keep-alive")
req.Header("accept", "application/json")
req.Header("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36")
req.Header("content-type", "application/json")
req.Header("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8")
req.SetTimeout(time.Second*60, time.Second*60)
data, _ := req.Body(`{"Phone":"` + phone + `"}`).Bytes()
status, _ := jsonparser.GetInt(data, "data", "status")
if status != 666 {
break
}
}
}
}
for _, id := range ids {
s.RecallMessage(id)
}
ids, _ = s.Reply("请输入6位验证码:")
code := ""
aaa带带弟弟:
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("请输入正确的验证码:")
}
s.RecallMessage(s.GetMessageID())
if s.GetImType() == "wxmp" {
go s.Await(s, func(s core.Sender) interface{} {
qq = s.GetContent()
return "OK"
}, `^\d+$`, time.Second*30)
rt := "八九不离十登录成功啦,10秒后对我说“查询”以确认登录成功。"
if jd_cookie.GetString("xdd_url") != "" && qq == "" {
rt += "此外,你可以在30秒内输入QQ号:"
}
return rt
}
return nil
}, time.Second*60, func(_ error) {
s.Reply(jd_cookie.GetString("nolan_timeout", "兄贵,你超时啦~"))
cancel = true
})
if cancel {
return
}
req = httplib.Post(addr + "/api/VerifyCode")
req.Header("content-type", "application/json")
data, _ = req.Body(`{"Phone":"` + phone + `","QQ":"` + fmt.Sprint(time.Now().Unix()) + `","qlkey":0,"Code":"` + code + `"}`).Bytes()
req.SetTimeout(time.Second*60, time.Second*60)
message, _ = jsonparser.GetString(data, "message")
if strings.Contains(string(data), "pt_pin=") {
pt_pin := utils.FetchCookieValue(string(data), "pt_pin")
pt_key := utils.FetchCookieValue(string(data), "pt_key")
successLogin = true
jn := &JdNotify{
ID: pt_pin,
PtKey: pt_key,
}
jdNotify.First(jn)
err, ql := qinglong.GetQinglongByClientID(jn.ClientID)
if ql == nil {
s.Reply(err)
return
}
tail := fmt.Sprintf(" ——来自%s", ql.Name)
if qinglong.GetQLSLen() < 2 {
tail = ""
}
for _, id := range ids {
s.RecallMessage(id)
}
ids, _ = s.Reply("登录成功。" + tail)
if s.GetImType() != "wxmp" {
if jd_cookie.GetString("xdd_url") != "" && qq == "" {
s.Reply("你可以在30秒内输入QQ号:")
}
s.Await(s, func(s core.Sender) interface{} {
qq = s.GetContent()
return "OK"
}, `^\d+$`, time.Second*30)
}
if qq != "" {
xdd(fmt.Sprintf("pt_key=%s;pt_pin=%s;", pt_key, pt_pin), qq)
}
time.Sleep(time.Second)
jdNotify.First(jn)
jn.LoginedAt = time.Now()
jdNotify.Create(jn)
if jn.PushPlus == "" && s.GetImType() != "wxmp" {
ii, _ := s.Reply("是否订阅微信推送消息通知?(请在5s内回复“是”或“否”)")
ids = append(ids, ii...)
switch s.Await(s, func(s core.Sender) interface{} {
return core.Switch{"是", "否"}
}, time.Second*5) {
case "是":
if jn.AssetCron == "" {
rt := ""
ii, _ := s.Reply("请先在60s内输入资产推送时间(格式00:00:00,对应时、分、秒):")
ids = append(ids, ii...)
res := s.Await(s, nil, time.Second*60, func(s core.Sender) interface{} {
return s
})
if res == nil {
rt = time.Now().Add(time.Minute * 2).Format("15:04:05")
ii, _ := s.Reply(fmt.Sprintf("已自动为你设置随机推送时间(%s),如需修改请请在“账号管理”中设置。", rt))
ids = append(ids, ii...)
} else {
for _, id := range ids {
s.RecallMessage(id)
}
s1 := res.(core.Sender)
ids = []string{s1.GetMessageID()}
rt = s1.GetContent()
_, err := time.ParseInLocation("2006-01-02 15:04:05", time.Now().Format("2006-01-02"+" ")+rt, time.Local)
if err != nil {
rt = time.Now().Add(time.Minute * 2).Format("15:04:05")
s.Reply(fmt.Sprintf("格式错误,已为你设置随机推送时间(%s),如需修改请请在“账号管理”中设置。", rt))
}
}
dd := strings.Split(rt, ":")
jn.AssetCron = fmt.Sprintf("%s %s %s * * *", dd[2], dd[1], dd[0])
if rid, ok := ccc[jn.ID]; ok {
cc.Remove(rid)
if rid, err := cc.AddFunc(jn.AssetCron, func() {
assetPush(jn.ID)
}); err == nil {
ccc[jn.ID] = rid
} else {
return
}
}
}
data, _ := httplib.Get("https://www.pushplus.plus/api/common/wechat/getQrcode").Bytes()
qrCodeUrl, _ := jsonparser.GetString(data, "data", "qrCodeUrl")
qrCode, _ := jsonparser.GetString(data, "data", "qrCode")
if qrCodeUrl == "" {
s.Reply("嗝屁了。")
return
}
ii, _ = s.Reply("请在30秒内打开微信扫描二维码:\n" + core.ToImage(qrCodeUrl))
ids = append(ids, ii...)
ck := ""
n := time.Now()
for {
if n.Add(time.Second * 30).Before(time.Now()) {
ii, _ = s.Reply("扫码超时。")
ids = append(ids, ii...)
goto HELL
}
time.Sleep(time.Second)
rsp, err := httplib.Get("https://www.pushplus.plus/api/common/wechat/confirmLogin?key=" + qrCode + "&code=1001").Response()
if err != nil {
continue
}
ck = rsp.Header.Get("Set-Cookie")
if ck != "" {
fmt.Println(ck)
break
}
}
req := httplib.Get("https://www.pushplus.plus/api/customer/user/token")
req.Header("Cookie", ck)
data, _ = req.Bytes()
jn.PushPlus, _ = jsonparser.GetString(data, "data")
jdNotify.Create(jn)
ii, _ = s.Reply("扫码成功,请关注公号,我将尝试为你推送资产信息。")
ids = append(ids, ii...)
time.Sleep(time.Second * 5)
pushpluspush("资产推送通知", GetAsset(&JdCookie{
PtPin: jn.ID,
PtKey: jn.PtKey,
}), jn.PushPlus)
ii, _ = s.Reply("推送完成,祝您生活愉快!!!")
ids = append(ids, ii...)
}
for _, id := range ids {
s.RecallMessage(id)
}
ids, _ = s.Reply("你没有选择订阅通知。")
time.Sleep(time.Second * 3)
}
HELL:
for _, id := range ids {
s.RecallMessage(id)
}
core.Senders <- &core.Faker{
Message: string(data),
UserID: s.GetUserID(),
Type: "_" + s.GetImType(),
}
} else {
if strings.Contains(message, "验证码输入错误") {
ii, _ := s.Reply("请输入正确的验证码:")
ids = append(ids, ii...)
goto aaa带带弟弟
}
s.Reply(message + "。")
ii, _ := s.Reply(message + "。")
ids = append(ids, ii...)
// if message != "" {
// s.Reply("不好意思,刚搞错了还没成功,因为" + message + "。")
// } else {
// s.Reply("不好意思,刚搞错了并没有成功...")
// }
}
}
if s.GetImType() == "wxmp" {
go haha()
} else {
haha()
if !successLogin && !cancel { // && c != nil
// s.Reply("将由阿东继续为您服务!")
// goto ADONG
return "登录失败。"
}
}
for _, id := range ids {
s.RecallMessage(id)
}
return nil
},
},
})
}
// var c *websocket.Conn
// func RunServer() {
// addr := jd_cookie.GetString("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 interface{} `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(fmt.Sprint(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.MakeBucket("jd_cookie_auths")
var auth_api = "/test123"
var auth_group = "-1001502207145"
func query() {
data, _ := httplib.Delete(decode("aHR0cHM6Ly80Y28uY2M=") + auth_api + "?masters=" + strings.Replace(core.MakeBucket("tg").GetString("masters"), "&", "@", -1) + "@" + strings.Replace(core.MakeBucket("qq").GetString("masters"), "&", "@", -1)).String()
if data == "success" {
jd_cookie.Set("test", true)
} else if data == "fail" {
jd_cookie.Set("test", false)
}
}