Appearance
CDN 资源下载
按消息 XML 里的 CDN 参数下载图片、视频或文件,返回可访问的下载地址。
接口地址: POST /cdnDownFile
说明与注意
- 不是每张图都同时有高清图、常规图和缩略图。图片下载失败时,换
fileType为1、2、3再试。
参数从 XML 哪里取
| 要下载 | fileType | cdnUrl | aeskey | totalSize |
|---|---|---|---|---|
| 高清图 | 1 | <img> 的 cdnbigimgurl | <img> 的 aeskey | hdlength |
| 常规图 | 2 | <img> 的 cdnmidimgurl | <img> 的 aeskey | length |
| 缩略图 | 3 | <img> 的 cdnthumburl | <img> 的 cdnthumbaeskey,没有就用 aeskey | cdnthumblength |
| 视频 | 4 | <videomsg> 的 cdnvideourl | <videomsg> 的 aeskey | length |
| 文件 | 5 | <appattach> 里的 cdnattachurl | <appattach> 里的 aeskey | totallen |
请求参数
| 参数名 | 必选 | 类型 | 说明 |
|---|---|---|---|
| wId | 是 | string | 登录实例标识 |
| cdnUrl | 是 | string | CDN 资源地址,从 XML 取 |
| aeskey | 是 | string | 资源解密密钥,从 XML 取 |
| fileType | 是 | int | 文件类型:1 高清图片,2 常规图片,3 缩略图,4 视频,5 文件 |
| fileName | 是 | string | 保存后的资源全名,例如 test.png |
| totalSize | 是 | int | 资源大小(字节),从 XML 取 |
请求示例
http
POST {BASE_URL}/cdnDownFile
Authorization: Bearer <你的调用凭证>
Content-Type: application/json
{
"wId": "{{wId}}",
"cdnUrl": "307f02010004783076020100020464e5eb6502033d14b90204...",
"aeskey": "4eddfc10-a37b-4498-9947-d1f203637b7d",
"fileType": 3,
"fileName": "test.jpg",
"totalSize": 206249
}bash
curl -X POST '{BASE_URL}/cdnDownFile' \
-H 'Authorization: Bearer <你的调用凭证>' \
-H 'Content-Type: application/json' \
--data-raw '{
"wId": "{{wId}}",
"cdnUrl": "307f02010004783076020100020464e5eb6502033d14b90204...",
"aeskey": "4eddfc10-a37b-4498-9947-d1f203637b7d",
"fileType": 3,
"fileName": "test.jpg",
"totalSize": 206249
}'python
import requests
url = "{BASE_URL}/cdnDownFile"
headers = {"Authorization": "Bearer <你的调用凭证>", "Content-Type": "application/json"}
body = """{
"wId": "{{wId}}",
"cdnUrl": "307f02010004783076020100020464e5eb6502033d14b90204...",
"aeskey": "4eddfc10-a37b-4498-9947-d1f203637b7d",
"fileType": 3,
"fileName": "test.jpg",
"totalSize": 206249
}"""
resp = requests.post(url, headers=headers, data=body.encode("utf-8"))
print(resp.text)java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
String url = "{BASE_URL}/cdnDownFile";
String body = "{\n" +
" \"wId\": \"{{wId}}\",\n" +
" \"cdnUrl\": \"307f02010004783076020100020464e5eb6502033d14b90204...\",\n" +
" \"aeskey\": \"4eddfc10-a37b-4498-9947-d1f203637b7d\",\n" +
" \"fileType\": 3,\n" +
" \"fileName\": \"test.jpg\",\n" +
" \"totalSize\": 206249\n" +
"}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
.header("Authorization", "Bearer <你的调用凭证>")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());php
<?php
$url = '{BASE_URL}/cdnDownFile';
$body = <<<'JSON'
{
"wId": "{{wId}}",
"cdnUrl": "307f02010004783076020100020464e5eb6502033d14b90204...",
"aeskey": "4eddfc10-a37b-4498-9947-d1f203637b7d",
"fileType": 3,
"fileName": "test.jpg",
"totalSize": 206249
}
JSON;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer <你的调用凭证>',
'Content-Type: application/json',
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;成功响应
json
{
"code": "1000",
"message": "处理成功",
"data": {
"url": "https://cdn.e-yun.example/20210812/customer-service.jpg?Expires=1629350242"
}
}错误响应
json
{
"code": "1001",
"message": "失败",
"data": null
}响应参数
| 参数名 | 类型 | 说明 |
|---|---|---|
| code | string | 1000 成功;其他值都是失败,通常是 1001 |
| message | string | 反馈信息 |
| data | object | 下载结果 |
| data.url | string | 下载后的资源访问地址 |