返回列表 发帖
查看: 1487|回复: 1

【免费开源】利用云数据API接口,开发属于自己的采集器

22

主题

78

回帖

160

积分

应用开发者

智伍应用

贡献
1 点
金币
50 个
QQ
发表于 2022-8-23 12:29:21 | 显示全部楼层 |阅读模式

复制下面的代码,保存为一个php文件即可,可以把代码封装一下,变成自己的东西!
  1. <?php
  2. header("Content-type: text/html; charset=utf-8");
  3. function get_sign($dataArr) //计算签名验证的函数
  4. {
  5.         if(!is_array($dataArr))
  6.         {
  7.                 return 'no';

  8.         } else {

  9.                 ksort($dataArr, SORT_STRING);
  10.                 $string1 = '';
  11.                 foreach ($dataArr as $k => $v) {
  12.                         $v=urlencode($v);
  13.                         $string1 .= "{$k}={$v}&";
  14.                 }
  15.                 return strtoupper(md5($string1));
  16.         }
  17. }
  18. function get_json_data($dataUrl) // 根据接口地址,转换成具体列表内容,展示结果
  19. {
  20.         $nowTime=time();
  21.         $tokenStr=file_get_contents('./appid.txt'); // 读取保存的appid和对应的密钥
  22.         $tokenArr=explode('_ZW_',$tokenStr);
  23.         $appid=$tokenArr[0];
  24.         $appid_key=$tokenArr[1];
  25.         $dataJson=file_get_contents($dataUrl);       
  26.         $dataJson=trim($dataJson);
  27.         $dataNewsArr=json_decode($dataJson,true);
  28.         $result='<hr><h2>下面是结果内容</h2><hr><p><br></p>';
  29.         $result=$result.'<table border=1 cellpadding=12 style="width:100%;">';
  30.         $result=$result.'<tr><th>一键采集</th><th>标题</th><th>链接地址</th><th>发布时间</th></tr>';
  31.         foreach($dataNewsArr as $item)
  32.         {
  33.                 $signArr=array();
  34.                 $signArr['url']=urldecode($item['fromurl']);
  35.                 $signArr['appid']=$appid;
  36.                 $signArr['t']=$nowTime;
  37.                 $signArr['appsecret']=$appid_key; // 密钥仅用于计算签名,不要公开,私密
  38.                 $sign=get_sign($signArr);
  39.                 $result=$result.'<tr style="text-align:center">';
  40.                 $result=$result.'<td nowrap><a href="./sdk_demo.php?ac=content&url='.urlencode($item['fromurl']).'&appid='.$appid.'&t='.$nowTime.'&sign='.$sign.'"> 点击采集 </a></td>';
  41.                 $result=$result.'<td>'.$item['title'].'</td>';
  42.                 $result=$result.'<td><a href="'.$item['fromurl'].'" target="_blank">'.$item['fromurl'].'</a></td>';
  43.                 $result=$result.'<td nowrap>'.date('Y-m-d H:i:s',$item['sendtime']).'</td>';
  44.                 $result=$result.'</tr>';
  45.         }
  46.         $result=$result.'</table>';
  47.         return $result;
  48. }
  49. if(!empty($_GET['ac']) && $_GET['ac']=='register')
  50. {
  51.         if(!file_exists('./appid.txt'))
  52.         {               
  53.                 $appid=php_uname('s').php_uname('n').php_uname('m'); // 根据服务器的特征,生成唯一appid,请求获得密钥之后,保存到本地
  54.                 $appid=$appid.__DIR__;
  55.                 $appid=md5($appid);
  56.                 $appid_key=file_get_contents("http://api.zhiwu55.net/v1/catch_data/register/?appid=".$appid);
  57.                 $dataStr=$appid.'_ZW_'.$appid_key;
  58.                 file_put_contents('./appid.txt',$dataStr); //生产环境中,上线了,千万不要这样保存appid和密钥,相当于公开暴露出去了
  59.         }
  60.         $result='<hr><h2>下面是结果内容</h2><hr><p><br></p>注册appid成功!已经保存到appid.txt文件中';       
  61. }
  62. if(!empty($_GET['ac']) && $_GET['ac']=='content')
  63. {
  64.         $fromurl=urlencode($_GET['url']);
  65.         $dataUrl="http://api.zhiwu55.net/v1/catch_data/content/?url={$fromurl}&appid={$_GET['appid']}&t={$_GET['t']}&sign={$_GET['sign']}";
  66.         $content=file_get_contents($dataUrl);
  67.         if($content=='Requests are too frequent')
  68.         {
  69.                 $result='<h1>采集过于频繁!</h1>';
  70.                
  71.         } elseif(strlen($content)<50) {
  72.                
  73.                 $result='<h1>'.$content.'</h1>';
  74.                
  75.         } elseif(stripos($content,'__zhiwu55.com__')!==false) {
  76.                
  77.                
  78.                 $firstPost=substr($content,0,strpos($content,'__zhiwu55.com__'));       
  79.                 $comment=substr($content,strpos($content,'__zhiwu55.com__')+15);       
  80.                 $comment=str_replace('__zhiwu55.cn__','</li><li>',$comment);       
  81.                 $result='<hr><h2>下面是结果内容</h2><hr><p><br></p>'.$firstPost.'<br><br><strong>评论如下:</strong><br><br><li>'.$comment.'</li>';
  82.        
  83.         } else {
  84.                
  85.                 $result='<hr><h2>下面是结果内容</h2><hr><p><br></p>'.$content;
  86.                
  87.         }
  88. }
  89. if(!empty($_GET['ac']) && $_GET['ac']=='search_keyword' && !empty($_GET['keyword']))
  90. {
  91.         $tokenStr=file_get_contents('./appid.txt'); // 读取保存的appid和对应的密钥
  92.         $tokenArr=explode('_ZW_',$tokenStr);
  93.         $appid=$tokenArr[0];       
  94.         $dataUrl="http://api.zhiwu55.net/v1/catch_data/search/?appid={$appid}&keyword=".urlencode($_GET['keyword']);
  95.         $result=get_json_data($dataUrl);
  96. }       
  97. if(!empty($_GET['ac']) && $_GET['ac']=='hotnews')
  98. {
  99.         $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/hotnews_json.html');
  100. }
  101. if(!empty($_GET['ac']) && $_GET['ac']=='top_news')
  102. {
  103.         $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/updatenews_json.html');       
  104. }
  105. if(!empty($_GET['ac']) && $_GET['ac']=='toutiao')
  106. {
  107.         $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/toutiao.com_json.html');       
  108. }
  109. if(!empty($_GET['ac']) && $_GET['ac']=='thepaper')
  110. {
  111.         $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/thepaper.cn_json.html');       
  112. }
  113. if(!empty($_GET['ac']) && $_GET['ac']=='sohu')
  114. {
  115.         $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/sohu.com_json.html');       
  116. }
  117. if(!empty($_GET['ac']) && $_GET['ac']=='sina')
  118. {
  119.         $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/sina.com.cn_json.html');       
  120. }
  121. if(!empty($_GET['ac']) && $_GET['ac']=='qq')
  122. {
  123.         $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/qq.com_json.html');       
  124. }
  125. if(!empty($_GET['ac']) && $_GET['ac']=='myzaker')
  126. {
  127.         $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/myzaker.com_json.html');       
  128. }
  129. if(!empty($_GET['ac']) && $_GET['ac']=='guokr')
  130. {
  131.         $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/guokr.com_json.html');       
  132. }
  133. if(!empty($_GET['ac']) && $_GET['ac']=='163')
  134. {
  135.         $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/163.com_json.html');       
  136. }
  137. if(!empty($_GET['ac']) && $_GET['ac']=='keyword01')
  138. {
  139.         $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/E4BD93E882B2_json.html');       
  140. }
  141. if(!empty($_GET['ac']) && $_GET['ac']=='keyword02')
  142. {
  143.         $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/E8B4A2E7BB8F_json.html');       
  144. }
  145. if(!empty($_GET['ac']) && $_GET['ac']=='keyword03')
  146. {
  147.         $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/E6989FE5BAA7_json.html');       
  148. }
  149. if(!empty($_GET['ac']) && $_GET['ac']=='keyword04')
  150. {
  151.         $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/E59BBDE99985_json.html');       
  152. }
  153. if(!empty($_GET['ac']) && $_GET['ac']=='keyword05')
  154. {
  155.         $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/E5869BE4BA8B_json.html');       
  156. }
  157. if(!empty($_GET['ac']) && $_GET['ac']=='keyword06')
  158. {
  159.         $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/E5BDA9E7A5A8_json.html');       
  160. }
  161. if(!empty($_GET['ac']) && $_GET['ac']=='keyword07')
  162. {
  163.         $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/E7949FE6B4BB_json.html');       
  164. }
  165. ?>
  166. <!DOCTYPE html>
  167. <html>
  168. <head>
  169. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  170. <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0,viewport-fit=cover">
  171. </head>
  172. <body style="padding:16px;">
  173. <div style="margin-bottom:64px;line-height:32px;">
  174.         <a href="./sdk_demo.php?ac=register">【必须】注册appid</a>   
  175.         <a href="./sdk_demo.php?ac=hotnews">获取热搜榜单的内容</a>   
  176.         <a href="./sdk_demo.php?ac=top_news">获取最新内容</a>   
  177.         <a href="./sdk_demo.php?ac=toutiao">今日头条</a>   
  178.         <a href="./sdk_demo.php?ac=thepaper">澎拜新闻</a>   
  179.         <a href="./sdk_demo.php?ac=sohu">搜狐</a>   
  180.         <a href="./sdk_demo.php?ac=sina">新浪</a>   
  181.         <a href="./sdk_demo.php?ac=qq">腾讯网</a>   
  182.         <a href="./sdk_demo.php?ac=myzaker">ZAKER扎克</a>   
  183.         <a href="./sdk_demo.php?ac=guokr">果壳</a>   
  184.         <a href="./sdk_demo.php?ac=163">网易</a><br><br>
  185.         <a href="./sdk_demo.php?ac=keyword01">体育</a>   
  186.         <a href="./sdk_demo.php?ac=keyword02">财经</a>   
  187.         <a href="./sdk_demo.php?ac=keyword03">星座</a>   
  188.         <a href="./sdk_demo.php?ac=keyword04">国际</a>   
  189.         <a href="./sdk_demo.php?ac=keyword05">军事</a>   
  190.         <a href="./sdk_demo.php?ac=keyword06">彩票</a>   
  191.         <a href="./sdk_demo.php?ac=keyword07">生活</a><br><br>
  192.         <form action="./sdk_demo.php" method="GET">
  193.                 <input type="hidden" name="ac" value="search_keyword">
  194.                 请输入简短精准关键词:
  195.                 <input type="text" name="keyword" value="房地产" style="padding:4px;height:30px;line-height:30px;width:300px;">
  196.                   
  197.                 <input type="submit" value="确定采集" style="height:38px;">
  198.         </form>
  199. </div>

  200. <?php
  201. echo $result;
  202. /*********

  203. 接口所有的请求方式都是GET请求,即直接访问接口地址即可,简单、方便、快捷使用智伍云数据的API接口

  204. 注意事项:

  205. 1、请自行用接口,注册一个自己的appid和密钥,不要用公开泄露出去,因为同一个appid请求过于频繁,会禁止访问一段时间

  206. 2、所有的数据都有过期时间,获取到数据之后,请保存到自己的服务器,图片做好本地化存储

  207. 3、如果appid对应的密钥忘记了,或者密钥泄露出去,需要重置密钥,暂时只能联系智伍应用在线客服处理

  208. -----------------------------------------------------------------------------

  209. 接口地址:http://api.zhiwu55.net/v1/catch_data/register/

  210. 接口说明:注册一个访问智伍云数据的appid和密钥,获得拉取数据的权限,仅一个appid请求参数,其中appid为自定义32位的数字和字母的组合,注册成功之后,会返回32位的密钥,请把这个返回的密钥保存起来,为了安全10分钟过后,此接口不再显示注册appid的密钥

  211. 调用示例:http://api.zhiwu55.net/v1/catch_data/register/?appid=ZW3456789812X45678901234567890a1  返回密钥:OuHZ552V20hi5ie3HCKTtyez3HR5ukhc  再次提醒,请把返回的密钥保存起来,以备需要的时候使用。

  212. -----------------------------------------------------------------------------

  213. 接口地址:http://api.zhiwu55.net/v1/catch_data/search/

  214. 接口说明:根据特定的关键语,返回指定的内容,有二个参数,分别是appid和keyword,返回json数据格式,如果看上了近期的某一篇文章内容,可以直接把标题当作关键词来访问该接口

  215. 调用示例:http://api.zhiwu55.net/v1/catch_data/search/?appid=ZW3456789812X45678901234567890a1&keyword=%E6%90%9E%E7%AC%91

  216. -----------------------------------------------------------------------------


  217. 接口地址:http://api.zhiwu55.net/v1/catch_data/content/

  218. 接口说明:这里一个最重要的接口,调用稍微麻烦一点,根据链接地址,拉取对应的数据和图片,需要用注册appid的32位密钥签名验证,一共有4个参数,分别如下

  219. 第1个参数:url,链接地址,请用接口返回的fromurl数值
  220. 第2个参数:appid,即自己注册的appid
  221. 第3个参数:t,当前的时间戳,请确保自己服务器的时间是中国的标准时间
  222. 第4个参数:sign,根据参数计算出来的签名

  223. 下面是调用示例代码:

  224. function get_sign($dataArr) //计算签名验证的函数
  225. {
  226.         if(!is_array($dataArr))
  227.         {
  228.                 return 'no';

  229.         } else {

  230.                 ksort($dataArr, SORT_STRING);
  231.                 $string1 = '';
  232.                 foreach ($dataArr as $k => $v) {
  233.                         $v=urlencode($v);
  234.                         $string1 .= "{$k}={$v}&";
  235.                 }
  236.                 return strtoupper(md5($string1));
  237.         }
  238. }
  239. $mySignArr=array();
  240. $mySignArr['url']=urldecode($fromurl); //通过接口返回的fromurl链接地址
  241. $mySignArr['appid']='ZW3456789812X45678901234567890a1'; // 注册的appid
  242. $mySignArr['t']=time(); //当前时间戳
  243. $mySignArr['appsecret']='OuHZ552V20hi5ie3HCKTtyez3HR5ukhc'; // 密钥
  244. $mySignStr=get_sign($signArr); // 根据参数计算出来的签名
  245. $dataUrl="http://api.zhiwu55.net/v1/catch_data/content/?url={$fromurl}&appid=ZW3456789812X45678901234567890a1&t={$mySignArr['t']}&sign={$mySignStr}";
  246. echo file_get_contents($dataUrl);

  247. -----------------------------------------------------------------------------

  248. 接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/updatenews_json.html

  249. 接口说明:获取全网最新的内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容

  250. -----------------------------------------------------------------------------

  251. 接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/hotnews_json.html

  252. 接口说明:今日热搜榜单火爆全网的内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容

  253. -----------------------------------------------------------------------------

  254. 接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/toutiao.com_json.html

  255. 接口说明:今日头条最新内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容

  256. -----------------------------------------------------------------------------

  257. 接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/thepaper.cn_json.html

  258. 接口说明:澎拜新闻最新内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容

  259. -----------------------------------------------------------------------------

  260. 接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/sohu.com_json.html

  261. 接口说明:搜狐最新内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容

  262. -----------------------------------------------------------------------------

  263. 接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/sina.com.cn_json.html

  264. 接口说明:新浪最新内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容

  265. -----------------------------------------------------------------------------

  266. 接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/qq.com_json.html

  267. 接口说明:腾讯网最新内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容

  268. -----------------------------------------------------------------------------

  269. 接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/myzaker.com_json.html

  270. 接口说明:扎客新闻网最新内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容

  271. -----------------------------------------------------------------------------

  272. 接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/guokr.com_json.html

  273. 接口说明:果壳网最新内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容

  274. -----------------------------------------------------------------------------

  275. 接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/163.com_json.html

  276. 接口说明:网易最新内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容

  277. ********/
  278. ?>
  279. </body>
  280. </html>
复制代码


智伍应用官方网站:zhiwu55.com
回复

使用道具 举报

22

主题

78

回帖

160

积分

应用开发者

智伍应用

贡献
1 点
金币
50 个
QQ
 楼主| 发表于 2022-8-25 14:58:48 | 显示全部楼层
下面的这二个插件,都是用上面的API接口二次开发的,大家可以参考看一下。

【Discuz插件】众大云采集_v9.7.3.zip

320.82 KB, 下载次数: 57

众大云采集

【Discuz插件】智伍云采集_zhiwu55_v2.0.2.zip

105.58 KB, 下载次数: 60

智伍云采集

智伍应用官方网站:zhiwu55.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 关注公众号
  • 有偿服务微信
  • 有偿服务QQ

手机版|小黑屋|Discuz! 官方交流社区 ( 皖ICP备16010102号 |皖公网安备34010302002376号 )|网站地图|star

GMT+8, 2024-3-29 16:20 , Processed in 0.040184 second(s), 8 queries , Redis On.

Powered by Discuz! W1.0 Licensed

Cpoyright © 2001-2024 Discuz! Team.

关灯 快速发帖
有偿服务QQ
有偿服务微信
返回顶部
快速回复 返回顶部 返回列表