暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Baidushoulu.php 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * 易优CMS
  4. * ============================================================================
  5. * 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.eyoucms.com
  7. * ----------------------------------------------------------------------------
  8. * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
  9. * ============================================================================
  10. * Author: 小虎哥 <1105415366@qq.com>
  11. * Date: 2018-4-3
  12. */
  13. namespace app\plugins\controller;
  14. use think\Db;
  15. class Baidushoulu extends Base
  16. {
  17. /**
  18. * 构造方法
  19. */
  20. public function __construct(){
  21. parent::__construct();
  22. }
  23. /**
  24. * 收藏与取消
  25. * @return [type] [description]
  26. */
  27. public function ajax_domain()
  28. {
  29. $param = input('param.');
  30. error_reporting(0);
  31. header("Access-Control-Allow-Origin:*");
  32. header('Content-type: application/json');
  33. $domain = $param['domain'];
  34. if(!isset($domain) || empty($domain) || $domain==''){
  35. $data = array(
  36. "code" => false,
  37. "msg" => "未传入请求参数!"
  38. );
  39. echo json_encode($data,JSON_UNESCAPED_UNICODE);
  40. exit;
  41. }
  42. if(substr($domain, -1) == '/'){
  43. $domain = substr($domain,0,strlen($domain)-1);
  44. }
  45. $data = $this->checkBaidu($domain);
  46. echo json_encode($data,JSON_UNESCAPED_UNICODE);
  47. }
  48. public function checkBaidu($url){
  49. $header = array(
  50. "Host:www.baidu.com",
  51. "Content-Type:application/x-www-form-urlencoded",//post请求
  52. "Connection: keep-alive",
  53. "Referer:https://www.baidu.com",
  54. "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.162 Safari/537.36"
  55. );
  56. $url = 'https://www.baidu.com/s?ie=UTF-8&wd='.urlencode($url).'&usm=3&rsv_idx=2&rsv_page=1';
  57. $ch = curl_init();
  58. curl_setopt($ch, CURLOPT_URL, $url);
  59. curl_setopt ($ch, CURLOPT_HTTPHEADER, $header);
  60. curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
  61. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  62. $output = curl_exec($ch);
  63. curl_close($ch);
  64. if(strpos($output, '没有找到') || strpos($output, '很抱歉')){
  65. $data = array(
  66. "code" => 403,
  67. "msg" => "该域名暂时未被百度收录!"
  68. );
  69. }else{
  70. $number = $this->GetBetween($output,'<span class="nums_text">百度为您找到相关结果约','个</span>');
  71. if(empty($number) || $number == 0){
  72. $number = $this->GetBetween($output,'<b>找到相关结果数约','个</b></p>');
  73. if(empty($number) || $number == 0){
  74. $data = array(
  75. "code" => false,
  76. "msg" => "获取百度收录失败!"
  77. );
  78. return $data;
  79. }
  80. }
  81. $data = array(
  82. "code" => 200,
  83. "msg" => "该域名已被百度收录!",
  84. "number" => str_replace(',','',$number)
  85. );
  86. }
  87. return $data;
  88. }
  89. public function GetBetween($content,$start,$end){
  90. $r = explode($start, $content);
  91. if (isset($r[1])){
  92. $r = explode($end, $r[1]);
  93. return $r[0];
  94. }
  95. }
  96. }