WeChat public account material management module

WeChat public account material management document: official document 

When seeing the new temporary material, the official way:

http请求方式:POST/FORM,使用https
https://api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE
调用示例(使用curl命令,用FORM表单方式上传一个多媒体文件):
curl -F [email protected] "https://api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE"

General development is to simulate form form post data through curl

$ch=curl_init();

curl_setopt($ch,CURLOPT_URL,$url);

curl_setopt($ch,CURLOPT_POST,true);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);   
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);//CURLOPT_POSTFIELDS
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$tmpInfo = curl_exec($ch);

//The data $data in it, this will be a bit pitted, it needs to be explained,

According to the official documentation of php.net, the option CURLOPT_POSTFILEDS  can be used to upload files through "@".$filename. This method is deprecated since PHP 5.5.0, and the CURLFILE class must be used to upload files

$obj = new CurlFile($imgUrl);
$obj->setMimeType("image/jpeg");

$post['media'] =  $obj;

$data=$post;//It needs to be encapsulated by this CurlFile first

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325849492&siteId=291194637