基于阿里云盘的共享云盘搭建
冷眸 Lv2

背景

什么?阿里云盘公测了!? 听说下载不限速?非常nice!

但是好像分享功能还没有上线,这对于程序员的我来说,这是难不住我了,既然官方还没有开放,那我就自己做一个。

抓到的api

阿里云盘有一个APP版,还有一个网页版,自然是从网页版开始入手。

image-20210331100628902

首先抓到了个显示文件列表的

显示文件列表

https://api.aliyundrive.com/v2/file/list

请求头

key value 备注
authorization eyJhbGciOiJSU… access_token(2小时刷新一次)详见刷新token
key value 备注
drive_id 1223242 磁盘id值
parent_file_id root 上级文件夹路径
limit 100 一页显示文件数量
all false 是否显示全部
image_thumbnail_process image/resize,w_160/format,jpeg 图片缩略图类型
order_by updated_at 排序字段
order_direction desc 排序顺序
fields * 未知

返回值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
"items": [
{
"drive_id": "1223242",
"domain_id": "bj29",
"file_id": "6038dc66b124e011132a46aaaaf6fffff08ebc36",
"name": "VID_20210223_214248.mp4",
"type": "file",
"content_type": "video/mp4",
"created_at": "2021-02-26T11:32:54.009Z",
"updated_at": "2021-02-26T11:32:54.339Z",
"file_extension": "mp4",
"hidden": false,
"size": 136280333,
"starred": false,
"status": "available",
"user_meta": "{\"size\":136280333,\"android_local_file_path\":\"/storage/emulated/0/DCIM/Camera/VID_20210223_214248.mp4\",\"time\":1614059022000,\"hash\":\"0C716CF6846CCE079ECD92224724A22ADC71D406\"}",
"labels": [
"烹饪 (菜品)",
"儿童艺术",
"微笑",
"快餐",
"球鞋",
"杯子",
"鞋类",
"小吃",
"晚餐",
"海报",
"椅",
"T恤",
"碟",
"白色",
"人像",
"餐具",
"画画",
"厨师",
"幼儿",
"服装"
],
"upload_id": "rapid-2e781a23-22a0-423c-8a93-bab1beb59733",
"parent_file_id": "6038dc5554da0d739e39471cb9c53bdcdac45dec",
"crc64_hash": "3598408307415484129",
"content_hash": "BED8D94F248873F6875403B8BDC94817CD427006",
"content_hash_name": "sha1",
"download_url": "https://bj29.cn-beijing.data.alicloudccp.com/6038dbd25b5b385da00b4646add4caf99bc21c9d%2F6038dbd2e476ab32c0af4a0da7710750162a6109?di=bj29&dr=1223242&f=6038dc66b124e011132a46aaaaf6fffff08ebc36&response-content-disposition=attachment%3B+filename%2A%3DUTF-8%27%27VID_20210223_214248.mp4&u=189ed15f3805427d919594b2e3efb649&x-oss-access-key-id=LTAIsE5mAn2F493Q&x-oss-expires=1617157812&x-oss-signature=eMloFbbvX7u22UPsoIehH0XE49u%2Fx5%2BN4BMLaN7yC%2Fw%3D&x-oss-signature-version=OSS2",
"url": "https://bj29.cn-beijing.data.alicloudccp.com/6038dbd25b5b385da00b4646add4caf99bc21c9d%2F6038dbd2e476ab32c0af4a0da7710750162a6109?di=bj29&dr=1223242&f=6038dc66b124e011132a46aaaaf6fffff08ebc36&u=189ed15f3805427d919594b2e3efb649&x-oss-access-key-id=LTAIsE5mAn2F493Q&x-oss-expires=1617157812&x-oss-signature=K5D1Oxdg38RNZNm7RDQ0UY2SQDsFnvI3X%2FDo8Dmki6I%3D&x-oss-signature-version=OSS2",
"thumbnail": "https://bj29.cn-beijing.data.alicloudccp.com/6038dbd25b5b385da00b4646add4caf99bc21c9d%2F6038dbd2e476ab32c0af4a0da7710750162a6109?x-oss-access-key-id=LTAIsE5mAn2F493Q&x-oss-expires=1617157812&x-oss-process=video%2Fsnapshot%2Ct_0%2Cf_jpg%2Cw_300&x-oss-signature=0jzYbkDEv3njJljFJgonmurOo72H%2Bt49kcn%2FBXLF6jM%3D&x-oss-signature-version=OSS2",
"category": "video",
"encrypt_mode": "none",
"video_media_metadata": {
"time": "2021-02-23T13:43:42.000Z",
"width": 1920,
"height": 1080,
"image_tags": [
{
"confidence": 0.9825762790792129,
"name": "食物饮料",
"tag_level": 1
},
{
"confidence": 0.9923276305198669,
"name": "面部",
"tag_level": 1
},
{
"confidence": 0.8011763691902161,
"name": "年龄段",
"tag_level": 1
},
{
"confidence": 0.9976219579025551,
"name": "衣服",
"tag_level": 1
},
{
"confidence": 0.7839520233018058,
"name": "艺术品",
"tag_level": 1
},
{
"confidence": 0.8449591823986599,
"name": "职业&角色",
"tag_level": 1
},
{
"confidence": 0.820408284664154,
"name": "其他",
"tag_level": 1
},
{
"confidence": 0.8314134081204733,
"name": "日常行为",
"tag_level": 1
},
{
"confidence": 0.8616611758867899,
"name": "家具",
"tag_level": 1
},
{
"confidence": 0.9675047516822814,
"name": "日常用品",
"tag_level": 1
},
{
"confidence": 0.7782116880019506,
"name": "外貌特征",
"tag_level": 1
},
{
"confidence": 0.9271179407835006,
"name": "其他场景",
"tag_level": 1
},
{
"confidence": 0.9833651361642061,
"parent_name": "面部",
"name": "人",
"tag_level": 2
},
{
"confidence": 0.9825762790792129,
"parent_name": "食物饮料",
"name": "菜品",
"tag_level": 2
},
{
"confidence": 0.7318126559257507,
"parent_name": "艺术品",
"name": "佩斯利",
"tag_level": 2
},
{
"confidence": 0.9692407846450806,
"parent_name": "衣服",
"name": "珠宝",
"tag_level": 2
},
{
"confidence": 0.7272474765777588,
"parent_name": "日常用品",
"name": "玩具",
"tag_level": 2
},
{
"confidence": 0.8236032088597616,
"parent_name": "食物饮料",
"name": "饮料",
"tag_level": 2
},
{
"confidence": 0.7782116880019506,
"parent_name": "外貌特征",
"name": "微笑",
"tag_level": 2
},
{
"confidence": 0.9271179407835006,
"parent_name": "其他场景",
"name": "快餐",
"tag_level": 2
},
{
"confidence": 0.9675047516822814,
"parent_name": "日常用品",
"name": "餐具",
"tag_level": 2
},
{
"confidence": 0.8220808684825898,
"parent_name": "日常行为",
"name": "吃",
"tag_level": 2
},
{
"confidence": 0.9850760319016196,
"parent_name": "衣服",
"name": "T恤",
"tag_level": 2
},
{
"confidence": 0.8314134081204733,
"parent_name": "日常行为",
"name": "晚餐",
"tag_level": 2
},
{
"confidence": 0.743120186858707,
"parent_name": "日常用品",
"name": "杯子",
"tag_level": 2
},
{
"confidence": 0.7124511823058128,
"parent_name": "日常行为",
"name": "早午餐",
"tag_level": 2
},
{
"confidence": 0.8624917450158492,
"parent_name": "衣服",
"name": "外套",
"tag_level": 2
},
{
"confidence": 0.8449591823986599,
"parent_name": "职业&角色",
"name": "厨师",
"tag_level": 2
},
{
"confidence": 0.9414882159233093,
"parent_name": "面部",
"name": "男性",
"tag_level": 2
},
{
"confidence": 0.9923276305198669,
"parent_name": "面部",
"name": "人像",
"tag_level": 2
},
{
"confidence": 0.7988193035125732,
"parent_name": "年龄段",
"name": "婴儿",
"tag_level": 2
},
{
"confidence": 0.7625196933746338,
"parent_name": "日常行为",
"name": "烹饪",
"tag_level": 2
},
{
"confidence": 0.7596184611320496,
"parent_name": "艺术品",
"name": "海报",
"tag_level": 2
},
{
"confidence": 0.8616611758867899,
"parent_name": "家具",
"name": "椅",
"tag_level": 2
},
{
"confidence": 0.882918914159139,
"parent_name": "衣服",
"name": "鞋",
"tag_level": 2
},
{
"confidence": 0.7714708050092062,
"parent_name": "艺术品",
"name": "儿童艺术",
"tag_level": 2
},
{
"confidence": 0.8011763691902161,
"parent_name": "年龄段",
"name": "幼儿",
"tag_level": 2
},
{
"confidence": 0.9976219579025551,
"parent_name": "衣服",
"name": "服装",
"tag_level": 2
},
{
"confidence": 0.9803289771080017,
"parent_name": "衣服",
"name": "球鞋",
"tag_level": 2
},
{
"confidence": 0.9724782407283783,
"parent_name": "衣服",
"name": "鞋类",
"tag_level": 2
},
{
"confidence": 0.7719930410385132,
"parent_name": "艺术品",
"name": "画画",
"tag_level": 2
},
{
"confidence": 0.7286345362663269,
"parent_name": "衣服",
"name": "眼镜",
"tag_level": 2
},
{
"confidence": 0.7036389437588778,
"parent_name": "面部",
"name": "女性",
"tag_level": 2
},
{
"confidence": 0.820408284664154,
"parent_name": "其他",
"name": "颜色",
"tag_level": 2
},
{
"confidence": 0.703624963760376,
"parent_name": "日常行为",
"name": "午餐",
"tag_level": 2
},
{
"confidence": 0.7333434224128723,
"parent_name": "菜品",
"name": "垃圾食品",
"tag_level": 3
},
{
"confidence": 0.9152717870824477,
"parent_name": "菜品",
"name": "小吃",
"tag_level": 3
},
{
"confidence": 0.7315773963928223,
"parent_name": "菜品",
"name": "三明治",
"tag_level": 3
},
{
"confidence": 0.9592457483796513,
"parent_name": "菜品",
"name": "烹饪 (菜品)",
"tag_level": 3
},
{
"confidence": 0.7795020341873169,
"parent_name": "颜色",
"name": "黑色",
"tag_level": 3
},
{
"confidence": 0.9825762790792129,
"parent_name": "菜品",
"name": "碟",
"tag_level": 3
},
{
"confidence": 0.820408284664154,
"parent_name": "颜色",
"name": "白色",
"tag_level": 3
}
],
"video_media_video_stream": [
{
"duration": "53.922833",
"clarity": "1080",
"fps": "19374000/323537",
"bitrate": "19933246",
"code_name": "h264",
"rotate": "90"
}
],
"video_media_audio_stream": [
{
"duration": "53.888000",
"channels": 2,
"channel_layout": "stereo",
"bit_rate": "96089",
"code_name": "aac",
"sample_rate": "48000"
}
],
"duration": "53.924"
},
"video_preview_metadata": {
"bitrate": "20218321",
"duration": "53.923500",
"audio_format": "aac",
"video_format": "h264",
"frame_rate": "19374000/323537",
"height": 1920,
"width": 1080,
"template_list": [
{
"template_id": "LD",
"status": "finished"
},
{
"template_id": "SD",
"status": "finished"
},
{
"template_id": "HD",
"status": "finished"
},
{
"template_id": "FHD",
"status": "finished"
}
]
},
"punish_flag": 0
},
{
"drive_id": "1223242",
"domain_id": "bj29",
"file_id": "6038dc61c5768a2e9604450fbb97fda2ba32c770",
"name": "VID_20210223_214246.mp4",
"type": "file",
"content_type": "video/mp4",
"created_at": "2021-02-26T11:32:49.985Z",
"updated_at": "2021-02-26T11:32:54.169Z",
"file_extension": "mp4",
"hidden": false,
"size": 1566348,
"starred": false,
"status": "available",
"user_meta": "{\"size\":1566348,\"android_local_file_path\":\"/storage/emulated/0/DCIM/Camera/VID_20210223_214246.mp4\",\"time\":1614058967000,\"hash\":\"C69DCD3BD4013F9C60E5F280AA76EF828FC854E7\"}",
"labels": [
"服装",
"餐具",
"快餐",
"碟",
"人",
"晚餐",
"烹饪 (菜品)"
],
"upload_id": "429E1612CCFE4ECE911F731ABE043644",
"parent_file_id": "6038dc5554da0d739e39471cb9c53bdcdac45dec",
"crc64_hash": "2666612379672871359",
"content_hash": "91BC159F0B00CE279289464078A3D637A7D099F0",
"content_hash_name": "sha1",
"download_url": "https://bj29.cn-beijing.data.alicloudccp.com/6038dc61c5768a2e9604450fbb97fda2ba32c770%2F6038dc61af4dcac31f6542cdbd2ae69963d97510?di=bj29&dr=1223242&f=6038dc61c5768a2e9604450fbb97fda2ba32c770&response-content-disposition=attachment%3B+filename%2A%3DUTF-8%27%27VID_20210223_214246.mp4&u=189ed15f3805427d919594b2e3efb649&x-oss-access-key-id=LTAIsE5mAn2F493Q&x-oss-expires=1617157812&x-oss-signature=a%2FdJxYLuXQMsfLBZAKts5CSmuAJWEjYT1MCnVbrCz94%3D&x-oss-signature-version=OSS2",
"url": "https://bj29.cn-beijing.data.alicloudccp.com/6038dc61c5768a2e9604450fbb97fda2ba32c770%2F6038dc61af4dcac31f6542cdbd2ae69963d97510?di=bj29&dr=1223242&f=6038dc61c5768a2e9604450fbb97fda2ba32c770&u=189ed15f3805427d919594b2e3efb649&x-oss-access-key-id=LTAIsE5mAn2F493Q&x-oss-expires=1617157812&x-oss-signature=ETMcMTaZRz%2B9EykUbrcpQneLWKkpAZu7Z10dOd%2FRPos%3D&x-oss-signature-version=OSS2",
"thumbnail": "https://bj29.cn-beijing.data.alicloudccp.com/6038dc61c5768a2e9604450fbb97fda2ba32c770%2F6038dc61af4dcac31f6542cdbd2ae69963d97510?x-oss-access-key-id=LTAIsE5mAn2F493Q&x-oss-expires=1617157812&x-oss-process=video%2Fsnapshot%2Ct_0%2Cf_jpg%2Cw_300&x-oss-signature=o6bswXryerhwBQ%2BsDGWwVHARbzOTHssKWYZ7gMPq3b0%3D&x-oss-signature-version=OSS2",
"category": "video",
"encrypt_mode": "none",
"video_media_metadata": {
"time": "2021-02-23T13:42:47.000Z",
"width": 1920,
"height": 1080,
"image_tags": [
{
"confidence": 0.9994364976882935,
"name": "食物饮料",
"tag_level": 1
},
{
"confidence": 0.9998117089271545,
"name": "面部",
"tag_level": 1
},
{
"confidence": 0.8567114472389221,
"name": "日常行为",
"tag_level": 1
},
{
"confidence": 0.9996705055236816,
"name": "衣服",
"tag_level": 1
},
{
"confidence": 0.9630321860313416,
"name": "其他场景",
"tag_level": 1
},
{
"confidence": 0.9942723512649536,
"name": "日常用品",
"tag_level": 1
},
{
"confidence": 0.9998117089271545,
"parent_name": "面部",
"name": "人",
"tag_level": 2
},
{
"confidence": 0.8343067765235901,
"parent_name": "食物饮料",
"name": "饮料",
"tag_level": 2
},
{
"confidence": 0.9971349239349365,
"parent_name": "衣服",
"name": "T恤",
"tag_level": 2
},
{
"confidence": 0.9957389235496521,
"parent_name": "面部",
"name": "人像",
"tag_level": 2
},
{
"confidence": 0.9942723512649536,
"parent_name": "日常用品",
"name": "餐具",
"tag_level": 2
},
{
"confidence": 0.9994364976882935,
"parent_name": "食物饮料",
"name": "菜品",
"tag_level": 2
},
{
"confidence": 0.993707537651062,
"parent_name": "面部",
"name": "男性",
"tag_level": 2
},
{
"confidence": 0.9630321860313416,
"parent_name": "其他场景",
"name": "快餐",
"tag_level": 2
},
{
"confidence": 0.7879353761672974,
"parent_name": "日常行为",
"name": "早午餐",
"tag_level": 2
},
{
"confidence": 0.9996705055236816,
"parent_name": "衣服",
"name": "服装",
"tag_level": 2
},
{
"confidence": 0.8567114472389221,
"parent_name": "日常行为",
"name": "晚餐",
"tag_level": 2
},
{
"confidence": 0.7285393476486206,
"parent_name": "日常行为",
"name": "吃",
"tag_level": 2
},
{
"confidence": 0.9305303692817688,
"parent_name": "菜品",
"name": "小吃",
"tag_level": 3
},
{
"confidence": 0.9983654618263245,
"parent_name": "菜品",
"name": "烹饪 (菜品)",
"tag_level": 3
},
{
"confidence": 0.9994364976882935,
"parent_name": "菜品",
"name": "碟",
"tag_level": 3
}
],
"video_media_video_stream": [
{
"duration": "0.133289",
"clarity": "1080",
"fps": "180000/2999",
"bitrate": "20641180",
"code_name": "h264",
"rotate": "90"
}
],
"video_media_audio_stream": [
{
"duration": "0.085333",
"channels": 2,
"channel_layout": "stereo",
"bit_rate": "127875",
"code_name": "aac",
"sample_rate": "48000"
}
],
"duration": "0.133"
},
"video_preview_metadata": {
"bitrate": "94004381",
"duration": "0.133300",
"audio_format": "aac",
"video_format": "h264",
"frame_rate": "180000/2999",
"height": 1920,
"width": 1080,
"template_list": [
{
"template_id": "LD",
"status": "finished"
},
{
"template_id": "SD",
"status": "finished"
},
{
"template_id": "HD",
"status": "finished"
},
{
"template_id": "FHD",
"status": "finished"
}
]
},
"punish_flag": 0
}
],
"next_marker": ""
}

