<?php
/*
http://un.jipinlantu.com/index/Joke/index
http://un.jipinlantu.com/index/Joke/zhihu_daily
http://un.jipinlantu.com/index/Joke/news?id=9726788
http://un.jipinlantu.com/index/Joke/new_comment?id=9726788
http://un.jipinlantu.com/index/Joke/get_address
http://un.jipinlantu.com/index/Joke/videoindex
http://un.jipinlantu.com/index/Joke/video_type?type=0&page=1;
http://un.jipinlantu.com/index/Joke/video_detail?vid=VBMJ132DL;
http://un.jipinlantu.com/index/Joke/playing_movie_list?start=0 ;
* @class 笑话段子
* @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;
class Joke
{
/**
* 正在上映电影列表
* @return mixed
*/
public function playing_movie_list(){
$start = (isset($_GET['start'])) ? intval($_GET ['start']) : 0;
$url="http://api.douban.com/v2/movie/in_theaters?start={$start}&count=9";
var_dump($url);die;
$res=$this->HttpGet($url);
return $res;
}
/**
* 电影详情
* @return mixed
*/
public function movie_info(){
$id = (isset($_GET['id'])) ? intval($_GET ['id']) : 6311303;
$url="http://api.douban.com/v2/movie/subject/{$id}";
$res=$this->HttpGet($url);
$arr = json_decode($res, true);
return json([
'msg' => 'success',
'code' => 1,
'data' => $arr
]);
}
/**
* 视频首页接口
*/
public function videoindex()
{
$res = $this->HttpGet("http://c.3g.163.com/nc/video/home/0-10.html");
$arr = json_decode($res, true);
return json([
'msg' => 'success',
'code' => 1,
'data' => $arr
]);
}
/**
*视频分类列表
*/
public function video_type($type = 0, $page = 10)
{
$type = (isset($_GET['type'])) ? intval($_GET ['type']) : 0;
$page = (isset($_GET['page'])) ? intval($_GET ['page']) : 10;
$news=array(
'news_type' => array(
//头条
0 => "T1348647909107",
//军事
1 => "T1348648141035",
//娱乐
2 => "T1348648517839",
//体育
3 => "T1348649079062",
//科技
4 => "T1348649580692",
//艺术
5 => "T1441074311424",
//教育
6 => "T1348654225495",
//要闻
7 =>"T1467284926140"
),
'video_type' => array(
//精品视频
0 => "VAP4BGTVD",
//搞笑视频
1 => "VAP4BFE3U",
//美女视频
2 => "VAP4BG6DL",
//体育视频
3 => "VBF8F2E94",
// 新闻现场
4 => "VAV3H6JSN"
)
);
$video_type = $news['video_type'][$type];
if (empty($video_type)) {
return json([
'msg' => '请填写正确的参数请求',
'code' => 0
]);
}
$url = "http://c.m.163.com/nc/video/list/" . $video_type . "/y/" . $page . "-10.html";
$res = $this->HttpGet($url);
$arr = json_decode($res, true);
return json([
'msg' => 'success',
'code' => 1,
'data' => $arr[$video_type]
]);
}
/**
* @param string $vid
* @return \think\response\Json
*/
public function video_detail($vid = "VEKKO9TJP")
{
$vid = $_GET['vid'];
if (empty($vid)) {
return json([
'msg' => '请填写正确的参数请求',
'code' => 0
]);
};
$url = "http://3g.163.com/touch/video/detail/" . $vid . ".html";
$res = $this->HttpGet($url);
$arr = json_decode($res, true);
return json([
'msg' => 'success',
'code' => 1,
'data' => $arr
]);
}
/**
* 获取城市天气预报
* @return bool|string
*/
public function get_weather()
{
$city=$_GET['city'];
if(empty($city)){
$city= $this->get_city();
}
$res = file_get_contents("http://api.map.baidu.com/telematics/v3/weather?location={$city}&output=json&ak=32da004455c52b48d84a3a484c0dbc99");
return json([
'msg' => 'success',
'code' => 1,
'data' => json_decode($res, true)
]);
}
protected function get_city(){
$getIp = getRemoteIPAddress();
$content = file_get_contents("http://api.map.baidu.com/location/ip?ak=enYCQ2yaIIjL8IZfYdA1gi6hK2eqqI2T&ip=120.237.113.106&coor=bd09ll");
$json = json_decode($content, true);
$place =urlencode($json['content']['address_detail']['city']);
return $place;
}
//获取IP地址
public function get_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);
$latitude_longitude=$json['content']['point']['y'].",".$json['content']['point']['x'];
$address = file_get_contents("http://api.map.baidu.com/geocoder/v2/?ak=enYCQ2yaIIjL8IZfYdA1gi6hK2eqqI2T&location={$latitude_longitude}&output=json&pois=0");
$arr= json_decode($address, true);
echo "你当前的位置:".$arr['result']['formatted_address'].$arr['result']['sematic_description']."<br>";
echo "你当前IP:".$getIp;
}
//获取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;
}
/**
* @title 笑话接口
* @param page 是 int 页数
* @return 返回数据实例
* @example 调用示例
* @method GET http://192.168.1.2/api/Joke/index?page=10
* @author xing <fbiufo@vip.qq.com>
*/
public function index($page = 10)
{
$page = (isset($_GET['page'])) ? intval($_GET ['page']) : 10;
$url = "http://3g.163.com/touch/jsonp/joke/chanListNews/T141931628472/2/{$page}-10.html?callback=data";
$res = $this->HttpGet($url);
$arr = json_decode(substr($res, 5, -1), true);
dump($arr);die;
// return json([
// 'msg' => 'success',
// 'code' => 1,
// 'data' => $arr['段子']
// ]);
}
/**
* 最新日报列表
* @return \think\response\Json
*/
public function zhihu_daily(){
$url="http://news-at.zhihu.com/api/4/news/latest";
$va=file_get_contents($url);
dump(json_decode($va, true));
}
/**
* 知乎日报文章详情
* @param string $id
* @return \think\response\Json
*/
public function news($id=""){
$id=intval($_GET ['id']);
if(empty($id)){
return json([
'msg' => '参数id不能为空',
'code' => 0,
]);
}
$url="http://news-at.zhihu.com/api/4"."/news/{$id}";
$va=file_get_contents($url);
dump(json_decode($va, true));
}
/**
* 知乎日报短评论
* @return \think\response\Json
*/
public function new_comment(){
$id=intval($_GET ['id']);
if(empty($id)){
return json([
'msg' => '参数id不能为空',
'code' => 0,
]);
}
$url="http://news-at.zhihu.com/api/4"."/story/{$id}/short-comments";
$va=file_get_contents($url);
dump(json_decode($va, true));
}
/*
*
* @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;
}
}
免费视频
猜你喜欢
转载自blog.csdn.net/wangzhae/article/details/108431786
今日推荐
周排行