亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Home WeChat Applet WeChat Development WeChat public platform development Upload and download multimedia files

WeChat public platform development Upload and download multimedia files

Feb 22, 2017 pm 03:40 PM
Micro-channel public platform

WeChat public accounts will use media_id to call related files when replying to pictures, voices, and videos. Many friends have asked how to develop and implement this. This article will introduce how to upload and download multimedia files during the development process of WeChat public platform.

1. Upload multimedia files

Official accounts can call this interface to upload pictures, voices, videos and other files to the WeChat server. After uploading, the server will return Corresponding media_id, the official account can obtain multimedia based on this media_id. Please note that media_id is reusable, and http protocol is required to call this interface.

Usually, file upload is performed through html forms, but through CURL, you can directly submit the POST form 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 complete absolute path, and the absolute path needs to be preceded by "@" to distinguish it.

On a Windows server, the format example is: "@F:\israel\upload\winter.jpg", and on a 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

##type is media

Parameter

Is it necessary

Description

##access_token

is

Call interface credentials

## media file type, including image, voice, video and thumbnail

is the media file identifier in

form-data, including filename, filelength, content- type and other information

Upload pictures

微信公眾平臺開發(fā)  上傳下載多媒體文件 Return results

{????"type":?"image",
????"media_id":?"QQ9nj-7ctrqA8t3WKU3dQN24IuFV_516MfZRZNnQ0c-BFVkk66jUkPXF49QE9L1l",
????"created_at":?1389793969}

Upload voice

微信公眾平臺開發(fā)  上傳下載多媒體文件 Return results

{????"type":?"voice",
????"media_id":?"5Idx79V9E3XfBCz_A50gr1a1_klgPpJnb_eq73yz0bn-prhIsNlwI3n6jQgshmWk",
????"created_at":?1389794760}

Upload video

微信公眾平臺開發(fā)  上傳下載多媒體文件

Return results

{????"type":?"video",
????"media_id":?"Jm-Wq0nXtA_oN1qNydQRP03dCsB0R2t5gCHDM3QNkBmMRE1WBaorVJNQTBRHvK9-",
????"created_at":?1389794768}

Upload abbreviation Sketch

Return result微信公眾平臺開發(fā)  上傳下載多媒體文件

{????"type":?"thumb",
????"thumb_media_id":?"2RhP0caRKHVOmZO5AKelHkK--vqPPwgUaRp5-WE63dvmmPRWiYVKgvNblIp_gv79",
????"created_at":?1389794771}

Parameter description

Parameter Description

type

Media file types include image, voice, video and thumbnail, mainly Thumbnails for video and music formats)

media_id

After the media file is uploaded, it is unique when obtained Identification

created_at

Media file upload timestamp

注意事項

上傳的多媒體文件有格式和大小限制,如下:

?? 圖片(image): 128K,支持JPG格式

?? 語音(voice):256K,播放長度不超過60s,支持AMR\MP3格式

?? 視頻(video):1MB,支持MP4格式

?? 縮略圖(thumb):64KB,支持JPG格式

媒體文件在后臺保存時間為3天,即3天后media_id失效。對于需要重復使用的多媒體文件,可以每3天循環(huán)上傳一次,更新media_id。

?

二、下載多媒體文件

公眾號可調(diào)用本接口來獲取多媒體文件。請注意,視頻文件不支持下載,調(diào)用該接口需http協(xié)議。

下載文件使用獲取圖片數(shù)據(jù),寫入新文件的方法。

http請求方式: GET

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

參數(shù)說明

參數(shù)

是否必須

說明

access_token

調(diào)用接口憑證

media_id

媒體文件ID

?

下載圖片

代碼實現(xiàn)

微信公眾平臺開發(fā)  上傳下載多媒體文件

返回HTTP頭示例如下

{????"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,
????"header_size":?308,
????"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}

?

下載語音

代碼實現(xiàn)

微信公眾平臺開發(fā)  上傳下載多媒體文件

返回HTTP頭如下

{????"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,
????"header_size":?306,
????"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}

可以看出,MP3的語音格式被壓縮成AMR格式了。

?

下載縮略圖

實現(xiàn)代碼

微信公眾平臺開發(fā)  上傳下載多媒體文件

返回HTTP頭如下

{????"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,
????"header_size":?306,
????"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}

?至于回復相應的消息,就是利用消息接口或者客服接口,構(gòu)造成相應的消息就行了,和構(gòu)造文本,圖文消息的方法是一樣的。

更多微信公眾平臺開發(fā) ?上傳下載多媒體文件?相關(guān)文章請關(guān)注PHP中文網(wǎng)!


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1488
72