刷新token

https://auth.aliyundrive.com/v2/account/token

主要请求头

key value 备注
Content-Type application/x-www-form-urlencoded 请求body类型

Request Body

1
{"refresh_token":"81c23489bc474a52aba2682171b49bd7","grant_type":"refresh_token"}

Response

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiIxODllZDE1ZjM4MDU0MjdkOTE5NTk0YjJlM2VmYjY0OSIsImN1c3RvbUpzb24iOiJ7XCJjbGllbnRJZFwiOlwiMjVkelgzdmJZcWt0Vnh5WFwiLFwiZG9tYWluSWRcIjpcImJqMjlcIixcInNjb3BlXCI6W1wiRFJJVkUuQUxMXCIsXCJTSEFSRS5BTExcIixcIkZJTEUuQUxMXCIsXCJVU0VSLkFMTFwiLFwiU1RPUkFHRS5BTExcIixcIlNUT1JBR0VGSUxFLkxJU1RcIixcIkJBVENIXCIsXCJPQVVUSC5BTExcIixcIklNQUdFLkFMTFwiLFwiSU5WSVRFLkFMTFwiXSxcInJvbGVcIjpcInVzZXJcIn0iLCJleHAiOjE2MTcxNjQ1OTMsImlhdCI6MTYxNzE1NzMzM30.Aiyx0_Uu6-VXmKYiwg7o-7yVn56JZ4TdPlutWy1gKdCTDBEiwDpz-DAJ8b0v_Jb4jkn-oKIY0OYtd0b3ED3eSrASAZzGYpO5G-nNAfP8lalQvniHxMOIkpuZR5VQILwnGaGWySyOLtSe4iqX0eZ_aIloakp_u-I7PMDaHCxps9U",
"refresh_token": "IY0OYtd0b3ED3eSrASAZz",
"expires_in": 7200,
"token_type": "Bearer",
"user_id": "189ed15f3805427d919594b2e3efb649",
"user_name": "156***040",
"avatar": "",
"nick_name": "",
"default_drive_id": "1223242",
"default_sbox_drive_id": "1223243",
"role": "user",
"status": "enabled",
"expire_time": "2021-03-31T04:23:13Z",
"state": "",
"exist_link": [],
"need_link": false,
"user_data": {
"DingDingRobotUrl": "https://oapi.dingtalk.com/robot/send?access_token=0b4a936d0e98c08608cd99f693393c18fa905aa0868215485a28497501916fec",
"EncourageDesc": "内测期间有效反馈前10名用户将获得终身免费会员",
"FeedBackSwitch": true,
"FollowingDesc": "34848372",
"back_up_config": {
"手机备份": {
"folder_id": "605bf483c4632a898a0647b982411042b3461108",
"photo_folder_id": "605bf483ca63adc60aad4d32abc75fa248c8c595",
"sub_folder": {},
"video_folder_id": "605bf483fbfe413356664e6aad0531ff9f9080b7"
}
},
"ding_ding_robot_url": "https://oapi.dingtalk.com/robot/send?access_token=0b4a936d0e98c08608cd99f693393c18fa905aa0868215485a28497501916fec",
"encourage_desc": "内测期间有效反馈前10名用户将获得终身免费会员",
"feed_back_switch": true,
"following_desc": "34848372"
},
"pin_setup": false,
"is_first_login": false,
"need_rp_verify": false,
"device_id": "71d6242ef0a44219b4cfa34d968115b5"
}

