Heim >php教程 >php手册 >WeChat lädt Beispielcode für temporäres Material hoch

WeChat lädt Beispielcode für temporäres Material hoch

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-11-19 13:05:292005Durchsuche

Temporäre Materialien auf WeChat hochladen
//Temporäre Materialien hochladen (hier Fotos als Beispiel machen)
statische Funktion add_material(){

$file_info=array(
'filename'=>'/images/1.png', //Die vom Formular übermittelte Datei (hier gebe ich das Stammverzeichnis des Projekts an)
);
// Temporäre Materialdokumente hochladen (https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738726&token=&lang=zh_CN)
$access_token = der Token-Wert, den Sie erhalten haben
$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
statische Funktion 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;
}

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn