Skip to content

Commit d0ee90c

Browse files
authored
fix(thunder): fix login issue (#8342 close #8288)
1 parent 544a7ea commit d0ee90c

File tree

4 files changed

+304
-34
lines changed

4 files changed

+304
-34
lines changed

drivers/thunder/driver.go

Lines changed: 110 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,29 @@ func (x *Thunder) Init(ctx context.Context) (err error) {
4545
Common: &Common{
4646
client: base.NewRestyClient(),
4747
Algorithms: []string{
48-
"HPxr4BVygTQVtQkIMwQH33ywbgYG5l4JoR",
49-
"GzhNkZ8pOBsCY+7",
50-
"v+l0ImTpG7c7/",
51-
"e5ztohgVXNP",
52-
"t",
53-
"EbXUWyVVqQbQX39Mbjn2geok3/0WEkAVxeqhtx857++kjJiRheP8l77gO",
54-
"o7dvYgbRMOpHXxCs",
55-
"6MW8TD8DphmakaxCqVrfv7NReRRN7ck3KLnXBculD58MvxjFRqT+",
56-
"kmo0HxCKVfmxoZswLB4bVA/dwqbVAYghSb",
57-
"j",
58-
"4scKJNdd7F27Hv7tbt",
48+
"9uJNVj/wLmdwKrJaVj/omlQ",
49+
"Oz64Lp0GigmChHMf/6TNfxx7O9PyopcczMsnf",
50+
"Eb+L7Ce+Ej48u",
51+
"jKY0",
52+
"ASr0zCl6v8W4aidjPK5KHd1Lq3t+vBFf41dqv5+fnOd",
53+
"wQlozdg6r1qxh0eRmt3QgNXOvSZO6q/GXK",
54+
"gmirk+ciAvIgA/cxUUCema47jr/YToixTT+Q6O",
55+
"5IiCoM9B1/788ntB",
56+
"P07JH0h6qoM6TSUAK2aL9T5s2QBVeY9JWvalf",
57+
"+oK0AN",
5958
},
60-
DeviceID: utils.GetMD5EncodeStr(x.Username + x.Password),
59+
DeviceID: func() string {
60+
if len(x.DeviceID) != 32 {
61+
return utils.GetMD5EncodeStr(x.DeviceID)
62+
}
63+
return x.DeviceID
64+
}(),
6165
ClientID: "Xp6vsxz_7IYVw2BB",
6266
ClientSecret: "Xp6vsy4tN9toTVdMSpomVdXpRmES",
63-
ClientVersion: "7.51.0.8196",
67+
ClientVersion: "8.31.0.9726",
6468
PackageName: "com.xunlei.downloadprovider",
65-
UserAgent: "ANDROID-com.xunlei.downloadprovider/7.51.0.8196 netWorkType/5G appid/40 deviceName/Xiaomi_M2004j7ac deviceModel/M2004J7AC OSVersion/12 protocolVersion/301 platformVersion/10 sdkVersion/220200 Oauth2Client/0.9 (Linux 4_14_186-perf-gddfs8vbb238b) (JAVA 0)",
69+
UserAgent: "ANDROID-com.xunlei.downloadprovider/8.31.0.9726 netWorkType/5G appid/40 deviceName/Xiaomi_M2004j7ac deviceModel/M2004J7AC OSVersion/12 protocolVersion/301 platformVersion/10 sdkVersion/512000 Oauth2Client/0.9 (Linux 4_14_186-perf-gddfs8vbb238b) (JAVA 0)",
6670
DownloadUserAgent: "Dalvik/2.1.0 (Linux; U; Android 12; M2004J7AC Build/SP1A.210812.016)",
67-
6871
refreshCTokenCk: func(token string) {
6972
x.CaptchaToken = token
7073
op.MustSaveDriverStorage(x)
@@ -80,6 +83,8 @@ func (x *Thunder) Init(ctx context.Context) (err error) {
8083
x.GetStorage().SetStatus(fmt.Sprintf("%+v", err.Error()))
8184
op.MustSaveDriverStorage(x)
8285
}
86+
// 清空 信任密钥
87+
x.Addition.CreditKey = ""
8388
}
8489
x.SetTokenResp(token)
8590
return err
@@ -93,6 +98,17 @@ func (x *Thunder) Init(ctx context.Context) (err error) {
9398
x.SetCaptchaToken(ctoekn)
9499
}
95100

101+
if x.Addition.CreditKey != "" {
102+
x.SetCreditKey(x.Addition.CreditKey)
103+
}
104+
105+
if x.Addition.DeviceID != "" {
106+
x.Common.DeviceID = x.Addition.DeviceID
107+
} else {
108+
x.Addition.DeviceID = x.Common.DeviceID
109+
op.MustSaveDriverStorage(x)
110+
}
111+
96112
// 防止重复登录
97113
identity := x.GetIdentity()
98114
if x.identity != identity || !x.IsLogin() {
@@ -102,6 +118,8 @@ func (x *Thunder) Init(ctx context.Context) (err error) {
102118
if err != nil {
103119
return err
104120
}
121+
// 清空 信任密钥
122+
x.Addition.CreditKey = ""
105123
x.SetTokenResp(token)
106124
}
107125
return nil
@@ -161,6 +179,17 @@ func (x *ThunderExpert) Init(ctx context.Context) (err error) {
161179
x.SetCaptchaToken(x.CaptchaToken)
162180
}
163181

182+
if x.ExpertAddition.CreditKey != "" {
183+
x.SetCreditKey(x.ExpertAddition.CreditKey)
184+
}
185+
186+
if x.ExpertAddition.DeviceID != "" {
187+
x.Common.DeviceID = x.ExpertAddition.DeviceID
188+
} else {
189+
x.ExpertAddition.DeviceID = x.Common.DeviceID
190+
op.MustSaveDriverStorage(x)
191+
}
192+
164193
// 签名方法
165194
if x.SignType == "captcha_sign" {
166195
x.Common.Timestamp = x.Timestamp
@@ -194,6 +223,8 @@ func (x *ThunderExpert) Init(ctx context.Context) (err error) {
194223
if err != nil {
195224
return err
196225
}
226+
// 清空 信任密钥
227+
x.ExpertAddition.CreditKey = ""
197228
x.SetTokenResp(token)
198229
x.SetRefreshTokenFunc(func() error {
199230
token, err := x.XunLeiCommon.RefreshToken(x.TokenResp.RefreshToken)
@@ -202,6 +233,8 @@ func (x *ThunderExpert) Init(ctx context.Context) (err error) {
202233
if err != nil {
203234
x.GetStorage().SetStatus(fmt.Sprintf("%+v", err.Error()))
204235
}
236+
// 清空 信任密钥
237+
x.ExpertAddition.CreditKey = ""
205238
}
206239
x.SetTokenResp(token)
207240
op.MustSaveDriverStorage(x)
@@ -233,7 +266,8 @@ func (x *ThunderExpert) SetTokenResp(token *TokenResp) {
233266

234267
type XunLeiCommon struct {
235268
*Common
236-
*TokenResp // 登录信息
269+
*TokenResp // 登录信息
270+
*CoreLoginResp // core登录信息
237271

238272
refreshTokenFunc func() error
239273
}
@@ -433,6 +467,10 @@ func (xc *XunLeiCommon) SetTokenResp(tr *TokenResp) {
433467
xc.TokenResp = tr
434468
}
435469

470+
func (xc *XunLeiCommon) SetCoreTokenResp(tr *CoreLoginResp) {
471+
xc.CoreLoginResp = tr
472+
}
473+
436474
// 携带Authorization和CaptchaToken的请求
437475
func (xc *XunLeiCommon) Request(url string, method string, callback base.ReqCallback, resp interface{}) ([]byte, error) {
438476
data, err := xc.Common.Request(url, method, func(req *resty.Request) {
@@ -461,7 +499,7 @@ func (xc *XunLeiCommon) Request(url string, method string, callback base.ReqCall
461499
}
462500
return nil, err
463501
case 9: // 验证码token过期
464-
if err = xc.RefreshCaptchaTokenAtLogin(GetAction(method, url), xc.UserID); err != nil {
502+
if err = xc.RefreshCaptchaTokenAtLogin(GetAction(method, url), xc.TokenResp.UserID); err != nil {
465503
return nil, err
466504
}
467505
default:
@@ -493,20 +531,25 @@ func (xc *XunLeiCommon) RefreshToken(refreshToken string) (*TokenResp, error) {
493531

494532
// 登录
495533
func (xc *XunLeiCommon) Login(username, password string) (*TokenResp, error) {
496-
url := XLUSER_API_URL + "/auth/signin"
497-
err := xc.RefreshCaptchaTokenInLogin(GetAction(http.MethodPost, url), username)
534+
//v3 login拿到 sessionID
535+
sessionID, err := xc.CoreLogin(username, password)
498536
if err != nil {
499537
return nil, err
500538
}
539+
//v1 login拿到令牌
540+
url := XLUSER_API_URL + "/auth/signin/token"
541+
if err = xc.RefreshCaptchaTokenInLogin(GetAction(http.MethodPost, url), username); err != nil {
542+
return nil, err
543+
}
501544

502545
var resp TokenResp
503546
_, err = xc.Common.Request(url, http.MethodPost, func(req *resty.Request) {
547+
req.SetPathParam("client_id", xc.ClientID)
504548
req.SetBody(&SignInRequest{
505-
CaptchaToken: xc.GetCaptchaToken(),
506549
ClientID: xc.ClientID,
507550
ClientSecret: xc.ClientSecret,
508-
Username: username,
509-
Password: password,
551+
Provider: SignProvider,
552+
SigninToken: sessionID,
510553
})
511554
}, &resp)
512555
if err != nil {
@@ -582,3 +625,48 @@ func (xc *XunLeiCommon) DeleteOfflineTasks(ctx context.Context, taskIDs []string
582625
}
583626
return nil
584627
}
628+
629+
func (xc *XunLeiCommon) CoreLogin(username string, password string) (sessionID string, err error) {
630+
url := XLUSER_API_BASE_URL + "/xluser.core.login/v3/login"
631+
var resp CoreLoginResp
632+
res, err := xc.Common.Request(url, http.MethodPost, func(req *resty.Request) {
633+
req.SetHeader("User-Agent", "android-ok-http-client/xl-acc-sdk/version-5.0.12.512000")
634+
req.SetBody(&CoreLoginRequest{
635+
ProtocolVersion: "301",
636+
SequenceNo: "1000012",
637+
PlatformVersion: "10",
638+
IsCompressed: "0",
639+
Appid: APPID,
640+
ClientVersion: "8.31.0.9726",
641+
PeerID: "00000000000000000000000000000000",
642+
AppName: "ANDROID-com.xunlei.downloadprovider",
643+
SdkVersion: "512000",
644+
Devicesign: generateDeviceSign(xc.DeviceID, xc.PackageName),
645+
NetWorkType: "WIFI",
646+
ProviderName: "NONE",
647+
DeviceModel: "M2004J7AC",
648+
DeviceName: "Xiaomi_M2004j7ac",
649+
OSVersion: "12",
650+
Creditkey: xc.GetCreditKey(),
651+
Hl: "zh-CN",
652+
UserName: username,
653+
PassWord: password,
654+
VerifyKey: "",
655+
VerifyCode: "",
656+
IsMd5Pwd: "0",
657+
})
658+
}, nil)
659+
if err != nil {
660+
return "", err
661+
}
662+
663+
if err = utils.Json.Unmarshal(res, &resp); err != nil {
664+
return "", err
665+
}
666+
667+
xc.SetCoreTokenResp(&resp)
668+
669+
sessionID = resp.SessionID
670+
671+
return sessionID, nil
672+
}

drivers/thunder/meta.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,25 @@ type ExpertAddition struct {
2323
RefreshToken string `json:"refresh_token" required:"true" help:"login type is refresh_token,this is required"`
2424

2525
// 签名方法1
26-
Algorithms string `json:"algorithms" required:"true" help:"sign type is algorithms,this is required" default:"HPxr4BVygTQVtQkIMwQH33ywbgYG5l4JoR,GzhNkZ8pOBsCY+7,v+l0ImTpG7c7/,e5ztohgVXNP,t,EbXUWyVVqQbQX39Mbjn2geok3/0WEkAVxeqhtx857++kjJiRheP8l77gO,o7dvYgbRMOpHXxCs,6MW8TD8DphmakaxCqVrfv7NReRRN7ck3KLnXBculD58MvxjFRqT+,kmo0HxCKVfmxoZswLB4bVA/dwqbVAYghSb,j,4scKJNdd7F27Hv7tbt"`
26+
Algorithms string `json:"algorithms" required:"true" help:"sign type is algorithms,this is required" default:"9uJNVj/wLmdwKrJaVj/omlQ,Oz64Lp0GigmChHMf/6TNfxx7O9PyopcczMsnf,Eb+L7Ce+Ej48u,jKY0,ASr0zCl6v8W4aidjPK5KHd1Lq3t+vBFf41dqv5+fnOd,wQlozdg6r1qxh0eRmt3QgNXOvSZO6q/GXK,gmirk+ciAvIgA/cxUUCema47jr/YToixTT+Q6O,5IiCoM9B1/788ntB,P07JH0h6qoM6TSUAK2aL9T5s2QBVeY9JWvalf,+oK0AN"`
2727
// 签名方法2
2828
CaptchaSign string `json:"captcha_sign" required:"true" help:"sign type is captcha_sign,this is required"`
2929
Timestamp string `json:"timestamp" required:"true" help:"sign type is captcha_sign,this is required"`
3030

3131
// 验证码
3232
CaptchaToken string `json:"captcha_token"`
33+
// 信任密钥
34+
CreditKey string `json:"credit_key" help:"credit key,used for login"`
3335

3436
// 必要且影响登录,由签名决定
35-
DeviceID string `json:"device_id" required:"true" default:"9aa5c268e7bcfc197a9ad88e2fb330e5"`
37+
DeviceID string `json:"device_id" default:""`
3638
ClientID string `json:"client_id" required:"true" default:"Xp6vsxz_7IYVw2BB"`
3739
ClientSecret string `json:"client_secret" required:"true" default:"Xp6vsy4tN9toTVdMSpomVdXpRmES"`
38-
ClientVersion string `json:"client_version" required:"true" default:"7.51.0.8196"`
40+
ClientVersion string `json:"client_version" required:"true" default:"8.31.0.9726"`
3941
PackageName string `json:"package_name" required:"true" default:"com.xunlei.downloadprovider"`
4042

4143
//不影响登录,影响下载速度
42-
UserAgent string `json:"user_agent" required:"true" default:"ANDROID-com.xunlei.downloadprovider/7.51.0.8196 netWorkType/4G appid/40 deviceName/Xiaomi_M2004j7ac deviceModel/M2004J7AC OSVersion/12 protocolVersion/301 platformVersion/10 sdkVersion/220200 Oauth2Client/0.9 (Linux 4_14_186-perf-gdcf98eab238b) (JAVA 0)"`
44+
UserAgent string `json:"user_agent" required:"true" default:"ANDROID-com.xunlei.downloadprovider/8.31.0.9726 netWorkType/5G appid/40 deviceName/Xiaomi_M2004j7ac deviceModel/M2004J7AC OSVersion/12 protocolVersion/301 platformVersion/10 sdkVersion/512000 Oauth2Client/0.9 (Linux 4_14_186-perf-gddfs8vbb238b) (JAVA 0)"`
4345
DownloadUserAgent string `json:"download_user_agent" required:"true" default:"Dalvik/2.1.0 (Linux; U; Android 12; M2004J7AC Build/SP1A.210812.016)"`
4446

4547
//优先使用视频链接代替下载链接
@@ -74,6 +76,10 @@ type Addition struct {
7476
Username string `json:"username" required:"true"`
7577
Password string `json:"password" required:"true"`
7678
CaptchaToken string `json:"captcha_token"`
79+
// 信任密钥
80+
CreditKey string `json:"credit_key" help:"credit key,used for login"`
81+
// 登录设备ID
82+
DeviceID string `json:"device_id" default:""`
7783
}
7884

7985
// 登录特征,用于判断是否重新登录

drivers/thunder/types.go

Lines changed: 100 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ type ErrResp struct {
1818
}
1919

2020
func (e *ErrResp) IsError() bool {
21+
if e.ErrorMsg == "success" {
22+
return false
23+
}
24+
2125
return e.ErrorCode != 0 || e.ErrorMsg != "" || e.ErrorDescription != ""
2226
}
2327

@@ -61,13 +65,79 @@ func (t *TokenResp) Token() string {
6165
}
6266

6367
type SignInRequest struct {
64-
CaptchaToken string `json:"captcha_token"`
65-
6668
ClientID string `json:"client_id"`
6769
ClientSecret string `json:"client_secret"`
6870

69-
Username string `json:"username"`
70-
Password string `json:"password"`
71+
Provider string `json:"provider"`
72+
SigninToken string `json:"signin_token"`
73+
}
74+
75+
type CoreLoginRequest struct {
76+
ProtocolVersion string `json:"protocolVersion"`
77+
SequenceNo string `json:"sequenceNo"`
78+
PlatformVersion string `json:"platformVersion"`
79+
IsCompressed string `json:"isCompressed"`
80+
Appid string `json:"appid"`
81+
ClientVersion string `json:"clientVersion"`
82+
PeerID string `json:"peerID"`
83+
AppName string `json:"appName"`
84+
SdkVersion string `json:"sdkVersion"`
85+
Devicesign string `json:"devicesign"`
86+
NetWorkType string `json:"netWorkType"`
87+
ProviderName string `json:"providerName"`
88+
DeviceModel string `json:"deviceModel"`
89+
DeviceName string `json:"deviceName"`
90+
OSVersion string `json:"OSVersion"`
91+
Creditkey string `json:"creditkey"`
92+
Hl string `json:"hl"`
93+
UserName string `json:"userName"`
94+
PassWord string `json:"passWord"`
95+
VerifyKey string `json:"verifyKey"`
96+
VerifyCode string `json:"verifyCode"`
97+
IsMd5Pwd string `json:"isMd5Pwd"`
98+
}
99+
100+
type CoreLoginResp struct {
101+
Account string `json:"account"`
102+
Creditkey string `json:"creditkey"`
103+
/* Error string `json:"error"`
104+
ErrorCode string `json:"errorCode"`
105+
ErrorDescription string `json:"error_description"`*/
106+
ExpiresIn int `json:"expires_in"`
107+
IsCompressed string `json:"isCompressed"`
108+
IsSetPassWord string `json:"isSetPassWord"`
109+
KeepAliveMinPeriod string `json:"keepAliveMinPeriod"`
110+
KeepAlivePeriod string `json:"keepAlivePeriod"`
111+
LoginKey string `json:"loginKey"`
112+
NickName string `json:"nickName"`
113+
PlatformVersion string `json:"platformVersion"`
114+
ProtocolVersion string `json:"protocolVersion"`
115+
SecureKey string `json:"secureKey"`
116+
SequenceNo string `json:"sequenceNo"`
117+
SessionID string `json:"sessionID"`
118+
Timestamp string `json:"timestamp"`
119+
UserID string `json:"userID"`
120+
UserName string `json:"userName"`
121+
UserNewNo string `json:"userNewNo"`
122+
Version string `json:"version"`
123+
/* VipList []struct {
124+
ExpireDate string `json:"expireDate"`
125+
IsAutoDeduct string `json:"isAutoDeduct"`
126+
IsVip string `json:"isVip"`
127+
IsYear string `json:"isYear"`
128+
PayID string `json:"payId"`
129+
PayName string `json:"payName"`
130+
Register string `json:"register"`
131+
Vasid string `json:"vasid"`
132+
VasType string `json:"vasType"`
133+
VipDayGrow string `json:"vipDayGrow"`
134+
VipGrow string `json:"vipGrow"`
135+
VipLevel string `json:"vipLevel"`
136+
Icon struct {
137+
General string `json:"general"`
138+
Small string `json:"small"`
139+
} `json:"icon"`
140+
} `json:"vipList"`*/
71141
}
72142

73143
/*
@@ -251,3 +321,29 @@ type Params struct {
251321
PredictSpeed string `json:"predict_speed"`
252322
PredictType string `json:"predict_type"`
253323
}
324+
325+
// LoginReviewResp 登录验证响应
326+
type LoginReviewResp struct {
327+
Creditkey string `json:"creditkey"`
328+
Error string `json:"error"`
329+
ErrorCode string `json:"errorCode"`
330+
ErrorDesc string `json:"errorDesc"`
331+
ErrorDescURL string `json:"errorDescUrl"`
332+
ErrorIsRetry int `json:"errorIsRetry"`
333+
ErrorDescription string `json:"error_description"`
334+
IsCompressed string `json:"isCompressed"`
335+
PlatformVersion string `json:"platformVersion"`
336+
ProtocolVersion string `json:"protocolVersion"`
337+
Reviewurl string `json:"reviewurl"`
338+
SequenceNo string `json:"sequenceNo"`
339+
UserID string `json:"userID"`
340+
VerifyType string `json:"verifyType"`
341+
}
342+
343+
// ReviewData 验证数据
344+
type ReviewData struct {
345+
Creditkey string `json:"creditkey"`
346+
Reviewurl string `json:"reviewurl"`
347+
Deviceid string `json:"deviceid"`
348+
Devicesign string `json:"devicesign"`
349+
}

0 commit comments

Comments
 (0)