Skip to content

CDN 资源下载 ​

按消息 XML 里的 CDN 参数下载图片、视频或文件,返回可访问的下载地址。

下载收到的消息,先用更简单的接口

下载图片、下载文件、下载视频直接收回调里的整段 XML,不用自己拆参数。手里只有 CDN 参数、没有整段 XML 时,再用本接口。

接口地址: POST /cdnDownFile

说明与注意 ​

  • 不是每张图都同时有高清图、常规图和缩略图。图片下载失败时,换 fileType 为 1、2、3 再试。

参数从 XML 哪里取 ​

要下载fileTypecdnUrlaeskeytotalSize
高清图1<img> 的 cdnbigimgurl<img> 的 aeskeyhdlength
常规图2<img> 的 cdnmidimgurl<img> 的 aeskeylength
缩略图3<img> 的 cdnthumburl<img> 的 cdnthumbaeskey,没有就用 aeskeycdnthumblength
视频4<videomsg> 的 cdnvideourl<videomsg> 的 aeskeylength
文件5<appattach> 里的 cdnattachurl<appattach> 里的 aeskeytotallen

请求参数 ​

参数名必选类型说明
wId是string登录实例标识
cdnUrl是stringCDN 资源地址,从 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
}

响应参数 ​

参数名类型说明
codestring1000 成功;其他值都是失败,通常是 1001
messagestring反馈信息
dataobject下载结果
data.urlstring下载后的资源访问地址