php開發工具 php微信開發之上傳臨時素材

來源:互聯網
上載者:User
本文執行個體為大家分享了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,

以上就是本文的全部內容,希望對大家的學習有所協助,也希望大家多多支援本站。

以上就介紹了php開發工具 php開發之上傳臨時素材,包括了php開發工具方面的內容,希望對PHP教程有興趣的朋友有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.