May 19, 2021 WeChat Mini Program Development Document
This interface should be called on the server side, as detailed in the Service Side API.
This interface supports cloud calls. Developer tool version required . . . 1.02.1904090 (latest stable download)
wx-server-sdk >= 0.4.0
Get temporary footage within a customer service message. T hat is, download temporary multimedia files. At present, the small program only supports downloading picture files.
How to call:
GET https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID
Property | Type | The default | Required | Description |
---|---|---|---|---|
access_token | string | Is | The interface calls the credentials | |
media_id | string | Is | Media file ID |
The returned picture is Buffer
Json
Property | Type | Description |
---|---|---|
errcode | number | Error code |
errmsg | string | The error message |
The legal value of errcode
Value | Description | The lowest version |
---|---|---|
40007 | The invalid media file ID |
If the call is successful, the picture binary content is returned directly, and if the request fails, the data in JSON format is returned.
Use the CURL command to upload a multimedia file as a FORM form
curl -I -G "https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID"
Cloud call is the ability provided by the small program Cloud Development to call WeChat open interfaces in cloud functions and need to be used in cloud functions via wx-server-sdk.
openapi.customerServiceMessage.getTempMedia
The permissions for the customerServiceMessage.getTempMedia API need to be configured in config.json, details
Property | Type | The default | Required | Description |
---|---|---|---|---|
mediaId | string | Is | Media file ID |
An object that contains binary data and its data type
Property | Type | Description |
---|---|---|
contentType | String | Data Type (MIME Type) |
buffer | Buffer | Data Buffer |
Json
Property | Type | Description |
---|---|---|
errCode | number | Error code |
errMsg | string | The error message |
The legal value of errCode
Value | Description | The lowest version |
---|
const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event, context) => {
try {
const result = await cloud.openapi.customerServiceMessage.getTempMedia({
mediaId: ''
})
return result
} catch (err) {
return err
}
}
// cloud = require('wx-server-sdk')
// ...
// 方法返回 Promise
cloud.openapi.customerServiceMessage.getTempMedia({
mediaId: 'MEDIA_ID'
})
{
"errCode": 0,
"errMsg": "openapi.customerServiceMessage.getTempMedia:ok",
"contentType": "image/jpeg",
"buffer": Buffer
}