久久久久av_欧美日韩一区二区在线_国产精品三区四区_日韩中字在线

返回列表 發(fā)帖
查看: 3084|回復: 1

【免費開源】利用云數據API接口,開發(fā)屬于自己的采集器

24

主題

93

回帖

177

積分

應用開發(fā)者

智伍應用

貢獻
1 點
金幣
50 個
QQ
樓主
發(fā)表于 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>發(fā)布時間</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); //生產環(huán)境中,上線了,千萬不要這樣保存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對應的密鑰忘記了,或者密鑰泄露出去,需要重置密鑰,暫時只能聯(lián)系智伍應用在線客服處理

  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>
復制代碼


回復

使用道具 舉報

24

主題

93

回帖

177

積分

應用開發(fā)者

智伍應用

貢獻
1 點
金幣
50 個
QQ
沙發(fā)
 樓主| 發(fā)表于 2022-8-25 14:58:48 | 只看Ta
下面的這二個插件,都是用上面的API接口二次開發(fā)的,大家可以參考看一下。

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

320.82 KB, 下載次數: 117

眾大云采集

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

105.58 KB, 下載次數: 120

智伍云采集

回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

  • 關注公眾號
  • 有償服務微信
  • 有償服務QQ

手機版|小黑屋|Discuz! 官方交流社區(qū) ( 皖ICP備16010102號 |皖公網安備34010302002376號 )|網站地圖|star

GMT+8, 2025-9-18 15:30 , Processed in 0.078986 second(s), 32 queries .

Powered by Discuz! W1.0 Licensed

Copyright © 2001-2025 Discuz! Team.

關燈 在本版發(fā)帖
有償服務QQ
有償服務微信
返回頂部
快速回復 返回頂部 返回列表