Uploading temporary materials on WeChat
// Upload temporary materials (take pictures as an example here)
static function add_material(){
$file_info=array(
'filename'=>'/images/1.png', //The file submitted by the form (here I specify the root directory of the project)
);
// Upload temporary material documents (https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738726&token=&lang=zh_CN)
$access_token = the token value you obtained
$url="https://api.weixin.qq.com/cgi-bin/material/add_material?access_token={$access_token}&type=image";
$timeout = 5;
$real_path="{$_SERVER['DOCUMENT_ROOT']}{$file_info['filename']}";
$data= array("media"=>"@{$real_path}",'form-data'=>$file_info);
$result = self::http_url($url, $data);
$res = json_decode($result, true);
var_dump($res);
}
// curl tool
static function http_url($url,$data = null){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data)){
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
curl_close($curl);
return $output;
}