作者 lyh

GX生成白帽报表脚本

1 <?php 1 <?php
2 /** 2 /**
3 * @remark : 3 * @remark :
4 - * @name :GeoQuestionResult.php 4 + * @name :GeoQuestionRes.php
5 * @author :lyh 5 * @author :lyh
6 * @method :post 6 * @method :post
7 * @time :2025/7/3 15:13 7 * @time :2025/7/3 15:13
@@ -11,11 +11,13 @@ namespace App\Console\Commands\Geo; @@ -11,11 +11,13 @@ namespace App\Console\Commands\Geo;
11 11
12 use App\Models\Geo\GeoPlatform; 12 use App\Models\Geo\GeoPlatform;
13 use App\Models\Geo\GeoQuestion; 13 use App\Models\Geo\GeoQuestion;
  14 +use App\Models\Geo\GeoQuestionResult;
  15 +use App\Models\Project\Project;
14 use App\Services\Geo\GeoService; 16 use App\Services\Geo\GeoService;
15 use Illuminate\Console\Command; 17 use Illuminate\Console\Command;
16 use Illuminate\Support\Facades\Redis; 18 use Illuminate\Support\Facades\Redis;
17 19
18 -class GeoQuestionResult extends Command 20 +class GeoQuestionRes extends Command
19 { 21 {
20 /** 22 /**
21 * The name and signature of the console command. 23 * The name and signature of the console command.
@@ -36,10 +38,17 @@ class GeoQuestionResult extends Command @@ -36,10 +38,17 @@ class GeoQuestionResult extends Command
36 $task_id = $this->getTaskId(); 38 $task_id = $this->getTaskId();
37 $questionModel = new GeoQuestion();//问题 39 $questionModel = new GeoQuestion();//问题
38 $info = $questionModel->read(['id'=>$task_id]); 40 $info = $questionModel->read(['id'=>$task_id]);
  41 + //获取当前项目的执行频率
  42 + $projectModel = new Project();
  43 + $projectInfo = $projectModel->read(['id'=>$info['project_id']],['geo_status','geo_frequency']);
  44 + if($projectInfo['geo_status'] == 0){
  45 + $questionModel->edit(['status'=>0],['id'=>$task_id]);
  46 + continue;
  47 + }
39 $questionArr = $info['question']; 48 $questionArr = $info['question'];
40 if(empty($questionArr)){ 49 if(empty($questionArr)){
41 echo date('Y-m-d H:i:s').'当前任务不存在问题。'.PHP_EOL; 50 echo date('Y-m-d H:i:s').'当前任务不存在问题。'.PHP_EOL;
42 - $questionModel->edit(['status'=>2],['id'=>$task_id]); 51 + $questionModel->edit(['status'=>0],['id'=>$task_id]);
43 } 52 }
44 //获取平台信息 53 //获取平台信息
45 $platformModel = new GeoPlatform();//平台 54 $platformModel = new GeoPlatform();//平台
@@ -49,13 +58,74 @@ class GeoQuestionResult extends Command @@ -49,13 +58,74 @@ class GeoQuestionResult extends Command
49 continue; 58 continue;
50 } 59 }
51 $geoService = new GeoService(); 60 $geoService = new GeoService();
  61 + $keywordArr = $info['keywords'] ?? [];
  62 + $urlArr = $info['url'] ?? [];
  63 + $geoResultModel = new GeoQuestionResult();
52 foreach ($questionArr as $q_item){ 64 foreach ($questionArr as $q_item){
53 foreach ($platformArr as $p_item){ 65 foreach ($platformArr as $p_item){
54 - $data = $geoService->setWebSearchChatAction($q_item,$p_item);  
55 - dd($data); 66 + $keywords = [];//命中的关键词
  67 + $urls = [];//命中的网址
  68 + $result_data = $geoService->setWebSearchChatAction($q_item,$p_item);
  69 + if(isset($result_data) && $result_data['code'] == 200){
  70 + $keywords = $this->getKeywords($keywordArr,$result_data['text'] ?? []);
  71 + $urls = $this->getUrl($urlArr,$result_data['annotations'] ?? []);
  72 + }
  73 + //保存一条结果记录
  74 + $data = [
  75 + 'project_id'=>$info['project_id'],
  76 + 'question_id'=>$info['id'],
  77 + 'platform'=>$p_item,
  78 + 'question'=>$q_item,
  79 + 'keywords'=>json_encode($keywords ?? [],true),//命中的关键词
  80 + 'text'=>json_encode($result_data ?? [],true),
  81 + 'url'=>json_encode($urls ?? [],true),//命中的网址
  82 + ];
  83 + $geoResultModel->addReturnId($data);
  84 + }
  85 + }
  86 + //更新下次执行时间
  87 + $questionModel->edit(['current_time'=>date('Y-m-d'),'next_time'=>date('Y-m-d', strtotime(date('Y-m-d') . ' +5 days'))],['id'=>$info['id']]);
  88 + }
  89 + }
  90 +
  91 + /**
  92 + * @remark :获取命中的url
  93 + * @name :getUrl
  94 + * @author :lyh
  95 + * @method :post
  96 + * @time :2025/7/3 16:38
  97 + */
  98 + public function getUrl($urlArr = [],$result_annotations = []){
  99 + $url = [];
  100 + if(!empty($urlArr) && !empty($result_annotations)){
  101 + foreach ($urlArr as $u_item){
  102 + foreach ($result_annotations as $a_item){
  103 + if (str_contains($a_item['url_citation']['url'], $u_item)) {
  104 + $url[] = $u_item;
  105 + }
  106 + }
  107 + }
  108 + }
  109 + return $url;
  110 + }
  111 +
  112 + /**
  113 + * @remark :获取命中的关键词
  114 + * @name :getKeywords
  115 + * @author :lyh
  116 + * @method :post
  117 + * @time :2025/7/3 16:26
  118 + */
  119 + public function getKeywords($keywordArr = [],$result_text = []){
  120 + $keywords = [];
  121 + if(!empty($keywordArr) && !empty($result_text)){
  122 + foreach ($keywordArr as $k_item){
  123 + if (str_contains($result_text, $k_item)) {
  124 + $keywords[] = $k_item;
56 } 125 }
57 } 126 }
58 } 127 }
  128 + return $keywords;
