企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
```powershell <?php /* * @Author: ecitlm * @Date: 2017-05-29 19:31:05 * @Last Modified by: ecitlm * @Last Modified time: 2017-05-30 18:04:42 */ namespace app\index\controller; use think\Loader; class News2 { /* http://un.jipinlantu.com/index/News2/banner http://un.jipinlantu.com/index/News2/new_list?type=0&page=0 http://un.jipinlantu.com/index/News2/new_detail?postid=FJNUSVLD00019B3E http://un.jipinlantu.com/index/News2/local_news?page=0&name=%E5%B1%B1%E4%B8%9C%E7%9C%81 http://un.jipinlantu.com/index/News2/wx_select?ps=10 */ /** * 新闻banner */ public function banner() { $url="http://c.m.163.com/nc/article/headline/list/0-10.html?from=toutiao&passport=&devId"; $res = $this->HttpGet($url); $arr = json_decode($res, true); return json($arr['list'][0]); } /** * * 新闻分类 */ public function new_list() { $type = (isset($_REQUEST['type'])) ? intval($_REQUEST['type']) : 0; $page = (isset($_REQUEST['page'])) ? intval($_REQUEST['page']) : 10; $data = [ 'page' => $page, 'type' =>$type, ]; $news_types = array( //头条 0 => "T1348647909107", //军事 1 => "T1348648141035", //娱乐 2 => "T1348648517839", //体育 3 => "T1348649079062", //科技 4 => "T1348649580692", //艺术 5 => "T1441074311424", //教育 6 => "T1348654225495", //要闻 7 =>"T1467284926140" ); $news_type = $news_types[$type]; if (empty($news_type)) { return json([ 'msg' => '请填写正确的请求参数', 'code' => 0 ]); } $url="http://c.m.163.com/nc/article/headline/{$news_type}/{$page}-10.html"; // var_dump($url);die; $res = $this->HttpGet($url); $arr = json_decode($res, true); return json([ 'msg' => 'success', 'code' => 1, 'data' => $arr[$news_type] ]); } /** * 新闻详情 * @param string $postid * @return \think\response\Json */ public function new_detail($postid = "CLJMJRRL000181KT") { $id = (isset($_GET['postid'])) ? $_GET ['postid'] : "CLJMJRRL000181KT"; $url="http://c.m.163.com/nc/article/{$id}/full.html"; $res = $this->HttpGet($url); $arr = json_decode($res, true); return json([ 'msg' => 'success', 'code' => 1, 'data' => $arr[$id] ]); } /** * 本地新闻 * @return \think\response\Json */ public function local_news() { $name = (isset($_GET['name'])) ?urlencode($_GET ['name']) : urlencode($this->get_ip_address()); $page = (isset($_GET['page'])) ? intval($_GET ['page']) : 0; $url="http://3g.163.com/touch/jsonp/article/local/{$name}/{$page}-10.html"; $res = $this->HttpGet($url); return json([ 'msg' => 'success', 'code' => 1, 'data' => $res ]); } /** *微信精选 * */ public function wx_select(){ $ps = (isset($_GET['ps'])) ? intval($_GET ['ps']) : 10; $jkAPikey="d046cd1f569ed13d951f0258902ef9b2"; $url="http://v.juhe.cn/weixin/query?key=d046cd1f569ed13d951f0258902ef9b2&ps=".$ps; $res=$this->HttpGet($url); dump(json_decode($res)); } /** * 获取IP地址 * @return string */ public function get_ip_address(){ $getIp = $this->getRemoteIPAddress(); $content = file_get_contents("http://api.map.baidu.com/location/ip?ak=enYCQ2yaIIjL8IZfYdA1gi6hK2eqqI2T&ip={$getIp}&coor=bd09ll"); $json = json_decode($content, true); $place=$json['content']['address_detail']['province']."_".$json['content']['address_detail']['city']; return $place; } //获取ip public function getRemoteIPAddress() { global $ip; if (getenv("HTTP_CLIENT_IP")) $ip = getenv("HTTP_CLIENT_IP"); else if(getenv("HTTP_X_FORWARDED_FOR")) $ip = getenv("HTTP_X_FORWARDED_FOR"); else if(getenv("REMOTE_ADDR")) $ip = getenv("REMOTE_ADDR"); else $ip = "Unknow"; return $ip; } /* * * @param unknown $url */ function HttpGet($url,$status=false){ // var_dump($url);die; $curl = curl_init (); curl_setopt ( $curl, CURLOPT_URL, $url); curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true ); curl_setopt ( $curl, CURLOPT_TIMEOUT,1000 ); curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36'); //curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4'); if($status){ curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept:application','X-Request:JSON','X-Requested-With:XMLHttpRequest')); } //如果用的协议是https则打开鞋面这个注释 curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, false ); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); $res = curl_exec ( $curl ); curl_close ( $curl ); return $res; } } ```