Skip to content
POST{BASE_URL}/api/cdn/urlDownload
只读CDN 文件JSON · Bearer 调用凭证 · body appid

按链接下载个微文件 ​

个微(微信)侧的媒体只给了下载链接时,凭 url 与 aesKey 取回文件;有 fileId 的附件用 cdn/download。

请求参数 ​

参数必填类型说明
appid是string实例 appid,标识操作哪个已登录账号。示例:we_xxxxxxxxxxxxxxx
url是string媒体文件的下载链接,原样传入。示例:https://imunion.weixin.qq.com/cgi-bin/mmae-bin/tpdownload…
aesKey是string文件 AESKey。示例:1a267f9b3613c512cb68095bd7b86411

请求示例 ​

http
POST {BASE_URL}/api/cdn/urlDownload
Authorization: Bearer <你的调用凭证>
Content-Type: application/json

{
  "appid": "we_xxxxxxxxxxxxxxx",
  "url": "https://imunion.weixin.qq.com/cgi-bin/mmae-bin/tpdownloadmedia?param=...",
  "aesKey": "1a267f9b3613c512cb68095bd7b86411"
}
bash
curl -X POST '{BASE_URL}/api/cdn/urlDownload' \
  -H 'Authorization: Bearer <你的调用凭证>' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "appid": "we_xxxxxxxxxxxxxxx",
  "url": "https://imunion.weixin.qq.com/cgi-bin/mmae-bin/tpdownloadmedia?param=...",
  "aesKey": "1a267f9b3613c512cb68095bd7b86411"
}'
python
import requests

url = "{BASE_URL}/api/cdn/urlDownload"
headers = {"Authorization": "Bearer <你的调用凭证>", "Content-Type": "application/json"}
body = """{
  "appid": "we_xxxxxxxxxxxxxxx",
  "url": "https://imunion.weixin.qq.com/cgi-bin/mmae-bin/tpdownloadmedia?param=...",
  "aesKey": "1a267f9b3613c512cb68095bd7b86411"
}"""

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}/api/cdn/urlDownload";
String body = "{\n" +
    "  \"appid\": \"we_xxxxxxxxxxxxxxx\",\n" +
    "  \"url\": \"https://imunion.weixin.qq.com/cgi-bin/mmae-bin/tpdownloadmedia?param=...\",\n" +
    "  \"aesKey\": \"1a267f9b3613c512cb68095bd7b86411\"\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}/api/cdn/urlDownload';
$body = <<<'JSON'
{
  "appid": "we_xxxxxxxxxxxxxxx",
  "url": "https://imunion.weixin.qq.com/cgi-bin/mmae-bin/tpdownloadmedia?param=...",
  "aesKey": "1a267f9b3613c512cb68095bd7b86411"
}
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;

响应示例 ​

解析响应前确认字段

返回字段见CDN 文件模块总览。完整响应格式及未列出的字段,请通过开通与支持联系客服确认后再解析。

响应字段 ​

字段类型说明
codeint64统一封套状态码:0=成功,负数=失败
detailstring附加明细,通常为空
messagestring文案:成功为 ok;失败形如 -码|描述
timestring服务端处理时间 YYYY-MM-DD HH:MM:SS

下一步 ​