得到的access_token为请求api必备的鉴权api,基本上所有的请求,请求头都需要加入authorization值就是access_token,**”expires_in”: 7200** 表示刷新时间为2小时。

获取用户信息

https://api.aliyundrive.com/v2/user/get

Request Header

key value 备注
authorization eyJhbGciOiJSU… access_token(2小时刷新一次)详见刷新token

Request Body

1
{}

Response Body

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{
"domain_id": "bj29",
"user_id": "189ed15f3805427d919594b2e3efb649",
"avatar": "",
"created_at": 1614338949038,
"updated_at": 1616639107250,
"email": "",
"nick_name": "",
"phone": "156***40",
"role": "user",
"status": "enabled",
"user_name": "156***040",
"description": "",
"default_drive_id": "1223242",
"user_data": {
"back_up_config": {
"手机备份": {
"folder_id": "605bf483c4632a898a0647b982411042b3461108",
"photo_folder_id": "605bf483ca63adc60aad4d32abc75fa248c8c595",
"sub_folder": {},
"video_folder_id": "605bf483fbfe413356664e6aad0531ff9f9080b7"
}
}
}
}

获取文件详情

https://api.aliyundrive.com/v2/file/get

Request Header

key value 备注
authorization eyJhbGciOiJSU… access_token(2小时刷新一次)详见刷新token

