Home >php教程 >php手册 >Thinkphp5.0 calls the data method of the free API interface

Thinkphp5.0 calls the data method of the free API interface

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-08-15 16:49:582626browse

I applied for several free API interfaces on the aggregate data website to play with, and then studied the method of calling data using Thinkphp5.0. Currently, I can use this to get the data. I just added a method and condition in the controller. All are added manually. Of course, variables can also be used to dynamically add conditions, depending on the interface situation.
<?php<br /> namespace appindexcontroller;<br /> use thinkController;<br /> <br /> class Index extends Controller<br /> {<br /> Public function news(){<br />          $appkey = "db05e1234f593a7b458b43c3bfb2a000";<br />               //************1. Headline news information query************<br /> ​​​​$url = "http://v.juhe.cn/toutiao/index";<br />          $params = [<br /> "type" => "top",//Type<br> "dtype" => "json", //Return data format: json or xml, default json<br> "key" => $appkey,//The key you applied for<br> ];<br> $ Paramstring = http_build_qury ($ Params);/*Require string after generating URL-Encode*/<br> <br> ​​​​​//print_r($paramstring);<br> // echo "& lt; br & gt;";           $ch = curl_init($url.'?'.$paramstring);<br> ​​​​$contents = curl_exec($ch);<br>          $title=$contents['title'];<br>          $content=[<br>              'title'=>$title,<br> ];<br> Return $ Content; <br>                                                                                                                                                                                               // curl_close($ch);<br>                 // print_r($content);<br>               // echo "<br>";<br> ​​​​//$result = json_decode($content,true);<br> <br> <br>               // if($result){<br>                                                                                                                                                  if ($result['error_code']=='0'){<br>                                                                                                                                                                                                                                                                                                                                                                         }else{<br> // echo $ result ['error_code']. ":". $ Result ['reaSon']; <br>                                                                                     //                   // }else{<br>            //                                                                                                                                                                                                                                                                                              .                                                                       //************************************************ ** <br> <br> }<br> }<br> <br><br><br><br> <br>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn