Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat small program API temporary footage interface


May 19, 2021 WeChat Mini Program Development Document


Table of contents


Temporary material interface


Get temporary material

A small program can use this interface to obtain temporary materials within the customer service message (ie download temporary multimedia files).At present, a small program only supports downloading a picture file.

Interface call request

HTTP Request: GET, HTTPS Call

https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID

Request Example (Example Get multimedia files via the curl)

curl -I -G "https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID"

Parameter Description

parameter Whether it must illustrate
access_token Yes Call interface credentials
media_id Yes Media file ID

Returns

Return to the HTTP header in the correct situation is as follows:

HTTP/1.1 200 OK
Connection: close
Content-Type: image/jpeg 
Content-disposition: attachment; filename="MEDIA_ID.jpg"
Date: Sun, 06 Jan 2013 10:20:18 GMT
Cache-Control: no-cache, must-revalidate
Content-Length: 339721
curl -G "https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID"

If the return is a video message material, the content is as follows:

{
 "video_url":DOWN_URL
}

Returning to the JSON data packet in error condition is, for example, (the example is an invalid media ID error):

{
  "errcode":40007,
  "errmsg":"invalid media_id"
}


Add temporary material

The applet can use this interface to upload the media file (currently only the picture only) to the WeChat server, the user sends a customer service message or passive replying to the user message.

Interface call request

HTTP Request: Post / Form, HTTPS Call

https://api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE

Call the sample (using the curl command, upload a multimedia file with the form form):

curl -F media=@test.jpg "https://api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE"

Parameter Description

parameter Whether it must illustrate
access_token Yes Call interface credentials
type Yes image
media Is Media file identification in form-data, with fileame, filelength, content-type and other information

Return to the description

The return JSON packet results in the correct case are as follows:

{
  "type":"TYPE",
  "media_id":"MEDIA_ID",
  "created_at":123456789
}


Parameters Describe
type image
media_id After the media file is uploaded, get the logo
created_at The media file upload timestamp

An example of returning a JSON packet in an error case is as follows (example is an invalid media type error):

{
  "errcode":40004,
  "errmsg":"invalid media type"
}