Php curl to obtain https encryption protocol requests return json data for information retrieval

Source: Internet
Author: User
Php curl to obtain https encryption protocol requests return json data for information retrieval Header ("Content-type: text/html; charset = utf-8 ");
Function getToken ($ url ){
$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_URL, $ url );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); // It is critical that the results returned by curl_exec ($ ch) can be assigned to other variables, json data operation. if this statement is not provided, the data returned by curl cannot be operated manually (such as json_decode)
Curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, false );
Curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, false );
Return curl_exec ($ ch );
// $ Row = curl_getinfo ($ ch, CURLINFO_HTTP_CODE );


}
$ Row = getToken ("https://api.weixin.qq.com/cgi-bin/token? Grant_type = client_credential & appid = wxe7aae4182885340b & secret = 1fd56a902800e30442611c1e3c792259 ");
$ Obj = json_decode ($ row );
Echo $ obj-> access_token;

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.