Temporary material:
There are often scenarios in which some temporary multimedia materials need to be used in official accounts. For example, when using interfaces, especially when sending messages, operations such as acquiring and calling multimedia files and multimedia messages are performed through media_id. The material management interface is open to all certified subscription accounts and service accounts.
caution:
1. For temporary materials, each material (media_id) will be automatically deleted 3 days after the developer uploads it or the fans send it to the WeChat server (so the material sent by the user to the developer should be downloaded locally as soon as possible if the developer needs it), Save server resources. 2. media_id is reusable. 3. The format and size of the material should be consistent with the official website of the public platform. Specifically, the size of the picture should not exceed 2M, the format of bmp/png/jpeg/jpg/gif should be supported, the size of the voice should not exceed 2M, and the length should not exceed 60 seconds (the official website of the public platform can insert voice less than 30 minutes into the article, but these voices It cannot be used in scenarios such as group sending, and can only be placed in the article. This interface is not supported at the moment), and supports mp3/wma/wav/amr format 4. You need to use https to call this interface.
1. Add temporary material
1.1. Call interface: (POST/FORM, https is required)
https://api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE
1.2. Invocation instance:
curl -F [email protected] "https://api.weixin.qq.com/cgi-bin/medi/upload?access_token=ACCESS_TOKEN&type=TYPE"
1.3. Parameter description:
ACCESS_TOKEN: call interface credentials, must
TYPE: The media file type, including image (image), voice (voice), video (video) and thumbnail (thumb), must be
MEDIA: The media file identifier in form-data contains information such as filename, filelength, content-type, etc., which must be
1.4. Return the instance:
{"type":"TYPE","media_id":"MEDIA_ID","created_at":123456789}
TYPE: media file type, including image, voice, video, and thumbnail (thumb, mainly used for thumbnails in video and music formats)
media_id: After the media file is uploaded, the unique identifier when it is obtained
created_at: media file upload timestamp
1.5. Return the error instance:
{"errcode":40004,"errmsg":"invalid media type"}
1.6. Notes
Uploaded temporary multimedia files have format and size restrictions as follows:
- Image: 2M, support bmp/png/jpeg/jpg/gif format
- Voice (voice): 2M, play length no more than 60s, support AMR\MP3 format
- Video (video): 10MB, support MP4 format
- Thumbnail (thumb): 64KB, support JPG format
Media files are kept in the background for 3 days, that is, the media_id expires after 3 days.
2. Obtain temporary material
2.1. Interface description
Video files do not support https download, and the http protocol is required to call this interface.
2.2. Call interface (GET, https call)
https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID
2.3. Invoke instance
curl -I -G "https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID"
2.4. Parameter description
access_token: call interface credentials, must
media_id: Media file ID, required
2.5. Return instructions
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 "2.6. Returns an error instance
{"errcode":40007,"errmsg":"invalid media_id"}
3. Add permanent material
3.1. Interface description
Recently updated, after the permanent image material is added, the URL will be returned to the developer, and the developer can use it within the Tencent domain name (if it is used outside the Tencent domain name, the image will be blocked).
3.1.1. The newly added permanent material can also be seen in the material management module of the official website of the public platform
3.1.2. There is an upper limit on the number of permanent materials, please add them carefully. The upper limit of text message materials and image materials is 5000, and other types are limited to 1000
3.1.3. The format and size of the materials should be consistent with the official website of the public platform. Specifically, the size of the picture should not exceed 2M, the format of bmp/png/jpeg/jpg/gif should be supported, the size of the voice should not exceed 5M, and the length should not exceed 60 seconds (the official website of the public platform can insert voice less than 30 minutes into the article, but these voices It cannot be used in scenarios such as group sending, and can only be placed in the article. This interface is not supported at the moment), and supports mp3/wma/wav/amr format
3.1.4. HTTPS protocol is required to call this interface
3.2. Calling the interface (post method)
https://api.weixin.qq.com/cgi-bin/material/add_news?access_token=ACCESS_TOKEN
3.3. Invoke instance
{
"articles": [{
"title": TITLE,
"thumb_media_id": THUMB_MEDIA_ID,
"author": AUTHOR,
"digest": DIGEST,
"show_cover_pic": SHOW_COVER_PIC(0 / 1),
"content": CONTENT,
"content_source_url": CONTENT_SOURCE_URL
},
//If the new multi-graphic material is added, there should be several paragraphs of articles structure here, up to 8 paragraphs
]
}
3.4. Parameter description
title: title, required
thumb_media_id: The id of the cover image material of the graphic message (must be a permanent mediaID), required
author: the author, required
digest: the digest of the image and text message. Only single image and text messages have digests. Multi-image and text messages are empty here and must be
show_cover_pic: Whether to display the cover, 0 is false, that is, not displayed, 1 is true, that is, it is displayed, must be
content: The specific content of the graphic message, supports HTML tags, must be less than 20,000 characters, less than 1M, and JS will be removed here, must be
content_source_url: The original address of the graphic message, that is, the URL after clicking "read the original text", it must be
3.5. Return instructions
{
"media_id":MEDIA_ID
}
3.6. Notes
In the specific content of the graphic message, the external image link will be filtered, and the developer can upload the image through the following interface to obtain the URL and put it into the graphic content for use. 3.7. Upload pictures in text messages
3.7.1. Added description
The pictures uploaded by this interface do not occupy the limit of 5000 pictures in the material library of the official account. The image only supports jpg/png format, and the size must be less than 1MB.
3.7.2. Calling the interface (post request)
https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token=ACCESS_TOKEN
3.7.3. Invoke instance
curl -F [email protected] "https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token=ACCESS_TOKEN"
3.7.4. Parameter description
access_token: call interface credentials, must
media: media file identifier in form-data, with filename, filelength, content-type and other information, must be
3.7.5. Return instructions
"url": "http://mmbiz.qpic.cn/mmbiz/gLO17UPS6FS2xsypf378iaNhWacZ1G1UplZYWEYfwvuU6Ont96b1roYs CNFwaRrSaKTPCUdBK9DgEHicsKwWCBRQ/0"
4. Add other types of permanent materials
4.1. Interface description
The interface is called through a POST form. The form id is media, which contains the content of the material to be uploaded, including filename, filelength, content-type and other information. Please note: The image material will enter the default grouping in the material management module of the official website of the public platform.
4.2. Calling the interface (post method)
https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=ACCESS_TOKEN
4.3. Parameter description
access_token: call interface credentials, must
type: The media file type, including image, voice, video, and thumbnail, which must be
media: media file identifier in form-data, with filename, filelength, content-type and other information, must be
4.4. Precautions for adding permanent video material
When uploading a video material, you need to POST another form, the id is description, which contains the description information of the material, and the content format is JSON, and the format is as follows:
{ "title":VIDEO_TITLE, "introduction":INTRODUCTION }
4.4.1. Invoke instance
curl "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=ACCESS_TOKEN" -F [email protected] -F description='{"title":VIDEO_TITLE, "introduction":INTRODUCTION}'
4.4.2. Parameter description
title: the title of the video clip
introduction: a description of the video material
4.4.3. Return instructions
{
"media_id":MEDIA_ID,
"url":URL
}
4.4.4. Return parameter description
media_id: The media_id of the newly added permanent material
url: The image URL of the newly added image material (this field will be returned only when the image material is added)
4.4.5. Returning an instance
{"errcode":40007,"errmsg":"invalid media_id"}
5. Get permanent footage
5.1. Interface description
After the permanent material is added, the developer can obtain the permanent material according to the media_id, and can also save it locally when needed.
caution:
1. To obtain permanent materials, you can also obtain materials such as graphic messages, pictures, voices, videos and other materials newly created by the official account in the material management module of the official website of the official platform (but you need to obtain the media_id of the materials by obtaining the material list first) 2. Temporary materials cannot be obtained through this interface 3. Calling this interface requires https protocol
5.2. Call interface (post method, https call)
https://api.weixin.qq.com/cgi-bin/material/get_material?access_token=ACCESS_TOKEN
5.3. Parameter description
access_token: call interface credentials, must
media_id: The media_id of the material to be obtained, it must be
5.4. Return instructions
If the requested material is a graphic message, the response is as follows:
{ "news_item": [ { "title":TITLE, "thumb_media_id":THUMB_MEDIA_ID, "thumb_url":THUMB_URL, "show_cover_pic":SHOW_COVER_PIC(0/1), "author":AUTHOR, "digest":DIGEST, "content":CONTENT, "url":URL, "content_source_url":CONTENT_SOURCE_URL }, //Multiple text messages have multiple articles ] }
If the returned video message material, the content is as follows:
{ "title":TITLE, "description":DESCRIPTION, "down_url":DOWN_URL, }
For other types of material messages, the response is directly to the content of the material, and the developer can save it as a file. E.g:
curl "https://api.weixin.qq.com/cgi-bin/material/get_material?access_token=ACCESS_TOKEN" -d '{"media_id":"61224425"}' > file
5.5. Return parameter description
title: the title of the graphic message
thumb_media_id: The id of the cover image material of the graphic message (must be a permanent mediaID)
thumb_url: The address of the cover image of the graphic message. Third-party developers can also use this URL to download the image to their own server, and then display it on their own website
show_cover_pic: whether to display the cover, 0 is false, that is, not displayed, 1 is true, that is, displayed
author: author
digest: the digest of the image and text message, only the single image and text message has the digest, and the multi-image text is empty here
content: The specific content of the graphic message, supports HTML tags, must be less than 20,000 characters, less than 1M, and JS will be removed here
url: URL of the graphic page
content_source_url: The original address of the graphic message, that is, the URL after clicking "Read the original text"
5.6. Returning an error instance
{"errcode":40007,"errmsg":"invalid media_id"}
6. Delete permanent footage
6.1. Interface description
After adding permanent materials, developers can use this interface to delete permanent materials that are no longer needed to save space.
caution:
1. Please operate this interface with caution, because it can delete the graphic messages, voice, video and other materials newly created by the official account in the material management module of the official website of the official platform (but you need to get the material list to know the media_id of the material first) 2. Temporary materials cannot be deleted through this interface 3. Calling this interface requires https protocol
6.3. Calling the interface (post method)
https://api.weixin.qq.com/cgi-bin/material/del_material?access_token=ACCESS_TOKEN
6.4. Parameter description
access_token: call interface credentials, must
media_id: The media_id of the material to be obtained, it must be
6.5. Return Instructions
{ "errcode":ERRCODE, "errmsg":ERRMSG }
Normally, when the call succeeds, the errcode will be 0.
7. Modify permanent graphic materials
7.1. Interface description
Developers can modify permanent graphic materials through this interface.
caution:
1. Graphic messages (permanent graphic materials) that can also be saved in the material management module of the official website of the public platform 2. Calling this interface requires https protocol
7.2. Calling the interface (post method)
https://api.weixin.qq.com/cgi-bin/material/update_news?access_token=ACCESS_TOKEN
7.3. Invoke instance
{ "media_id":MEDIA_ID, "index":INDEX, "articles": { "title": TITLE, "thumb_media_id": THUMB_MEDIA_ID, "author": AUTHOR, "digest": DIGEST, "show_cover_pic": SHOW_COVER_PIC(0 / 1), "content": CONTENT, "content_source_url": CONTENT_SOURCE_URL } }
7.4. Parameter description:
media_id: The id of the graphic message to be modified, it must be
index: The position of the article to be updated in the image and text message (this field is only meaningful when there are multiple image and text messages), the first article is 0, it must be
title: title, required
thumb_media_id: The id of the cover image material of the graphic message (must be a permanent mediaID), required
author: the author, required
digest: the digest of the image and text message. Only single image and text messages have digests. Multi-image and text messages are empty here and must be
show_cover_pic: Whether to display the cover, 0 is false, that is, not displayed, 1 is true, that is, it is displayed, must be
content: The specific content of the graphic message, supports HTML tags, must be less than 20,000 characters, less than 1M, and JS will be removed here, must be
content_source_url: The original address of the graphic message, that is, the URL after clicking "read the original text", it must be
7.5. Return instructions
{
"errcode": ERRCODE,
"errmsg": ERRMSG
}
The value of errcode should be 0 when correct.
8. Get the total number of materials
8.1. Interface description
Developers can obtain a list of permanent materials according to this interface, and can also save them locally when needed.
caution:
1. The total number of permanent materials will also count the materials in the material management on the official website of the public platform 2. The total number of pictures and graphic message materials (including single graphic and multi-text) is limited to 5,000, and the total number of other materials is limited to 1,000. 3. Calling this interface requires https protocol
8.2. Calling the interface (get method)
https://api.weixin.qq.com/cgi-bin/material/get_materialcount?access_token=ACCESS_TOKEN
8.3. Return instructions
{
"voice_count":COUNT,
"video_count":COUNT,
"image_count":COUNT,
"news_count":COUNT
}
8.4. Return parameter description
voice_count: total number of voices
video_count: total number of videos
image_count: total number of images
news_count: total number of pictures and texts
8.5. Returning failed instances
{"errcode":-1,"errmsg":"system error"}
9. Get the material list
9.1. Interface description:
After adding permanent materials, developers can obtain a list of permanent materials by type.
caution:
1. Obtain the list of permanent materials, and also include the new graphic messages, voice, video and other materials created by the official account in the material management module of the official website of the official platform (but you need to obtain the material list to know the media_id of the material first) 2. Temporary materials cannot be obtained through this interface 3. Calling this interface requires https protocol
9.2. Calling the interface (post method)
https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token=ACCESS_TOKEN
9.3. Calling the instance
{
"type":TYPE,
"offset":OFFSET,
"count":COUNT
}
9.4. Parameter description
type: The type of material, image (image), video (video), voice (voice), graphic (news), must be
offset: return from the offset position of all materials, 0 means return from the first material, must be
count: Returns the number of materials, ranging from 1 to 20, must be
9.5. Return instructions
The response of the permanent teletext message material list is as follows:
{ "total_count": TOTAL_COUNT, "item_count": ITEM_COUNT, "item": [{ "media_id": MEDIA_ID, "content": { "news_item": [{ "title": TITLE, "thumb_media_id": THUMB_MEDIA_ID, "thumb_url": THUMB_URL, "show_cover_pic": SHOW_COVER_PIC(0 / 1), "author": AUTHOR, "digest": DIGEST, "content": CONTENT, "url": URL, "content_source_url": CONTETN_SOURCE_URL }, //Multiple graphic messages will have multiple articles here ] }, "update_time": UPDATE_TIME }, //There may be multiple graphic message item structures ] }
Other types (picture, voice, video) are returned as follows:
{ "total_count": TOTAL_COUNT, "item_count": ITEM_COUNT, "item": [{ "media_id": MEDIA_ID, "name": NAME, "update_time": UPDATE_TIME, "url":URL }, //may have more than one material ] }
9.6. Return parameter description
total_count: The total number of assets of this type
item_count: The number of materials obtained by this call
title: The title of the graphic message
thumb_media_id: The id of the cover image material of the graphic message (must be a permanent mediaID)
thumb_url: The address of the cover image of the graphic message, third-party developers can also use this URL to download the image to their own server, and then display it on their own website
show_cover_pic: Whether to display the cover, 0 is false, that is, not displayed, 1 is true, that is, displayed
author: author
digest: the digest of the image and text message, only the single image and text message has the digest, and the multi-image text is empty here
content: The specific content of the graphic message, supports HTML tags, must be less than 20,000 characters, less than 1M, and JS will be removed here
url: The URL of the image and text page, or, when the obtained list is a list of image materials, this field is the URL of the image
content_source_url: The original address of the graphic message, that is, the URL after clicking "Read the original text"
update_time: The last update time of this graphic message material
name: file name
9.7. Error return example:
{"errcode":40007,"errmsg":"invalid media_id"}