Get the App
SLTechnology News&Howtos  ›  Development  › 

How to upload temporary material developed by php Wechat

Shulou Source: shulou.com Published: 2022-06-03 19:30:21 11月12日 Update

This article mainly introduces how to upload temporary materials for php WeChat development. The introduction in the article is very detailed and has certain reference value. Interested friends must read it!

specific contents are as follows

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-> curl_Get ($url),true); return $result ['access_token']; } function curl_post($url, $data = null){ //Create a new cURL resource $curl = curl_init(); //Set URL and 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 resource and free system resource curl_close($curl); return $output;}

Call uploadImg($imgurl) to pass image address parameters

return results

array ( 'type' => 'image','media_id' => ' W89mt3FEaxXOMOw0fLj2Cb6A8vfMjuXrj6XW59O3l9a7Tj_h3SjlBEr4dvp4Du2R','created_at' => 1464140301, Above is "php WeChat development how to achieve upload temporary materials" All the content of this article, thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!

Tags: Content resources materials development articles values interests parameters pictures addresses guys partners more browsers knowledge systems results industry information information channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Docker OPPO Reno Redmi MySQL