forked from OpenListTeam/auth
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathwopan.go
More file actions
107 lines (102 loc) · 2.57 KB
/
wopan.go
File metadata and controls
107 lines (102 loc) · 2.57 KB
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
// Package auth wopan.go by xhofe
package auth
import (
"github.com/gin-gonic/gin"
"github.com/twoonefour/alist-auth/common"
"github.com/twoonefour/alist-auth/utils"
"github.com/xhofe/wopan-sdk-go"
"net/http"
)
type SmsReq struct {
Func string `json:"func"`
ClientId string `json:"clientId"`
Param string `json:"param"`
}
type SmsRes struct {
STATUS string `json:"STATUS"`
MSG string `json:"MSG"`
LOGID interface{} `json:"LOGID"`
RSP struct {
RSPCODE string `json:"RSP_CODE"`
RSPDESC string `json:"RSP_DESC"`
DATA interface{} `json:"DATA"`
} `json:"RSP"`
}
func wopanLogin(c *gin.Context) {
req := struct {
Phone string `json:"phone"`
Password string `json:"password"`
}{}
if err := c.ShouldBind(&req); err != nil {
common.Error(c, err)
return
}
w := wopan.Default()
res, err := w.PcWebLogin(req.Phone, req.Password)
if err != nil {
common.Error(c, err)
return
}
c.JSON(200, res)
}
func wopanVerifyCode(c *gin.Context) {
req := struct {
Phone string `json:"phone"`
Password string `json:"password"`
VerifyCode string `json:"verify_code"`
}{}
if err := c.ShouldBind(&req); err != nil {
common.Error(c, err)
return
}
if req.VerifyCode == "" && req.Password == "" && req.Phone != "" {
wopanSendSmsCode(c, req)
return
}
w := wopan.Default()
res, err := w.PcLoginVerifyCode(req.Phone, req.Password, req.VerifyCode)
if err != nil {
common.Error(c, err)
return
}
c.JSON(200, res)
}
func wopanSendSmsCode(c *gin.Context, req struct {
Phone string `json:"phone"`
Password string `json:"password"`
VerifyCode string `json:"verify_code"`
}) {
w := wopan.Default()
p, err := w.EncryptParam(wopan.ChannelAPIUser, wopan.Json{
"operateType": "1",
"phone": req.Phone,
"uuid": "",
"verifyCode": "",
})
if err != nil {
common.Error(c, err)
return
}
smsReq := SmsReq{
Func: "pc_send",
ClientId: wopan.DefaultClientID,
Param: p,
}
var smsRes SmsRes
client := utils.RestyClient.R().SetBody(&smsReq).SetResult(&smsRes).SetHeaders(map[string]string{
"Content-Type": "application/json",
"Origin": "https://pan.wo.cn",
"Referer": "https://pan.wo.cn/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
})
_, err = client.Execute("POST", "https://panservice.mail.wo.cn/api-user/sendMessageCodeBase")
if err != nil {
common.Error(c, err)
return
}
if smsRes.RSP.RSPCODE != "0000" {
common.ErrorStr(c, smsRes.RSP.RSPDESC)
return
}
c.Status(http.StatusNoContent)
}