Request Body

1
2
3
4
{
"drive_id":"1223242",
"file_id":"6038dc66b124e011132a46aaaaf6fffff08ebc36"
}

dirve_id 表示磁盘id

file_id 表示要获取的文件的id

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{
"drive_id": "1223242",
"domain_id": "bj29",
"file_id": "6059622cd2e3111a4a4b41d2a640c2287188b024",
"name": "navicatpremiumchspj.zip",
"type": "file",
"content_type": "application/oct-stream",
"created_at": "2021-03-23T03:36:12.889Z",
"updated_at": "2021-03-23T03:36:12.889Z",
"file_extension": "zip",
"hidden": false,
"size": 71804315,
"starred": false,
"status": "available",
"upload_id": "rapid-73cf6a54-2db8-4150-9528-0eab7d68df6b",
"parent_file_id": "605962258b64be31035f450289ff610f06b627bb",
"crc64_hash": "3814220635283411191",
"content_hash": "F1D49F8641661ECE1CA41A17588A0106FD79C0F0",
"content_hash_name": "sha1",
"download_url": "https://bj29.cn-beijing.data.alicloudccp.com/5fb4ff0f2d4647bc93d24b0f9f02082e9aa698e8%2F5fb4ff0f02c43de37548425ab0120125a4bf5e90?di=bj29&dr=1223242&f=6059622cd2e3111a4a4b41d2a640c2287188b024&response-content-disposition=attachment%3B+filename%2A%3DUTF-8%27%27navicatpremiumchspj.zip&u=189ed15f3805427d919594b2e3efb649&x-oss-access-key-id=LTAIsE5mAn2F493Q&x-oss-expires=1617160047&x-oss-signature=uqUjVis%2BKqQK3bn%2FWF8NF48WoInDRJrKcWvsZUM43bk%3D&x-oss-signature-version=OSS2",
"url": "https://bj29.cn-beijing.data.alicloudccp.com/5fb4ff0f2d4647bc93d24b0f9f02082e9aa698e8%2F5fb4ff0f02c43de37548425ab0120125a4bf5e90?di=bj29&dr=1223242&f=6059622cd2e3111a4a4b41d2a640c2287188b024&u=189ed15f3805427d919594b2e3efb649&x-oss-access-key-id=LTAIsE5mAn2F493Q&x-oss-expires=1617160047&x-oss-signature=KmgpmoZ%2FXgx8%2FLyZyPSPS8mN68Zubk%2FPXCafZ5KMdJ4%3D&x-oss-signature-version=OSS2",
"category": "zip",
"encrypt_mode": "none",
"punish_flag": 0,
"trashed": false
}