59 } 129 }
60 130
61 /** 131 /**
@@ -33,6 +33,8 @@ class GeoLogic extends BaseLogic @@ -33,6 +33,8 @@ class GeoLogic extends BaseLogic
33 public function setGeoStatus(){ 33 public function setGeoStatus(){
34 $projectModel = new Project(); 34 $projectModel = new Project();
35 $data = $projectModel->edit(['geo_status'=>$this->param['geo_status'],'geo_frequency'=>$this->param['geo_frequency']],['id'=>$this->param['project_id']]); 35 $data = $projectModel->edit(['geo_status'=>$this->param['geo_status'],'geo_frequency'=>$this->param['geo_frequency']],['id'=>$this->param['project_id']]);
  36 + $questionModel = new GeoQuestion();
  37 + $questionModel->edit(['status'=>$this->param['geo_status']],['project_id'=>$this->param['project_id']]);
36 return $this->success($data); 38 return $this->success($data);
37 } 39 }
38 40
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :GeoQuestionRes.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2025/7/3 16:01
  8 + */
  9 +
  10 +namespace App\Models\Geo;
  11 +
  12 +use App\Models\Base;
  13 +
  14 +/**
  15 + * @remark :geo设置请求结果
  16 + * @name :GeoQuestionRes
  17 + * @author :lyh
  18 + * @method :post
  19 + * @time :2025/7/3 16:01
  20 + */
  21 +class GeoQuestionResult extends Base
  22 +{
  23 + protected $table = 'gl_geo_question_result';
  24 +}