Skip to content

CDN 图片上传 ​

把图片上传到微信 CDN,返回 cdnUrl、aesKey、hdLength,给自定义小程序图片等需要 CDN 参数的接口用。

接口地址: POST /uploadCdnImage

说明与注意 ​

  • content 要是接口服务能直接访问的图片 URL。

请求参数 ​

参数名必选类型说明
wId是string登录实例标识
content是string图片 URL。图片不能超过 5M,超过返回「图片不可超过5M,请压缩」

请求示例 ​

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

{
  "wId": "{{wId}}",
  "content": "https://cdn.e-yun.example/images/customer-service.jpg"
}
bash
curl -X POST '{BASE_URL}/uploadCdnImage' \
  -H 'Authorization: Bearer <你的调用凭证>' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "wId": "{{wId}}",
  "content": "https://cdn.e-yun.example/images/customer-service.jpg"
}'
python
import requests

url = "{BASE_URL}/uploadCdnImage"
headers = {"Authorization": "Bearer <你的调用凭证>", "Content-Type": "application/json"}
body = """{
  "wId": "{{wId}}",
  "content": "https://cdn.e-yun.example/images/customer-service.jpg"
}"""

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}/uploadCdnImage";
String body = "{\n" +
    "  \"wId\": \"{{wId}}\",\n" +
    "  \"content\": \"https://cdn.e-yun.example/images/customer-service.jpg\"\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}/uploadCdnImage';
$body = <<<'JSON'
{
  "wId": "{{wId}}",
  "content": "https://cdn.e-yun.example/images/customer-service.jpg"
}
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": "上传cdn图片成功",
  "data": {
    "cdnUrl": "307b0201000474307202010002041b9042eb02033d14b90204...",
    "aesKey": "52efd887fcfdad1d71c29d0129daaabd",
    "hdLength": 173475
  }
}

错误响应 ​

json
{
  "code": "1001",
  "message": "失败",
  "data": null
}

响应参数 ​

参数名类型说明
codestring1000 成功;其他值都是失败,通常是 1001
messagestring反馈信息
dataobjectCDN 图片信息
data.cdnUrlstring图片 CDN 信息
data.aesKeystring图片 aesKey
data.hdLengthnumber图片大小