获取文件下载链接

https://api.aliyundrive.com/v2/file/get_download_url

请求跟获取文件详情一致

Respones Body

1
2
3
4
5
6
7
8
9
10
11
{
"method":"GET",
"url":"https://bj29.cn-beijing.data.alicloudccp.com/5fb4ff0f2d4647bc93d24b0f9f02082e9aa698e8%2F5fb4ff0f02c43de37548425ab0120125a4bf5e90?di=bj29&dr=1223242&f=6059622cd2e3111a4a4b41d2a640c2287188b024&response-content-disposition=attachment%3B+filename%2A%3DUTF-8%27%27navicatpremiumchspj.zip&u=189ed15f3805427d919594b2e3efb649&x-oss-access-key-id=LTAIsE5mAn2F493Q&x-oss-additional-headers=referer&x-oss-expires=1617160338&x-oss-signature=H0D7ibFJ3hKuNeWqWpo5flMJBPEtQJvR%2FQ%2FxhlAfKT4%3D&x-oss-signature-version=OSS2",
"expiration":"2021-03-31T03:12:18.595Z",
"size":71804315,
"ratelimit":{
"part_speed":-1,
"part_size":-1
}
}

搭建

直接使用guns框架速搭

实现的功能

  • 文件列表
  • 文件下载
  • 视频在线播放
  • 批量复制文件下载链接
  • 定时刷新token

