微信臨時素材的上傳
// 上傳臨時素材(這裡以圖片為例)
static function add_material(){
$file_info=array(
'filename'=>'/images/1.png', // 表單提交的檔案(這裡我指定的是該專案的根目錄)
);
// 上傳臨時素材文件(https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738726&token=&lang=zh_CN)
$access_token = 你自己取得到的token值
$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工具
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;
}