作者 赵彬吉

fb inquiry

... ... @@ -338,7 +338,7 @@ class RelayInquiry extends Command
$re_website = 'https://' . $domain . '/';
//urls
list($urls, $lang) = $this->getUrls($is_v6, $domain, $re_website, $form, $task);
list($urls, $lang, $inquiry_product_url) = $this->getUrls($is_v6, $domain, $re_website, $form, $task);
if(!$urls){
continue;
}
... ... @@ -349,7 +349,7 @@ class RelayInquiry extends Command
$country_name = $ip_data->ip_area;
//message
list($message, $message_id, $msg_lang) = $this->getMessage($task, $form->message, $domain);
list($message, $message_id, $msg_lang) = $this->getMessage($task, $form->message, $domain, $inquiry_product_url);
$lang = $lang ?: $msg_lang;
$this->output('获取转发设备信息');
... ... @@ -406,6 +406,7 @@ class RelayInquiry extends Command
$ip_data = $this->getIpData($form->country_name);
$ip = $ip_data->ip;
$country_name = $ip_data->ip_area;
//message
list($message, $message_id, $lang) = $this->getMessage($task, $form->message, $domain);
... ... @@ -477,7 +478,7 @@ class RelayInquiry extends Command
return $ip_data;
}
public function getMessage($task, $message, $domain){
public function getMessage($task, $message, $domain, $inquiry_product_url = ''){
$this->output('转发内容');
$form_message = $message;
$message_id = 0;
... ... @@ -486,7 +487,7 @@ class RelayInquiry extends Command
//AI生成
$error = 0;
while ($error<3){
$message = $this->ai_send($task['ai_param'], $message);
$message = $this->ai_send($task['ai_param'], $message, $inquiry_product_url);
if(!$message){
$this->output('AI文案生成失败');
$error++;
... ... @@ -580,7 +581,13 @@ class RelayInquiry extends Command
$urls[] = Arr::random($inquiry_urls);
}
}
return [$urls, $lang];
//着陆页是否是产品页面或产品列表页
$inquiry_product_url = '';
if(in_array(Arr::last($urls), $product_url) || in_array(Arr::last($urls), $product_cate_url)){
$inquiry_product_url = Arr::last($urls);
}
return [$urls, $lang, $inquiry_product_url];
}
/**
* 获取待处理询盘表单
... ... @@ -693,7 +700,7 @@ class RelayInquiry extends Command
}
}
public function ai_send($ai_param, $incontent)
public function ai_send($ai_param, $incontent, $inquiry_product_url)
{
$ai_command = AiCommand::where('key', 'fb_inquiry_text')->value('ai');
if (!$ai_command) {
... ... @@ -707,6 +714,16 @@ class RelayInquiry extends Command
}else{
$language = Translate::getTls($lang);
}
//着陆页是否是产品页面或产品列表页
if($inquiry_product_url){
$title = Common::getUrlTitle($inquiry_product_url);
if($title){
$ai_command = str_replace('{mkeywords}', $title, $ai_command);
}
}
$ai_command = str_replace('{mkeywords}', Arr::random(explode("\r\n", $ai_param['mkeywords'])), $ai_command);
$ai_command = str_replace('{incontent}', Arr::random(explode("\r\n", $incontent)), $ai_command);
$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;
use App\Models\User\UserLogin as UserLoginModel;
use Illuminate\Encryption\Encrypter;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
/**
* @name:
... ... @@ -225,4 +226,24 @@ class Common
public static function deal_str($str){
return str_replace(['{','}','”','“','"'],'',$str);
}
/**
* 获取网页 title
* @param $url
* @author zbj
* @date 2024/12/31
*/
public static function getUrlTitle($url)
{
try {
$response = Http::withoutVerifying()->get($url);
$html = $response->body();
$dom = new \DOMDocument();
@$dom->loadHTML($html); // 加载 HTML
$title = $dom->getElementsByTagName('title')->item(0); // 获取 <title> 标签
return $title->nodeValue;
} catch (\Exception $e) {
return '';
}
}
}
... ...