function uploadMedia(){
$access_token = getAcessToken('5343747bcc859');//可以用自己的,我是定死测试的
$url = "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=$access_token&type=image";
$file = realpath('/1.jpg');//要求必须是绝对路径
$fields['media'] = '@'.$file;//@符号是必须要的
/**下面是请求*/
$ch = curl_init($url) ;
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch) ;
$res = curl_getinfo($ch);
dump($result);
if (curl_errno($ch)) {
return curl_error($ch);
}
curl_close($ch);
return $result;
}