代码

定时刷新token
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package cn.stylefeng.guns.core.schedue.token;

import cn.stylefeng.guns.config.aliyunpan.AliYunPanProperties;
import cn.stylefeng.guns.sys.core.constant.Const;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHeaders;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.InitBinder;

import javax.annotation.PostConstruct;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

/**
* @program: guns-vip
* @author: wkj
* @create: 2021-03-26 17:31
**/
@Service
@Log4j2
public class AliYunPanToken {

@Autowired
private AliYunPanProperties aliYunPanProperties;

private CloseableHttpClient httpClient = HttpClientBuilder.create().build();


/**
* 刷新token 获取 access_token
* @return
*/
@PostConstruct
public void refreshToken(){
HttpPost httpPost = new HttpPost(Const.REFRESH_TOKEN_URI);
httpPost.setHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");
List<BasicNameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("refresh_token",aliYunPanProperties.getRefreshToken()));
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(params, StandardCharsets.UTF_8);
httpPost.setEntity(formEntity);
CloseableHttpResponse response = null;
try {
response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
String s = EntityUtils.toString(entity);
JSONObject resJson = JSON.parseObject(s);
aliYunPanProperties.setRefreshToken(resJson.getString("refresh_token"));
aliYunPanProperties.setAccessToken(resJson.getString("access_token"));
aliYunPanProperties.setDeviceId(resJson.getString("default_drive_id"));
log.info("刷新token成功!!");

} catch (Exception e) {
e.printStackTrace();
log.error("刷新token失败,请检查refresh_token是否过期");
}
}


}
1
2
3
4
5
6
7
8
/**
* 每两小时执行一次 刷新token 因为access_token 每两小时过期一次
*/
@Scheduled(cron = "0 0 0/2 * * *")
public void cron() {
log.info("定时任务:开始刷新token");
aliYunPanToken.refreshToken();
}
文件列表
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package cn.stylefeng.guns.modular.aliyun.service;

