Introduction to upload temporary materials for WeChat development

Source: Internet
Author: User
This section describes in detail the development of simple materials for uploading temporary materials, and provides code analysis for your reference. Mainly for you to introduce the development of simple implementation of http://www.php.cn/php/php-tp-uploads.html "target =" _ blank "> Upload temporary materials related information, specific code analysis for your reference.

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 = comment '; $ 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 the 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, expires, 1 ); // execute curl, capture the URL, and pass it to the browser $ output = curl_exec ($ curl); // Close the cURL resource and release the system resource curl_close ($ curl ); return $ output ;}

Call uploadImg ($ imgurl) to transmit image address parameters
Returned results

array ( 'type' => 'image', 'media_id' => 'W89mt3FEaxXOMOw0fLj2Cb6A8vfMjuXrj6XW59O3l9a7Tj_h2SjlBEr4dvp4Du2R', 'created_at' => 1464140301,)

The above is the detailed introduction to upload temporary materials for development. For more information, see other related articles on php Chinese network!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.