php微信开发之上传临时素材
本文实例为大家分享了php微信上传临时素材的具体代码,供大家参考,具体内容如下
public function uploadImg($imgUrl){ $TOKEN=$this->getAccessToken(); $URL ='http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token='.$TOKEN.'&type=image'; $data = array('media'=>'@'.$imgUrl); $result = $this->curl_post($URL,$data); $data = @json_decode($result,true); return $data['media_id']; } public function getAccessToken(){ $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxe574b1bd35d7d4da&secret=d4624c36b6795d1d99dcf0547af5443d'; $result = json_decode($this->curlGet($url),true); return $result['access_token']; } function curl_post($url, $data = null) { //创建一个新cURL资源 $curl = curl_init(); //设置URL和相应的选项 curl_setopt($curl, CURLOPT_URL, $url); if (!empty($data)){ curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); } curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //执行curl,抓取URL并把它传递给浏览器 $output = curl_exec($curl); //关闭cURL资源,并且释放系统资源 curl_close($curl); return $output; }
调用uploadImg($imgurl) 传图片地址参数
返回结果
array ( 'type' => 'image', 'media_id' => 'W89mt3FEaxXOMOw0fLj2Cb6A8vfMjuXrj6XW59O3l9a7Tj_h2SjlBEr4dvp4Du2R', 'created_at' => 1464140301,
相关推荐
83911535 2020-11-13
曾是土木人 2020-10-31
yegen00 2020-10-21
soralaro 2020-10-11
katanaFlower 2020-09-18
wytzsjzly 2020-08-17
88407710 2020-08-17
ChinaJoeEE 2020-08-16
CyborgLin 2020-08-15
Blueberry 2020-08-15
PinkBean 2020-08-11
katanaFlower 2020-08-03
hunningtu 2020-07-30
阿债的方寸天地 2020-06-28
pingyan 2020-06-25
wytzsjzly 2020-06-25
阳光岛主 2020-06-25
阿债的方寸天地 2020-06-16