import cn.stylefeng.guns.config.aliyunpan.AliYunPanProperties;
import cn.stylefeng.guns.core.schedue.token.AliYunPanToken;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHeaders;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
* @program: guns-vip
* @author: wkj
* @create: 2021-03-27 10:21
**/
@Service
public class AliYunPanService {

@Autowired
private AliYunPanProperties aliYunPanProperties;

@Autowired
private AliYunPanToken aliYunPanToken;

private CloseableHttpClient httpClient = HttpClientBuilder.create().build();

/**
* 判断有没有过期
* @return
*/
public CloseableHttpResponse getHttpResponse(HttpPost httpPost){
try {
CloseableHttpResponse response = httpClient.execute(httpPost);
if(response.getStatusLine().getStatusCode()!=200){
aliYunPanToken.refreshToken();
return httpClient.execute(httpPost);
}
return response;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

/**
* 获取用户基本信息
*/

public JSONObject getUser(){
HttpPost httpPost = new HttpPost("https://api.aliyundrive.com/v2/user/get");
httpPost.setHeader(HttpHeaders.AUTHORIZATION, aliYunPanProperties.getAccessToken());
httpPost.setHeader(HttpHeaders.CONTENT_TYPE, "application/json;charset=utf8");
StringEntity stringEntity = new StringEntity("{}", "utf-8");
httpPost.setEntity(stringEntity);
CloseableHttpResponse httpResponse = getHttpResponse(httpPost);
JSONObject jsonObject = parseResponseToJSON(httpResponse);
String driveId = jsonObject.getString("default_drive_id");
aliYunPanProperties.setDeviceId(driveId);
return jsonObject;
}

/**
* 获取文件类表
*/
public JSONObject getList(String parentFileId){
HttpPost httpPost = new HttpPost("https://api.aliyundrive.com/v2/file/list");
httpPost.setHeader(HttpHeaders.AUTHORIZATION, aliYunPanProperties.getAccessToken());
httpPost.setHeader(HttpHeaders.CONTENT_TYPE, "application/json;charset=utf8");
JSONObject param = new JSONObject();
param.put("drive_id",aliYunPanProperties.getDeviceId());
// 如果parentFileId不为空,默认顶级
param.put("parent_file_id", StringUtils.isNotBlank(parentFileId)?parentFileId:"root");
StringEntity stringEntity = new StringEntity(param.toJSONString(), "utf-8");
httpPost.setEntity(stringEntity);
CloseableHttpResponse httpResponse = getHttpResponse(httpPost);
JSONObject jsonObject = parseResponseToJSON(httpResponse);

return jsonObject;
}

/**
* 获取文件详情
*/
public JSONObject getFile(String fileId){
HttpPost httpPost = new HttpPost("https://api.aliyundrive.com/v2/file/get");
httpPost.setHeader(HttpHeaders.AUTHORIZATION, aliYunPanProperties.getAccessToken());
httpPost.setHeader(HttpHeaders.CONTENT_TYPE, "application/json;charset=utf8");
JSONObject param = new JSONObject();
param.put("drive_id",aliYunPanProperties.getDeviceId());
param.put("file_id", fileId);
StringEntity stringEntity = new StringEntity(param.toJSONString(), "utf-8");
httpPost.setEntity(stringEntity);
CloseableHttpResponse httpResponse = getHttpResponse(httpPost);
JSONObject jsonObject = parseResponseToJSON(httpResponse);
return jsonObject;
}
/**
* 获取文件下载链接
*/
public JSONObject getFileDownLoadUrl(String fileId){
HttpPost httpPost = new HttpPost("https://api.aliyundrive.com/v2/file/get_download_url");
httpPost.setHeader(HttpHeaders.AUTHORIZATION, aliYunPanProperties.getAccessToken());
httpPost.setHeader(HttpHeaders.CONTENT_TYPE, "application/json;charset=utf8");
JSONObject param = new JSONObject();
param.put("drive_id",aliYunPanProperties.getDeviceId());
param.put("file_id", fileId);
StringEntity stringEntity = new StringEntity(param.toJSONString(), "utf-8");
httpPost.setEntity(stringEntity);
CloseableHttpResponse httpResponse = getHttpResponse(httpPost);
JSONObject jsonObject = parseResponseToJSON(httpResponse);
return jsonObject;
}

/**
* 转换响应为json
* parse response
*/
public JSONObject parseResponseToJSON(CloseableHttpResponse response){
HttpEntity entity = response.getEntity();
String s = null;
try {
s = EntityUtils.toString(entity);
} catch (IOException e) {
e.printStackTrace();
}
JSONObject resJson = JSON.parseObject(s);
return resJson;
}




}

前端

使用layui

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
layui.use(['table', 'admin', 'ax','element'], function () {
var $ = layui.$;
var table = layui.table;
var $ax = layui.ax;
var admin = layui.admin;
var element = layui.element;
/**
* Guns复杂表单的示例管理
*/
var EgForm = {
tableId: "fileListTable"
};
$("#copy").hide();
var rendera = function(){
$("#nav a").on('click',
function () {
var queryData = {};
queryData['fileId'] = $(this).attr("name");
table.reload(EgForm.tableId, {
where: queryData, page: {curr: 1}
});
$(this).nextAll().remove();
}
);
}
/**
* 初始化表格的列
*/
EgForm.initColumn = function () {
return [[
{type: 'checkbox'},
{field: 'file_id', align: "center",align: 'center', hide: true, title: '文件id'},
{field: 'name', align: "center",align: 'center', sort: true, title: '名称'},
{field: 'type',title: '文件类型',hide: true},
{field: 'size',title: '文件大小',align: 'center',templet:function (d) {
if(d.type==='file'){
return ((d.size/1024)/1024).toFixed(2)+"MB"
}else{
return '-'
}
}},
{field: 'typeName',title: '文件类型',templet:function (d) {
return d.type=='file'?'文件':'文件夹';
}},
{field: 'download_url',title: '下载地址'},
{field:'file_extension',title: '文件后缀',hide: true},
{align: 'center', toolbar: '#tableBar', title: '操作'}
]];
};

/**
* 点击查询按钮
*/
EgForm.search = function () {
var queryData = {};
queryData['condition'] = $("#condition").val();
table.reload(EgForm.tableId, {
where: queryData, page: {curr: 1}
});
};

/**
* 弹出添加对话框
*/
EgForm.openAddDlg = function () {
admin.putTempData('formOk', false);
top.layui.admin.open({
type: 2,
title: '添加Guns复杂表单的示例',
content: Feng.ctxPath + '/egForm/add',
end: function () {
admin.getTempData('formOk') && table.reload(EgForm.tableId);
}
});
};

/**
* 导出excel按钮
*/
EgForm.exportExcel = function () {
var checkRows = table.checkStatus(EgForm.tableId);
if (checkRows.data.length === 0) {
Feng.error("请选择要获取下载链接的文件");
} else {
var urls='';
for (let i = 0; i < checkRows.data.length; i++) {
if(checkRows.data[0].type==='file'){
urls+=checkRows.data[i].download_url+"<br/>"
}
}
if(urls){
admin.open({
type: 1,
title: '复制链接',
content: ""+urls,
area:['600px', '500px']
});
}else{
Feng.info("没有文件")
}
}
};

/**
* 点击删除
*
* @param data 点击按钮时候的行数据
*/
EgForm.onDeleteItem = function (data) {
var operation = function () {
var ajax = new $ax(Feng.ctxPath + "/egForm/delete", function (data) {
Feng.success("删除成功!");
table.reload(EgForm.tableId);
}, function (data) {
Feng.error("删除失败!" + data.responseJSON.message + "!");
});
ajax.set("formId", data.formId);
ajax.start();
};
Feng.confirm("是否删除?", operation);
};

// 渲染表格
var tableResult = table.render({
elem: '#' + EgForm.tableId,
url: Feng.ctxPath + '/ali/list',
page: true,
height: "full-98",
cellMinWidth: 100,
cols: EgForm.initColumn()
});

// 搜索按钮点击事件
$('#btnSearch').click(function () {
EgForm.search();
});

// 添加按钮点击事件
$('#btnAdd').click(function () {
window.location.href = Feng.ctxPath + "/egForm/add";
});

// 导出excel
$('#btnExp').click(function () {
EgForm.exportExcel();
});

EgForm.copy = function (data){
if(data.type ==='file'){
$("#copy").show();
$("#copy").val(data.download_url);
var input = document.getElementById("copy")
input.select();
input.setSelectionRange(0, 9999);
if (document.execCommand('Copy')) {
Feng.success("复制成功")
}
$("#copy").hide();
}else{
Feng.info("文件夹没有链接!")
}
}

EgForm.player = function (data){
admin.open({
type: 2,
title: '播放',
content: Feng.ctxPath+"/ali/player?fileId="+data.file_id,
});
}
// 工具条点击事件
table.on('tool(' + EgForm.tableId + ')', function (obj) {
var data = obj.data;
var layEvent = obj.event;

if (layEvent === 'delete') {
EgForm.onDeleteItem(data);
} else if(layEvent === 'copy') {
EgForm.copy(data);
} else if(layEvent === 'player'){
EgForm.player(data);
}
});

table.on('rowDouble('+EgForm.tableId+')', function(obj){
//获取当前行的数据
var data = obj.data;
if(data.type === 'folder'){
var queryData = {};
queryData['fileId'] = data.file_id;
table.reload(EgForm.tableId, {
where: queryData, page: {curr: 1}
});
$("#nav").append("<span lay-separator>/</span><a href='#' name='"+data.file_id+"'>"+data.name+"</a>");
rendera();
// element.render('breadcrumb','path');
}else{
Feng.info("暂不支持打开文件");
}
});








});

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
@layout("/common/_container.html",{js:["/assets/aliyunpan/aliyunpan.js"]}){

<div class="layui-body-header">
<span class="layui-body-header-title">文件列表</span>
</div>
<input type="text" id="copy">
<div class="layui-fluid">
<div class="layui-row layui-col-space15">
<div class="layui-col-sm12 layui-col-md12 layui-col-lg12">
<div class="layui-card">
<div class="layui-card-body">
<div class="layui-form toolbar">
<div class="layui-form-item">
<div class="layui-inline">
<input id="condition" class="layui-input" type="text" placeholder="名称"/>
</div>
<div class="layui-inline">
<button id="btnSearch" class="layui-btn icon-btn"><i class="layui-icon"></i>搜索
</button>
<!-- <button id="btnAdd" class="layui-btn icon-btn"><i class="layui-icon"></i>添加-->
<!-- </button>-->
<button id="btnExp" class="layui-btn icon-btn"><i class="layui-icon"></i>批量下载
</button>
</div>
</div>
</div>
<span id="nav" class="layui-breadcrumb" lay-separator="/" lay-filter="path">
<a href='#' name="root">首页</a>
</span>
<table class="layui-table" id="fileListTable" lay-filter="fileListTable"></table>
</div>
</div>
</div>
</div>
</div>

<script type="text/html" id="tableBar">
{{# if(d.file_extension=='mp4'){ }}
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="player">播放</a>
{{# } }}
{{# if(d.type=='file'){ }}
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="copy">复制链接</a>
{{# } }}
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="edit">编辑</a>
</script>
@}

最终效果

首页

image-20210331111523367

播放页面

image-20210331111622894

只是简单地实现了一些功能,更多的功能,看心情维护吧。。。

  • 本文标题:基于阿里云盘的共享云盘搭建
  • 本文作者:冷眸
  • 创建时间:2021-03-31 03:21:17
  • 本文链接:https://www.lengmou.net//articles/2021/03/31/1617160877140.html
  • 版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!