6
6
"fmt"
7
7
"net/http"
8
8
"net/url"
9
+ "path"
9
10
"sort"
10
11
"strconv"
11
12
"strings"
@@ -54,17 +55,37 @@ func getTime(t string) time.Time {
54
55
}
55
56
56
57
func (d * Yun139 ) refreshToken () error {
57
- if d .ref = = nil {
58
+ if d .ref ! = nil {
58
59
return d .ref .refreshToken ()
59
60
}
60
- url := "https://aas.caiyun.feixin.10086.cn:443/tellin/authTokenRefresh.do"
61
- var resp RefreshTokenResp
62
61
decode , err := base64 .StdEncoding .DecodeString (d .Authorization )
63
62
if err != nil {
64
- return err
63
+ return fmt . Errorf ( "authorization decode failed: %s" , err )
65
64
}
66
65
decodeStr := string (decode )
67
66
splits := strings .Split (decodeStr , ":" )
67
+ if len (splits ) < 3 {
68
+ return fmt .Errorf ("authorization is invalid, splits < 3" )
69
+ }
70
+ strs := strings .Split (splits [2 ], "|" )
71
+ if len (strs ) < 4 {
72
+ return fmt .Errorf ("authorization is invalid, strs < 4" )
73
+ }
74
+ expiration , err := strconv .ParseInt (strs [3 ], 10 , 64 )
75
+ if err != nil {
76
+ return fmt .Errorf ("authorization is invalid" )
77
+ }
78
+ expiration -= time .Now ().UnixMilli ()
79
+ if expiration > 1000 * 60 * 60 * 24 * 15 {
80
+ // Authorization有效期大于15天无需刷新
81
+ return nil
82
+ }
83
+ if expiration < 0 {
84
+ return fmt .Errorf ("authorization has expired" )
85
+ }
86
+
87
+ url := "https://aas.caiyun.feixin.10086.cn:443/tellin/authTokenRefresh.do"
88
+ var resp RefreshTokenResp
68
89
reqBody := "<root><token>" + splits [2 ] + "</token><account>" + splits [1 ] + "</account><clienttype>656</clienttype></root>"
69
90
_ , err = base .RestyClient .R ().
70
91
ForceContentType ("application/xml" ).
@@ -108,15 +129,16 @@ func (d *Yun139) request(pathname string, method string, callback base.ReqCallba
108
129
//"mcloud-route": "001",
109
130
"mcloud-sign" : fmt .Sprintf ("%s,%s,%s" , ts , randStr , sign ),
110
131
//"mcloud-skey":"",
111
- "mcloud-version" : "6.6.0" ,
112
- "Origin" : "https://yun.139.com" ,
113
- "Referer" : "https://yun.139.com/w/" ,
114
- "x-DeviceInfo" : "||9|6.6.0|chrome|95.0.4638.69|uwIy75obnsRPIwlJSd7D9GhUvFwG96ce||macos 10.15.2||zh-CN|||" ,
115
- "x-huawei-channelSrc" : "10000034" ,
116
- "x-inner-ntwk" : "2" ,
117
- "x-m4c-caller" : "PC" ,
118
- "x-m4c-src" : "10002" ,
119
- "x-SvcType" : svcType ,
132
+ "mcloud-version" : "7.14.0" ,
133
+ "Origin" : "https://yun.139.com" ,
134
+ "Referer" : "https://yun.139.com/w/" ,
135
+ "x-DeviceInfo" : "||9|7.14.0|chrome|120.0.0.0|||windows 10||zh-CN|||" ,
136
+ "x-huawei-channelSrc" : "10000034" ,
137
+ "x-inner-ntwk" : "2" ,
138
+ "x-m4c-caller" : "PC" ,
139
+ "x-m4c-src" : "10002" ,
140
+ "x-SvcType" : svcType ,
141
+ "Inner-Hcy-Router-Https" : "1" ,
120
142
})
121
143
122
144
var e BaseResp
@@ -269,12 +291,12 @@ func (d *Yun139) groupGetFiles(catalogID string) ([]model.Obj, error) {
269
291
for {
270
292
data := d .newJson (base.Json {
271
293
"groupID" : d .CloudID ,
272
- "catalogID" : catalogID ,
294
+ "catalogID" : path . Base ( catalogID ) ,
273
295
"contentSortType" : 0 ,
274
296
"sortDirection" : 1 ,
275
297
"startNumber" : pageNum ,
276
298
"endNumber" : pageNum + 99 ,
277
- "path" : catalogID ,
299
+ "path" : path . Join ( d . RootFolderID , catalogID ) ,
278
300
})
279
301
280
302
var resp QueryGroupContentListResp
@@ -310,7 +332,7 @@ func (d *Yun139) groupGetFiles(catalogID string) ([]model.Obj, error) {
310
332
}
311
333
files = append (files , & f )
312
334
}
313
- if pageNum > resp .Data .GetGroupContentResult .NodeCount {
335
+ if ( pageNum + 99 ) > resp .Data .GetGroupContentResult .NodeCount {
314
336
break
315
337
}
316
338
pageNum = pageNum + 100
@@ -393,10 +415,10 @@ func (d *Yun139) personalRequest(pathname string, method string, callback base.R
393
415
"Mcloud-Client" : "10701" ,
394
416
"Mcloud-Route" : "001" ,
395
417
"Mcloud-Sign" : fmt .Sprintf ("%s,%s,%s" , ts , randStr , sign ),
396
- "Mcloud-Version" : "7.13 .0" ,
418
+ "Mcloud-Version" : "7.14 .0" ,
397
419
"Origin" : "https://yun.139.com" ,
398
420
"Referer" : "https://yun.139.com/w/" ,
399
- "x-DeviceInfo" : "||9|7.13 .0|chrome|120.0.0.0|||windows 10||zh-CN|||" ,
421
+ "x-DeviceInfo" : "||9|7.14 .0|chrome|120.0.0.0|||windows 10||zh-CN|||" ,
400
422
"x-huawei-channelSrc" : "10000034" ,
401
423
"x-inner-ntwk" : "2" ,
402
424
"x-m4c-caller" : "PC" ,
@@ -405,7 +427,7 @@ func (d *Yun139) personalRequest(pathname string, method string, callback base.R
405
427
"X-Yun-Api-Version" : "v1" ,
406
428
"X-Yun-App-Channel" : "10000034" ,
407
429
"X-Yun-Channel-Source" : "10000034" ,
408
- "X-Yun-Client-Info" : "||9|7.13 .0|chrome|120.0.0.0|||windows 10||zh-CN|||dW5kZWZpbmVk||" ,
430
+ "X-Yun-Client-Info" : "||9|7.14 .0|chrome|120.0.0.0|||windows 10||zh-CN|||dW5kZWZpbmVk||" ,
409
431
"X-Yun-Module-Type" : "100" ,
410
432
"X-Yun-Svc-Type" : "1" ,
411
433
})
0 commit comments