微信临时素材的上传
// 上传临时素材(这里以图片为例)
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;
}