作者 赵彬吉

fb inquiry

@@ -338,7 +338,7 @@ class RelayInquiry extends Command @@ -338,7 +338,7 @@ class RelayInquiry extends Command
338 $re_website = 'https://' . $domain . '/'; 338 $re_website = 'https://' . $domain . '/';
339 339
340 //urls 340 //urls
341 - list($urls, $lang) = $this->getUrls($is_v6, $domain, $re_website, $form, $task); 341 + list($urls, $lang, $inquiry_product_url) = $this->getUrls($is_v6, $domain, $re_website, $form, $task);
342 if(!$urls){ 342 if(!$urls){
343 continue; 343 continue;
344 } 344 }
@@ -349,7 +349,7 @@ class RelayInquiry extends Command @@ -349,7 +349,7 @@ class RelayInquiry extends Command
349 $country_name = $ip_data->ip_area; 349 $country_name = $ip_data->ip_area;
350 350
351 //message 351 //message
352 - list($message, $message_id, $msg_lang) = $this->getMessage($task, $form->message, $domain); 352 + list($message, $message_id, $msg_lang) = $this->getMessage($task, $form->message, $domain, $inquiry_product_url);
353 $lang = $lang ?: $msg_lang; 353 $lang = $lang ?: $msg_lang;
354 354
355 $this->output('获取转发设备信息'); 355 $this->output('获取转发设备信息');
@@ -406,6 +406,7 @@ class RelayInquiry extends Command @@ -406,6 +406,7 @@ class RelayInquiry extends Command
406 $ip_data = $this->getIpData($form->country_name); 406 $ip_data = $this->getIpData($form->country_name);
407 $ip = $ip_data->ip; 407 $ip = $ip_data->ip;
408 $country_name = $ip_data->ip_area; 408 $country_name = $ip_data->ip_area;
  409 +
409 //message 410 //message
410 list($message, $message_id, $lang) = $this->getMessage($task, $form->message, $domain); 411 list($message, $message_id, $lang) = $this->getMessage($task, $form->message, $domain);
411 412
@@ -477,7 +478,7 @@ class RelayInquiry extends Command @@ -477,7 +478,7 @@ class RelayInquiry extends Command
477 return $ip_data; 478 return $ip_data;
478 } 479 }
479 480
480 - public function getMessage($task, $message, $domain){ 481 + public function getMessage($task, $message, $domain, $inquiry_product_url = ''){
481 $this->output('转发内容'); 482 $this->output('转发内容');
482 $form_message = $message; 483 $form_message = $message;
483 $message_id = 0; 484 $message_id = 0;
@@ -486,7 +487,7 @@ class RelayInquiry extends Command @@ -486,7 +487,7 @@ class RelayInquiry extends Command
486 //AI生成 487 //AI生成
487 $error = 0; 488 $error = 0;
488 while ($error<3){ 489 while ($error<3){
489 - $message = $this->ai_send($task['ai_param'], $message); 490 + $message = $this->ai_send($task['ai_param'], $message, $inquiry_product_url);
490 if(!$message){ 491 if(!$message){
491 $this->output('AI文案生成失败'); 492 $this->output('AI文案生成失败');
492 $error++; 493 $error++;
@@ -580,7 +581,13 @@ class RelayInquiry extends Command @@ -580,7 +581,13 @@ class RelayInquiry extends Command
580 $urls[] = Arr::random($inquiry_urls); 581 $urls[] = Arr::random($inquiry_urls);
581 } 582 }
582 } 583 }
583 - return [$urls, $lang]; 584 + //着陆页是否是产品页面或产品列表页
  585 + $inquiry_product_url = '';
  586 + if(in_array(Arr::last($urls), $product_url) || in_array(Arr::last($urls), $product_cate_url)){
  587 + $inquiry_product_url = Arr::last($urls);
  588 + }
  589 +
  590 + return [$urls, $lang, $inquiry_product_url];
584 } 591 }
585 /** 592 /**
586 * 获取待处理询盘表单 593 * 获取待处理询盘表单
@@ -693,7 +700,7 @@ class RelayInquiry extends Command @@ -693,7 +700,7 @@ class RelayInquiry extends Command
693 } 700 }
694 } 701 }
695 702
696 - public function ai_send($ai_param, $incontent) 703 + public function ai_send($ai_param, $incontent, $inquiry_product_url)
697 { 704 {
698 $ai_command = AiCommand::where('key', 'fb_inquiry_text')->value('ai'); 705 $ai_command = AiCommand::where('key', 'fb_inquiry_text')->value('ai');
699 if (!$ai_command) { 706 if (!$ai_command) {
@@ -707,6 +714,16 @@ class RelayInquiry extends Command @@ -707,6 +714,16 @@ class RelayInquiry extends Command
707 }else{ 714 }else{
708 $language = Translate::getTls($lang); 715 $language = Translate::getTls($lang);
709 } 716 }
  717 +
  718 +
  719 +
  720 + //着陆页是否是产品页面或产品列表页
  721 + if($inquiry_product_url){
  722 + $title = Common::getUrlTitle($inquiry_product_url);
  723 + if($title){
  724 + $ai_command = str_replace('{mkeywords}', $title, $ai_command);
  725 + }
  726 + }
710 $ai_command = str_replace('{mkeywords}', Arr::random(explode("\r\n", $ai_param['mkeywords'])), $ai_command); 727 $ai_command = str_replace('{mkeywords}', Arr::random(explode("\r\n", $ai_param['mkeywords'])), $ai_command);
711 $ai_command = str_replace('{incontent}', Arr::random(explode("\r\n", $incontent)), $ai_command); 728 $ai_command = str_replace('{incontent}', Arr::random(explode("\r\n", $incontent)), $ai_command);
712 $ai_command = str_replace('{characters}', Arr::random(explode("\r\n", $ai_param['characters'])), $ai_command); 729 $ai_command = str_replace('{characters}', Arr::random(explode("\r\n", $ai_param['characters'])), $ai_command);
@@ -8,6 +8,7 @@ use App\Models\User\UserLog as UserLogModel; @@ -8,6 +8,7 @@ use App\Models\User\UserLog as UserLogModel;
8 use App\Models\User\UserLogin as UserLoginModel; 8 use App\Models\User\UserLogin as UserLoginModel;
9 use Illuminate\Encryption\Encrypter; 9 use Illuminate\Encryption\Encrypter;
10 use Illuminate\Support\Facades\Cache; 10 use Illuminate\Support\Facades\Cache;
  11 +use Illuminate\Support\Facades\Http;
11 12
12 /** 13 /**
13 * @name: 14 * @name:
@@ -225,4 +226,24 @@ class Common @@ -225,4 +226,24 @@ class Common
225 public static function deal_str($str){ 226 public static function deal_str($str){
226 return str_replace(['{','}','”','“','"'],'',$str); 227 return str_replace(['{','}','”','“','"'],'',$str);
227 } 228 }
  229 +
  230 + /**
  231 + * 获取网页 title
  232 + * @param $url
  233 + * @author zbj
  234 + * @date 2024/12/31
  235 + */
  236 + public static function getUrlTitle($url)
  237 + {
  238 + try {
  239 + $response = Http::withoutVerifying()->get($url);
  240 + $html = $response->body();
  241 + $dom = new \DOMDocument();
  242 + @$dom->loadHTML($html); // 加载 HTML
  243 + $title = $dom->getElementsByTagName('title')->item(0); // 获取 <title> 标签
  244 + return $title->nodeValue;
  245 + } catch (\Exception $e) {
  246 + return '';
  247 + }
  248 + }
228 } 249 }