陈德本 7 vuotta sitten
vanhempi
sitoutus
2601845306
3 muutettua tiedostoa jossa 136 lisäystä ja 108 poistoa
  1. 130 0
      cli.php
  2. 3 1
      composer.json
  3. 3 107
      hintData.php

+ 130 - 0
cli.php

@@ -0,0 +1,130 @@
+<?php
+set_time_limit(0);
+require_once('vendor/autoload.php');
+
+use League\Flysystem\Plugin\ListFiles;
+use League\Flysystem\Plugin\ListPaths;
+use PhpOffice\PhpSpreadsheet\Spreadsheet;
+use PhpOffice\PhpSpreadsheet\Style\Alignment;
+use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
+
+
+error_reporting(0);
+
+
+$settings = [
+    'baseUri' => 'https://www.meitu.live:433/remote.php/webdav/',
+    'userName' => "wangyating",
+    'password' => "wyt4913402",
+    'authType'=>CURLAUTH_BASIC
+];
+$client = new Sabre\DAV\Client($settings);
+$adapter = new League\Flysystem\WebDAV\WebDAVAdapter($client,"/remote.php/webdav");
+$flysystem = new League\Flysystem\Filesystem($adapter);
+$flysystem->addPlugin(new ListFiles());
+$flysystem->addPlugin(new ListPaths());
+
+
+
+$wd = $argv[1];
+$deep = $argv[2] ?: 1;
+$keys = explode(",", $wd);
+$result = $response = [];
+baidu($keys);
+
+$spreadsheet = new Spreadsheet();
+$sheet = $spreadsheet->getActiveSheet();
+$sheet->setTitle("为你推荐-相关搜索词");
+$row = 1;
+$sheet->setCellValue("A" . $row, "序号");
+$sheet->setCellValue("B" . $row, "关键词");
+$sheet->setCellValue("C" . $row, "相关搜索词");
+$row++;
+foreach ($result as $key => $item) {
+    $sheet->setCellValue("A" . $row, $row - 1);
+    $sheet->setCellValue("B" . $row, $item['key']);
+    $sheet->setCellValue("C" . $row, $item['relatedWd']);
+    $row++;
+}
+$styleArray = [
+    'alignment' => [
+        'horizontal' => Alignment::HORIZONTAL_CENTER,
+        'vertical' => Alignment::VERTICAL_CENTER,
+    ],
+];
+$sheet->getColumnDimension("A")->setWidth(14);
+$sheet->getColumnDimension("B")->setWidth(25);
+$sheet->getColumnDimension("C")->setWidth(25);
+$sheet->getStyle("A1:C" . $row)->applyFromArray($styleArray);
+
+$writer = new Xlsx($spreadsheet);
+
+//$file_path = sprintf(sys_get_temp_dir() . "/%s-%s.xlsx", $wd, date("Y-m-d"));
+$file_path = tempnam(sys_get_temp_dir(), 'baidu');;
+$writer->save($file_path);
+$flysystem->put(sprintf("关键词/关键词拓展/百度/百度为您推荐/%s-%s.xlsx",$wd,date("YmdHis")), file_get_contents($file_path));
+$data=$flysystem->listFiles("关键词/关键词拓展/百度/百度为您推荐");
+//var_dump($data);
+$spreadsheet->disconnectWorksheets();
+
+
+function baidu($wds)
+{
+    global $deep;
+    for ($i = 0; $i < $deep; $i++) {
+        if (!isset($_wds)) {
+            $_wds = $wds;
+        }
+        $wds2 = [];
+        foreach ($_wds as $wd) {
+            $wds2 = array_merge($wds2, getRelatedKeywords($wd));
+        }
+        $_wds = $wds2;
+    }
+}
+
+function getRelatedKeywords($wd)
+{
+    global $response, $result;
+    $searchUrl = "http://www.baidu.com/s?ie=UTF-8&rn=20&wd=%s";
+
+    $url = sprintf($searchUrl, $wd);
+    $rules = [
+        'json' => ['.c-tools', 'data-tools'],
+    ];
+    $ql = (new QL\QueryList)->get($url);
+    $rt = $ql->rules($rules)->query()->getData();
+    $rt = json_decode(json_encode($rt), true);
+    $wds = [];
+    foreach ($rt as $item) {
+        $json = json_decode($item['json'], true);
+        $baiduUrl = substr($json['url'], 30);
+        if ($baiduUrl) {
+            $_url = "https://sp2.baidu.com/8LUYsjW91Qh3otqbppnN2DJv/link?url=%s&query=%s&cb=jQuery110206243498231922682_1558178381142&data_name=recommend_common_merger_online&format=json&t=%s";
+            $_url = sprintf($_url, $baiduUrl, $wd, time() . "000");
+            $data = @file_get_contents($_url);
+            $pat = "#1558178381142\((.*)\)#";
+            preg_match($pat, $data, $arr);
+            $data = json_decode($arr[1], true);
+            if ($data['data'][0]['hintData']) {
+                foreach ($data['data'][0]['hintData'] as $hintDatum) {
+                    if ($response[md5($item['wd'])]) {
+                        continue;
+                    }
+                    foreach ($hintDatum['linkInfo'] as $item) {
+                        $response[md5($item['wd'])] = $item['wd'];
+                        $result[] = ['key' => $wd, 'relatedWd' => $item['wd']];
+                        $wds[] = $item['wd'];
+                    }
+                    foreach ($hintDatum['linkInfo2'] as $item) {
+                        $response[md5($item['wd'])] = $item['wd'];
+                        $result[] = ['key' => $wd, 'relatedWd' => $item['wd']];
+                        $wds[] = $item['wd'];
+                    }
+                }
+            }
+//            print_r($data);die();
+        }
+    }
+    return $wds;
+}

