Home > php教程 > php手册 > body text

WeChat upload temporary material example code

WBOY
Release: 2016-11-19 13:05:29
Original
1873 people have browsed it

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;
}

source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!