Skip to content

Commit

Permalink
fix: updated the login api error
Browse files Browse the repository at this point in the history
  • Loading branch information
52funny authored and 52funny committed Aug 16, 2024
1 parent fc174e7 commit 23a5d8a
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion internal/pikpak/pikpak.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,23 @@ func NewPikPak(account, password string) PikPak {
}

func (p *PikPak) Login() error {
captchaToken, err := p.getCaptchaToken()
if err != nil {
return err
}
m := make(map[string]string)
m["client_id"] = clientID
m["client_secret"] = clientSecret
m["grant_type"] = "password"
m["username"] = p.Account
m["password"] = p.Password
m["captcha_token"] = captchaToken
bs, err := jsoniter.Marshal(&m)
if err != nil {
return err
}
req, err := http.NewRequest("POST", "https://user.mypikpak.com/v1/auth/token", bytes.NewBuffer(bs))

req, err := http.NewRequest("POST", "https://user.mypikpak.com/v1/auth/signin", bytes.NewBuffer(bs))
if err != nil {
return err
}
Expand All @@ -92,6 +98,34 @@ func (p *PikPak) Login() error {
return nil
}

func (p *PikPak) getCaptchaToken() (string, error) {
m := make(map[string]any)
m["client_id"] = clientID
m["device_id"] = p.DeviceId
m["action"] = "POST:https://user.mypikpak.com/v1/auth/signin"
m["meta"] = map[string]string{
"username": p.Account,
}
body, err := jsoniter.Marshal(&m)
if err != nil {
return "", err
}
req, err := http.NewRequest("POST", "https://user.mypikpak.com/v1/shield/captcha/init", bytes.NewBuffer(body))
if err != nil {
return "", err
}
req.Header.Add("Content-Type", "application/json")
bs, err := p.sendRequest(req)
if err != nil {
return "", err
}
error_code := jsoniter.Get(bs, "error_code").ToInt()
if error_code != 0 {
return "", fmt.Errorf("get captcha error: %v", jsoniter.Get(bs, "error").ToString())
}
return jsoniter.Get(bs, "captcha_token").ToString(), nil
}

func (p *PikPak) sendRequest(req *http.Request) ([]byte, error) {
p.setHeader(req)
resp, err := p.client.Do(req)
Expand Down

0 comments on commit 23a5d8a

Please sign in to comment.