+ 3 - 1
composer.json

@@ -4,6 +4,8 @@
         "league/oauth2-server": "^7.3",
         "jaeger/querylist": "^4.1",
         "phpoffice/phpspreadsheet": "^1.6",
-        "jaeger/querylist-rule-baidu": "^4.0"
+        "jaeger/querylist-rule-baidu": "^4.0",
+        "league/flysystem": "^1.0",
+        "league/flysystem-webdav": "^1.0"
     }
 }

+ 3 - 107
hintData.php

@@ -8,10 +8,6 @@ set_time_limit(0);
  */
 require_once('vendor/autoload.php');
 
-use PhpOffice\PhpSpreadsheet\Spreadsheet;
-use PhpOffice\PhpSpreadsheet\Style\Alignment;
-use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
-use QL\QueryList;
 
 //$ql = QueryList::get('https://www.baidu.com/s?wd=QueryList');
 //$titles = $ql->find('h3>a')->texts(); //获取搜索结果标题列表
@@ -79,116 +75,16 @@ if (!$wd) {
     </html>
     <?php
 } else {
-    error_reporting(0);
     $origin_str = [';', ';', ',', ',', ' ', "\r\n"];
     $des_str = [',', ',', ',', ',', ',', ','];
     $wd = str_replace($origin_str, $des_str, $wd);
-    $keys = explode(",", $wd);
     $deep=$_REQUEST['deep']?:1;
-    $result = $response = [];
-    baidu($keys);
-//    print_r($result);
-//    die();
-
-    $spreadsheet = new Spreadsheet();
-    $sheet = $spreadsheet->getActiveSheet();
-    $sheet->setTitle("为你推荐-相关搜索词");
-    $row = 1;
-    $sheet->setCellValue("A" . $row, "序号");
-    $sheet->setCellValue("B" . $row, "关键词");
-    $sheet->setCellValue("C" . $row, "相关搜索词");
-    $row++;
-    foreach ($result as $key => $item) {
-        $sheet->setCellValue("A" . $row, $row - 1);
-        $sheet->setCellValue("B" . $row, $item['key']);
-        $sheet->setCellValue("C" . $row, $item['relatedWd']);
-        $row++;
-    }
-    $styleArray = [
-        'alignment' => [
-            'horizontal' => Alignment::HORIZONTAL_CENTER,
-            'vertical' => Alignment::VERTICAL_CENTER,
-        ],
-    ];
-    $sheet->getColumnDimension("A")->setWidth(14);
-    $sheet->getColumnDimension("B")->setWidth(25);
-    $sheet->getColumnDimension("C")->setWidth(25);
-    $sheet->getStyle("A1:C" . $row)->applyFromArray($styleArray);
-
-    $writer = new Xlsx($spreadsheet);
-    header("Pragma: public");
-    header("Expires: 0");
-    header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
-    header("Content-Type:application/force-download");
-    header("Content-Type:application/vnd.ms-execl");
-    header("Content-Type:application/octet-stream");
-    header("Content-Type:application/download");
-    header('Content-Disposition:attachment;filename="为你推荐-相关搜索词.xlsx"');
-    header("Content-Transfer-Encoding:binary");
-    $writer->save('php://output');
-    $spreadsheet->disconnectWorksheets();
+    $cmd=sprintf("nohup /usr/local/php7.2/bin/php /home/wwwroot/wyt.phplife.net/cli.php %s %s > /home/wwwroot/wangyating.log &",$wd,$deep);
+    $str= shell_exec($cmd);
+    echo "任务提交成功!";
 //    echo "完成,总耗时".$second."秒";
 
 }
