How to upload temporary material for Wechat development
This article mainly introduces the Wechat development of how to upload temporary material, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to know about it.
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) {/ / create a new cURL resource $curl = curl_init (); / / set URL and the corresponding options 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); / / execute curl, grab URL and pass it to browser $output = curl_exec ($curl); / / close cURL resources and release system resources curl_close ($curl); return $output;}
Call uploadImg ($imgurl) to pass the image address parameter
Return the result
Array ('type' = >' image', 'media_id' = >' W89mt3FEaxXOMOw0fLj2Cb6A8vfMjuXrj6XW59O3l9a7Tjroomh3SjlBEr4dvp4Du2Race, 'created_at' = > 1464140301,) Thank you for reading this article carefully. I hope the article "how to upload temporary material for Wechat Development" shared by the editor will be helpful to you. At the same time, I hope you will support us, pay attention to the industry information channel, and wait for you to learn!