In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you "how to upload and download multimedia files in the development of Wechat public platform". The content is simple and clear. I hope it can help you solve your doubts. Now let the editor lead you to study and learn the article "how to upload and download multimedia files in the development of Wechat public platform".
I. upload multimedia files
The official account can call this API to upload pictures, voice, videos and other files to the Wechat server. After uploading, the server will return the corresponding media_id, and the official account can then obtain multimedia according to the media_id. Note that media_id is reusable and the http protocol is required to call this interface.
Usually, the file is uploaded through the html form, but through CURL, the POST submission of the form can be made directly on the server side without going through the browser to complete the file upload function.
It should be noted that the file name must be a complete absolute path, and the absolute path must be preceded by "@" to indicate the distinction.
On the Windows server, the format example is "@ F:\ israel\ upload\ winter.jpg", while on the Linux server, the format example is: "@ home/israel/upload/winter.jpg".
Http request method: POST/FORM
Http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE
Parameter description
Parameters.
Is it necessary
Description
Access_token
Yes
Calling interface credential
Type
Yes
Media file types, including picture (image), voice (voice), video (video) and thumbnail (thumb)
Media
Yes
Media file identification in form-data, such as filename, filelength, content-type, etc.
Upload pictures
Return the result
{"type": "image", "media_id": "QQ9nj-7ctrqA8t3WKU3dQN24IuFV_516MfZRZNnQ0c-BFVkk66jUkPXF49QE9L1l", "created_at": 1389793969}
Upload voice
Return the result
{"type": "voice", "media_id": "5Idx79V9E3XfBCz_A50gr1a1_klgPpJnb_eq73yz0bn-prhIsNlwI3n6jQgshmWk", "created_at": 1389794760}
Upload video
Return the result
{"type": "video", "media_id": "Jm-Wq0nXtA_oN1qNydQRP03dCsB0R2t5gCHDM3QNkBmMRE1WBaorVJNQTBRHvK9-", "created_at": 1389794768}
Upload thumbnails
Return the result
{"type": "thumb", "thumb_media_id": "2RhP0caRKHVOmZO5AKelHkK--vqPPwgUaRp5-WE63dvmmPRWiYVKgvNblIp_gv79", "created_at": 1389794771}
Parameter description
Parameters.
Description
Type
Media file types, including picture (image), voice (voice), video (video) and thumbnail (thumb, mainly used for video and music format thumbnails)
Media_id
After the media file is uploaded, the unique identification when it is obtained
Created_at
Media file upload timestamp
Matters needing attention
Uploaded multimedia files are limited in format and size, as follows:
Picture (image): 128K, which supports JPG format
Voice chat (voice): 256k, playback length is less than 60s, and AMR\ MP3 format is supported.
Video (video): 1MB, which supports MP4 format
Thumbnails (thumb): 64KB, which supports JPG format
The media file is saved in the background for 3 days, that is, the media_id expires after 3 days. For multimedia files that need to be reused, you can upload them in a cycle every 3 days and update the media_id.
Download multimedia files
The official account can call this API to obtain multimedia files. Please note that downloading of video files is not supported. Http protocol is required to call this API.
The download file uses the method of obtaining picture data and writing to a new file.
Http request method: GET
Http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID
Parameter description
Parameters.
Is it necessary
Description
Access_token
Yes
Calling interface credential
Media_id
Yes
Media file ID
Download pictures
Code implementation
An example of returning HTTP headers is as follows
{"url": "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=My4oqLEyFVrgFF-XOZagdvbTt9XywYjGwMg_GxkPwql7-f0BpnvXFCOKBUyAf0agmZfMChW5ECSyTAgAoaoU2WMyj7aVHmB17ce4HzLRZ3XFTbm2vpKt_9gYA29xrwIKpnvH-BYmNFSddt7re5ZrIg&media_id=QQ9nj-7ctrqA8t3WKU3dQN24IuFV_516MfZRZNnQ0c-BFVkk66jUkPXF49QE9L1l"," content_type ":" image/jpeg "," http_code ": 200,308" header_size "," request_size ": 316," filetime ":-1," ssl_verify_result ": 0 "redirect_count": 0, "total_time": 1.36, "namelookup_time": 1.016, "connect_time": 1.078, "pretransfer_time": 1.078, "size_upload": 0, "size_download": 105542, "speed_download": 77604, "speed_upload": 0, "download_content_length": 105542, "upload_content_length": 0 "starttransfer_time": 1.141, "redirect_time": 0}
Download voice
Code implementation
The HTTP header is returned as follows
{"url": "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=My4oqLEyFVrgFF-XOZagdvbTt9XywYjGwMg_GxkPwql7-f0BpnvXFCOKBUyAf0agmZfMChW5ECSyTAgAoaoU2WMyj7aVHmB17ce4HzLRZ3XFTbm2vpKt_9gYA29xrwIKpnvH-BYmNFSddt7re5ZrIg&media_id=5Idx79V9E3XfBCz_A50gr1a1_klgPpJnb_eq73yz0bn-prhIsNlwI3n6jQgshmWk"," content_type ":" audio/amr "," http_code ": 200,306" header_size "," request_size ": 316," filetime ":-1," ssl_verify_result ": 0 "redirect_count": 0, "total_time": 0.125, "namelookup_time": 0.031, "connect_time": 0.063, "pretransfer_time": 0.063, "size_upload": 0, "size_download": 10470, "speed_download": 83760, "speed_upload": 0, "download_content_length": 10470, "upload_content_length": 0 "starttransfer_time": 0.125, "redirect_time": 0}
It can be seen that the voice format of MP3 has been compressed into AMR format.
Download thumbnails
Implementation code
The HTTP header is returned as follows
{"url": "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=My4oqLEyFVrgFF-XOZagdvbTt9XywYjGwMg_GxkPwql7-f0BpnvXFCOKBUyAf0agmZfMChW5ECSyTAgAoaoU2WMyj7aVHmB17ce4HzLRZ3XFTbm2vpKt_9gYA29xrwIKpnvH-BYmNFSddt7re5ZrIg&media_id=2RhP0caRKHVOmZO5AKelHkK--vqPPwgUaRp5-WE63dvmmPRWiYVKgvNblIp_gv79"," content_type ":" image/jpeg "," http_code ": 200,306" header_size "," request_size ": 316," filetime ":-1," ssl_verify_result ": 0 "redirect_count": 0, "total_time": 0.094, "namelookup_time": 0, "connect_time": 0.047, "pretransfer_time": 0.047, "size_upload": 0, "size_download": 6057, "speed_download": 64436, "speed_upload": 0, "download_content_length": 6057, "upload_content_length": 0, "starttransfer_time": 0.094 "redirect_time": 0}
As for replying to the corresponding message, the message interface or customer service interface is used to construct the corresponding message, which is the same as the method of constructing text, picture and text messages.
The above is all the contents of the article "how to upload and download multimedia files in the development of Wechat public platform". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.