-function baidu($wds)
-{
-    global $deep;
-    for ($i = 0; $i < $deep; $i++) {
-        if (!isset($_wds)) {
-            $_wds = $wds;
-        }
-        $wds2 = [];
-        foreach ($_wds as $wd) {
-            $wds2 = array_merge($wds2, getRelatedKeywords($wd));
-        }
-        $_wds = $wds2;
-    }
-}
 
-function getRelatedKeywords($wd)
-{
-    global $response, $result;
-    $searchUrl = "http://www.baidu.com/s?ie=UTF-8&rn=20&wd=%s";
-
-    $url = sprintf($searchUrl, $wd);
-    $rules = [
-        'json' => ['.c-tools', 'data-tools'],
-    ];
-    $ql = (new QL\QueryList)->get($url);
-    $rt = $ql->rules($rules)->query()->getData();
-    $rt = json_decode(json_encode($rt), true);
-    $wds = [];
-    foreach ($rt as $item) {
-        $json = json_decode($item['json'], true);
-        $baiduUrl = substr($json['url'], 30);
-        if ($baiduUrl) {
-            $_url = "https://sp2.baidu.com/8LUYsjW91Qh3otqbppnN2DJv/link?url=%s&query=%s&cb=jQuery110206243498231922682_1558178381142&data_name=recommend_common_merger_online&format=json&t=%s";
-            $_url = sprintf($_url, $baiduUrl, $wd, time() . "000");
-            $data = @file_get_contents($_url);
-            $pat = "#1558178381142\((.*)\)#";
-            preg_match($pat, $data, $arr);
-            $data = json_decode($arr[1], true);
-            if ($data['data'][0]['hintData']) {
-                foreach ($data['data'][0]['hintData'] as $hintDatum) {
-                    if ($response[md5($item['wd'])]) {
-                        continue;
-                    }
-                    foreach ($hintDatum['linkInfo'] as $item) {
-                        $response[md5($item['wd'])] = $item['wd'];
-                        $result[] = ['key' => $wd, 'relatedWd' => $item['wd']];
-                        $wds[] = $item['wd'];
-                    }
-                    foreach ($hintDatum['linkInfo2'] as $item) {
-                        $response[md5($item['wd'])] = $item['wd'];
-                        $result[] = ['key' => $wd, 'relatedWd' => $item['wd']];
-                        $wds[] = $item['wd'];
-                    }
-                }
-            }
-//            print_r($data);die();
-        }
-    }
-    return $wds;
-}