Skip to content

Commit e47f693

Browse files
committed
Adapting updated verify system
1 parent fa15d19 commit e47f693

2 files changed

Lines changed: 46 additions & 31 deletions

File tree

desktop/login.go

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,65 @@ import (
77
"net/url"
88
"strings"
99
"time"
10-
11-
"golang.org/x/text/encoding/simplifiedchinese"
1210
)
1311

1412
func loginCampus(config *Config) error {
15-
// 初始化客户端
1613
client := &http.Client{
17-
Timeout: time.Duration(10) * time.Second,
14+
Timeout: 10 * time.Second,
1815
}
19-
// 构造 POST 请求
16+
17+
urlStr := "http://10.0.0.252/cgi-bin/ace_web_auth.cgi"
18+
2019
formData := url.Values{
21-
"DDDDD": {config.Username},
22-
"upass": {config.Password},
23-
"0MKKey": {"登 录"},
20+
"web_jumpto": {""},
21+
"orig_referer": {"http://www.qq.com/"},
22+
"username": {config.Username},
23+
"userpwd": {config.Password},
24+
"login_page": {""},
25+
"temp_account": {"0"},
26+
"path": {"-6"},
27+
"u_type": {"1"},
2428
}
25-
// 执行网络请求
26-
response, err := client.PostForm("http://10.0.0.253/0.htm", formData)
29+
30+
response, err := client.PostForm(urlStr, formData)
2731
if err != nil {
2832
return fmt.Errorf("网络请求失败")
2933
}
30-
// 自动关闭请求体
31-
defer func(Body io.ReadCloser) {
32-
_ = Body.Close()
33-
}(response.Body)
34-
// 读取请求
34+
defer response.Body.Close()
35+
3536
bodyBytes, err := io.ReadAll(response.Body)
3637
if err != nil {
3738
return fmt.Errorf("读取响应失败")
3839
}
39-
// 转换编码
40-
utf8body, err := simplifiedchinese.GBK.NewDecoder().Bytes(bodyBytes)
41-
if err != nil {
42-
return fmt.Errorf("编码转换失败")
43-
}
44-
// 转换成 UTF-8 编码
45-
html := string(utf8body)
46-
// 返回请求状态
47-
if strings.Contains(html, "您已经成功登录") {
40+
41+
html := string(bodyBytes)
42+
redirect := extractRedirect(html)
43+
44+
if strings.Contains(redirect, "login_online_detail") {
4845
return nil
49-
} else if strings.Contains(html, "userid error1") {
50-
return fmt.Errorf("账号错误")
51-
} else if strings.Contains(html, "userid error2") {
52-
return fmt.Errorf("密码错误")
46+
} else if strings.Contains(redirect, "reason=27") {
47+
return fmt.Errorf("账号或密码错误")
5348
}
54-
// 无法处理
49+
5550
return fmt.Errorf("其他错误")
5651
}
52+
53+
func extractRedirect(html string) string {
54+
start := strings.Index(html, "location")
55+
if start == -1 {
56+
return ""
57+
}
58+
59+
firstQuote := strings.IndexAny(html[start:], `"'`)
60+
if firstQuote == -1 {
61+
return ""
62+
}
63+
firstQuote += start
64+
65+
secondQuote := strings.IndexAny(html[firstQuote+1:], `"'`)
66+
if secondQuote == -1 {
67+
return ""
68+
}
69+
secondQuote += firstQuote + 1
70+
return html[firstQuote+1 : secondQuote]
71+
}

desktop/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func workflow(application fyne.App) {
123123
if config, err := loadConfig("config.json"); err == nil {
124124
if err := loginCampus(config); err == nil {
125125
os.Exit(0)
126-
} else if err.Error() == "账号错误" || err.Error() == "密码错误" {
126+
} else if err.Error() == "账号或密码错误" {
127127
showDialogWindow(application, err.Error(), func() {
128128
if err := deleteConfig("config.json"); err != nil {
129129
showDialogWindow(application, "无法删除错误配置文件", func() {
@@ -157,4 +157,4 @@ func main() {
157157
application := app.NewWithID("com.simplenty.drcom")
158158
workflow(application)
159159
application.Run()
160-
}
160+
}

0 commit comments

Comments
 (0)