|
复制下面的代码,保存为一个php文件即可,可以把代码封装一下,变成自己的东西!
- <?php
- header("Content-type: text/html; charset=utf-8");
- function get_sign($dataArr) //计算签名验证的函数
- {
- if(!is_array($dataArr))
- {
- return 'no';
- } else {
- ksort($dataArr, SORT_STRING);
- $string1 = '';
- foreach ($dataArr as $k => $v) {
- $v=urlencode($v);
- $string1 .= "{$k}={$v}&";
- }
- return strtoupper(md5($string1));
- }
- }
- function get_json_data($dataUrl) // 根据接口地址,转换成具体列表内容,展示结果
- {
- $nowTime=time();
- $tokenStr=file_get_contents('./appid.txt'); // 读取保存的appid和对应的密钥
- $tokenArr=explode('_ZW_',$tokenStr);
- $appid=$tokenArr[0];
- $appid_key=$tokenArr[1];
- $dataJson=file_get_contents($dataUrl);
- $dataJson=trim($dataJson);
- $dataNewsArr=json_decode($dataJson,true);
- $result='<hr><h2>下面是结果内容</h2><hr><p><br></p>';
- $result=$result.'<table border=1 cellpadding=12 style="width:100%;">';
- $result=$result.'<tr><th>一键采集</th><th>标题</th><th>链接地址</th><th>发布时间</th></tr>';
- foreach($dataNewsArr as $item)
- {
- $signArr=array();
- $signArr['url']=urldecode($item['fromurl']);
- $signArr['appid']=$appid;
- $signArr['t']=$nowTime;
- $signArr['appsecret']=$appid_key; // 密钥仅用于计算签名,不要公开,私密
- $sign=get_sign($signArr);
- $result=$result.'<tr style="text-align:center">';
- $result=$result.'<td nowrap><a href="./sdk_demo.php?ac=content&url='.urlencode($item['fromurl']).'&appid='.$appid.'&t='.$nowTime.'&sign='.$sign.'"> 点击采集 </a></td>';
- $result=$result.'<td>'.$item['title'].'</td>';
- $result=$result.'<td><a href="'.$item['fromurl'].'" target="_blank">'.$item['fromurl'].'</a></td>';
- $result=$result.'<td nowrap>'.date('Y-m-d H:i:s',$item['sendtime']).'</td>';
- $result=$result.'</tr>';
- }
- $result=$result.'</table>';
- return $result;
- }
- if(!empty($_GET['ac']) && $_GET['ac']=='register')
- {
- if(!file_exists('./appid.txt'))
- {
- $appid=php_uname('s').php_uname('n').php_uname('m'); // 根据服务器的特征,生成唯一appid,请求获得密钥之后,保存到本地
- $appid=$appid.__DIR__;
- $appid=md5($appid);
- $appid_key=file_get_contents("http://api.zhiwu55.net/v1/catch_data/register/?appid=".$appid);
- $dataStr=$appid.'_ZW_'.$appid_key;
- file_put_contents('./appid.txt',$dataStr); //生产环境中,上线了,千万不要这样保存appid和密钥,相当于公开暴露出去了
- }
- $result='<hr><h2>下面是结果内容</h2><hr><p><br></p>注册appid成功!已经保存到appid.txt文件中';
- }
- if(!empty($_GET['ac']) && $_GET['ac']=='content')
- {
- $fromurl=urlencode($_GET['url']);
- $dataUrl="http://api.zhiwu55.net/v1/catch_data/content/?url={$fromurl}&appid={$_GET['appid']}&t={$_GET['t']}&sign={$_GET['sign']}";
- $content=file_get_contents($dataUrl);
- if($content=='Requests are too frequent')
- {
- $result='<h1>采集过于频繁!</h1>';
-
- } elseif(strlen($content)<50) {
-
- $result='<h1>'.$content.'</h1>';
-
- } elseif(stripos($content,'__zhiwu55.com__')!==false) {
-
-
- $firstPost=substr($content,0,strpos($content,'__zhiwu55.com__'));
- $comment=substr($content,strpos($content,'__zhiwu55.com__')+15);
- $comment=str_replace('__zhiwu55.cn__','</li><li>',$comment);
- $result='<hr><h2>下面是结果内容</h2><hr><p><br></p>'.$firstPost.'<br><br><strong>评论如下:</strong><br><br><li>'.$comment.'</li>';
-
- } else {
-
- $result='<hr><h2>下面是结果内容</h2><hr><p><br></p>'.$content;
-
- }
- }
- if(!empty($_GET['ac']) && $_GET['ac']=='search_keyword' && !empty($_GET['keyword']))
- {
- $tokenStr=file_get_contents('./appid.txt'); // 读取保存的appid和对应的密钥
- $tokenArr=explode('_ZW_',$tokenStr);
- $appid=$tokenArr[0];
- $dataUrl="http://api.zhiwu55.net/v1/catch_data/search/?appid={$appid}&keyword=".urlencode($_GET['keyword']);
- $result=get_json_data($dataUrl);
- }
- if(!empty($_GET['ac']) && $_GET['ac']=='hotnews')
- {
- $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/hotnews_json.html');
- }
- if(!empty($_GET['ac']) && $_GET['ac']=='top_news')
- {
- $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/updatenews_json.html');
- }
- if(!empty($_GET['ac']) && $_GET['ac']=='toutiao')
- {
- $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/toutiao.com_json.html');
- }
- if(!empty($_GET['ac']) && $_GET['ac']=='thepaper')
- {
- $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/thepaper.cn_json.html');
- }
- if(!empty($_GET['ac']) && $_GET['ac']=='sohu')
- {
- $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/sohu.com_json.html');
- }
- if(!empty($_GET['ac']) && $_GET['ac']=='sina')
- {
- $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/sina.com.cn_json.html');
- }
- if(!empty($_GET['ac']) && $_GET['ac']=='qq')
- {
- $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/qq.com_json.html');
- }
- if(!empty($_GET['ac']) && $_GET['ac']=='myzaker')
- {
- $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/myzaker.com_json.html');
- }
- if(!empty($_GET['ac']) && $_GET['ac']=='guokr')
- {
- $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/guokr.com_json.html');
- }
- if(!empty($_GET['ac']) && $_GET['ac']=='163')
- {
- $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/163.com_json.html');
- }
- if(!empty($_GET['ac']) && $_GET['ac']=='keyword01')
- {
- $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/E4BD93E882B2_json.html');
- }
- if(!empty($_GET['ac']) && $_GET['ac']=='keyword02')
- {
- $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/E8B4A2E7BB8F_json.html');
- }
- if(!empty($_GET['ac']) && $_GET['ac']=='keyword03')
- {
- $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/E6989FE5BAA7_json.html');
- }
- if(!empty($_GET['ac']) && $_GET['ac']=='keyword04')
- {
- $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/E59BBDE99985_json.html');
- }
- if(!empty($_GET['ac']) && $_GET['ac']=='keyword05')
- {
- $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/E5869BE4BA8B_json.html');
- }
- if(!empty($_GET['ac']) && $_GET['ac']=='keyword06')
- {
- $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/E5BDA9E7A5A8_json.html');
- }
- if(!empty($_GET['ac']) && $_GET['ac']=='keyword07')
- {
- $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/E7949FE6B4BB_json.html');
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0,viewport-fit=cover">
- </head>
- <body style="padding:16px;">
- <div style="margin-bottom:64px;line-height:32px;">
- <a href="./sdk_demo.php?ac=register">【必须】注册appid</a>
- <a href="./sdk_demo.php?ac=hotnews">获取热搜榜单的内容</a>
- <a href="./sdk_demo.php?ac=top_news">获取最新内容</a>
- <a href="./sdk_demo.php?ac=toutiao">今日头条</a>
- <a href="./sdk_demo.php?ac=thepaper">澎拜新闻</a>
- <a href="./sdk_demo.php?ac=sohu">搜狐</a>
- <a href="./sdk_demo.php?ac=sina">新浪</a>
- <a href="./sdk_demo.php?ac=qq">腾讯网</a>
- <a href="./sdk_demo.php?ac=myzaker">ZAKER扎克</a>
- <a href="./sdk_demo.php?ac=guokr">果壳</a>
- <a href="./sdk_demo.php?ac=163">网易</a><br><br>
- <a href="./sdk_demo.php?ac=keyword01">体育</a>
- <a href="./sdk_demo.php?ac=keyword02">财经</a>
- <a href="./sdk_demo.php?ac=keyword03">星座</a>
- <a href="./sdk_demo.php?ac=keyword04">国际</a>
- <a href="./sdk_demo.php?ac=keyword05">军事</a>
- <a href="./sdk_demo.php?ac=keyword06">彩票</a>
- <a href="./sdk_demo.php?ac=keyword07">生活</a><br><br>
- <form action="./sdk_demo.php" method="GET">
- <input type="hidden" name="ac" value="search_keyword">
- 请输入简短精准关键词:
- <input type="text" name="keyword" value="房地产" style="padding:4px;height:30px;line-height:30px;width:300px;">
-
- <input type="submit" value="确定采集" style="height:38px;">
- </form>
- </div>
- <?php
- echo $result;
- /*********
- 接口所有的请求方式都是GET请求,即直接访问接口地址即可,简单、方便、快捷使用智伍云数据的API接口
- 注意事项:
- 1、请自行用接口,注册一个自己的appid和密钥,不要用公开泄露出去,因为同一个appid请求过于频繁,会禁止访问一段时间
- 2、所有的数据都有过期时间,获取到数据之后,请保存到自己的服务器,图片做好本地化存储
- 3、如果appid对应的密钥忘记了,或者密钥泄露出去,需要重置密钥,暂时只能联系智伍应用在线客服处理
- -----------------------------------------------------------------------------
- 接口地址:http://api.zhiwu55.net/v1/catch_data/register/
- 接口说明:注册一个访问智伍云数据的appid和密钥,获得拉取数据的权限,仅一个appid请求参数,其中appid为自定义32位的数字和字母的组合,注册成功之后,会返回32位的密钥,请把这个返回的密钥保存起来,为了安全10分钟过后,此接口不再显示注册appid的密钥
- 调用示例:http://api.zhiwu55.net/v1/catch_data/register/?appid=ZW3456789812X45678901234567890a1 返回密钥:OuHZ552V20hi5ie3HCKTtyez3HR5ukhc 再次提醒,请把返回的密钥保存起来,以备需要的时候使用。
- -----------------------------------------------------------------------------
- 接口地址:http://api.zhiwu55.net/v1/catch_data/search/
- 接口说明:根据特定的关键语,返回指定的内容,有二个参数,分别是appid和keyword,返回json数据格式,如果看上了近期的某一篇文章内容,可以直接把标题当作关键词来访问该接口
- 调用示例:http://api.zhiwu55.net/v1/catch_data/search/?appid=ZW3456789812X45678901234567890a1&keyword=%E6%90%9E%E7%AC%91
- -----------------------------------------------------------------------------
- 接口地址:http://api.zhiwu55.net/v1/catch_data/content/
- 接口说明:这里一个最重要的接口,调用稍微麻烦一点,根据链接地址,拉取对应的数据和图片,需要用注册appid的32位密钥签名验证,一共有4个参数,分别如下
- 第1个参数:url,链接地址,请用接口返回的fromurl数值
- 第2个参数:appid,即自己注册的appid
- 第3个参数:t,当前的时间戳,请确保自己服务器的时间是中国的标准时间
- 第4个参数:sign,根据参数计算出来的签名
- 下面是调用示例代码:
- function get_sign($dataArr) //计算签名验证的函数
- {
- if(!is_array($dataArr))
- {
- return 'no';
- } else {
- ksort($dataArr, SORT_STRING);
- $string1 = '';
- foreach ($dataArr as $k => $v) {
- $v=urlencode($v);
- $string1 .= "{$k}={$v}&";
- }
- return strtoupper(md5($string1));
- }
- }
- $mySignArr=array();
- $mySignArr['url']=urldecode($fromurl); //通过接口返回的fromurl链接地址
- $mySignArr['appid']='ZW3456789812X45678901234567890a1'; // 注册的appid
- $mySignArr['t']=time(); //当前时间戳
- $mySignArr['appsecret']='OuHZ552V20hi5ie3HCKTtyez3HR5ukhc'; // 密钥
- $mySignStr=get_sign($signArr); // 根据参数计算出来的签名
- $dataUrl="http://api.zhiwu55.net/v1/catch_data/content/?url={$fromurl}&appid=ZW3456789812X45678901234567890a1&t={$mySignArr['t']}&sign={$mySignStr}";
- echo file_get_contents($dataUrl);
- -----------------------------------------------------------------------------
- 接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/updatenews_json.html
- 接口说明:获取全网最新的内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容
- -----------------------------------------------------------------------------
- 接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/hotnews_json.html
- 接口说明:今日热搜榜单火爆全网的内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容
- -----------------------------------------------------------------------------
- 接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/toutiao.com_json.html
- 接口说明:今日头条最新内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容
- -----------------------------------------------------------------------------
- 接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/thepaper.cn_json.html
- 接口说明:澎拜新闻最新内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容
- -----------------------------------------------------------------------------
- 接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/sohu.com_json.html
- 接口说明:搜狐最新内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容
- -----------------------------------------------------------------------------
- 接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/sina.com.cn_json.html
- 接口说明:新浪最新内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容
- -----------------------------------------------------------------------------
- 接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/qq.com_json.html
- 接口说明:腾讯网最新内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容
- -----------------------------------------------------------------------------
- 接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/myzaker.com_json.html
- 接口说明:扎客新闻网最新内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容
- -----------------------------------------------------------------------------
- 接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/guokr.com_json.html
- 接口说明:果壳网最新内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容
- -----------------------------------------------------------------------------
- 接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/163.com_json.html
- 接口说明:网易最新内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容
- ********/
- ?>
- </body>
- </html>
复制代码
|
|