Skip to content

Commit

Permalink
refactor: 登录流程优化
Browse files Browse the repository at this point in the history
  • Loading branch information
Redmomn committed Nov 12, 2024
1 parent 45d66e3 commit 63ccad5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
1 change: 0 additions & 1 deletion client/auth/sig.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ type SigInfo struct {
TempPwd []byte
CaptchaInfo [3]string

CaptchaURL string
NewDeviceVerifyURL string

Nickname string
Expand Down
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (c *QQClient) PasswordLogin() (*LoginResponse, error) {
return &res, err
}

func (c *QQClient) CommitCaptcha(ticket, randStr, aid string) (*LoginResponse, error) {
func (c *QQClient) SubmitCaptcha(ticket, randStr, aid string) (*LoginResponse, error) {
c.Sig().CaptchaInfo = [3]string{ticket, randStr, aid}
data, err := buildPasswordLoginRequest(c.Uin, c.version(), c.Device(), &c.transport.Sig, c.PasswordMD5)
if err != nil {
Expand Down
12 changes: 5 additions & 7 deletions client/ntlogin.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,6 @@ func parseNtloginResponse(response []byte, sig *auth.SigInfo) (LoginResponse, er
return nil
}()
sig.Cookies = base.Header.Cookie.Cookie.Unwrap()
sig.CaptchaURL = func() string {
if body.Captcha != nil {
return body.Captcha.Url
}
return ""
}()
sig.NewDeviceVerifyURL = base.Header.Error.NewDeviceVerifyUrl.Unwrap()
err = nil
}
Expand All @@ -166,19 +160,23 @@ func parseNtloginResponse(response []byte, sig *auth.SigInfo) (LoginResponse, er
err = fmt.Errorf("login fail on ntlogin(%s): [%s]>%s", ret.Name(), title, content)
}
var loginErr LoginError
var verifyURL string
//nolint:exhaustive
switch ret {
case loginstate.CaptchaVerify:
loginErr = NeedCaptcha
loginErr = SliderNeededError
verifyURL = body.Captcha.Url
case loginstate.NewDeviceVerify:
loginErr = UnsafeDeviceError
verifyURL = base.Header.Error.NewDeviceVerifyUrl.Unwrap()
default:
loginErr = OtherLoginError
}
return LoginResponse{
Success: false,
Error: loginErr,
ErrorMessage: ret.Name(),
VerifyURL: verifyURL,
}, err
}

Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ func main() {
return nil
}
switch ret.Error {
case client.NeedCaptcha:
case client.SliderNeededError:
logger.Warnln("captcha verification required")
logger.Warnln(c.Sig().CaptchaURL)
aid := strings.Split(strings.Split(c.Sig().CaptchaURL, "&sid=")[1], "&")[0]
logger.Warnln(ret.VerifyURL)
aid := strings.Split(strings.Split(ret.VerifyURL, "sid=")[1], "&")[0]
logger.Warnln("ticket?->")
ticket := utils.ReadLine()
logger.Warnln("rand_str?->")
randStr := utils.ReadLine()
ret, err = c.CommitCaptcha(ticket, randStr, aid)
ret, err = c.SubmitCaptcha(ticket, randStr, aid)
continue
case client.UnsafeDeviceError:
vf, err := c.GetNewDeviceVerifyURL()
Expand Down

0 comments on commit 63ccad5

Please sign in to comment.