作者 zhl

Merge remote-tracking branch 'origin/master' into zhl

@@ -332,17 +332,7 @@ class RelayInquiry extends Command @@ -332,17 +332,7 @@ class RelayInquiry extends Command
332 try { 332 try {
333 $res = false; 333 $res = false;
334 foreach ($ad_task as $task){ 334 foreach ($ad_task as $task){
335 - //需要多个ip访问的国家 随机2-5次访问,只有一次询盘  
336 - if (in_array($val->country_name, $this->multiple_ip_visit_country)) {  
337 - $times = mt_rand(2, 5); //随机次数  
338 - $inquiry_time = mt_rand(1, $times); //第几次询盘  
339 - $this->output('多次访问模拟:' . $times);  
340 - for ($i = 1; $i <= $times; $i++) {  
341 - $res += $this->relayDetail($task, $val, $inquiry_time == $i);  
342 - }  
343 - }else{  
344 - $res += $this->relayDetail($task, $val);  
345 - } 335 + $res += $this->relayDetail($task, $val);
346 $res += $this->relayShopDetail($task, $val); 336 $res += $this->relayShopDetail($task, $val);
347 $res += $this->relayFobDetail($task, $val); 337 $res += $this->relayFobDetail($task, $val);
348 } 338 }
@@ -405,7 +395,7 @@ class RelayInquiry extends Command @@ -405,7 +395,7 @@ class RelayInquiry extends Command
405 * @param $form 395 * @param $form
406 * @return bool 396 * @return bool
407 */ 397 */
408 - public function relayDetail($task, $form, $is_inquiry = true) 398 + public function relayDetail($task, $form)
409 { 399 {
410 $this->output('获取转发对象'); 400 $this->output('获取转发对象');
411 if(empty($task['target'] )){ 401 if(empty($task['target'] )){
@@ -441,62 +431,76 @@ class RelayInquiry extends Command @@ -441,62 +431,76 @@ class RelayInquiry extends Command
441 } 431 }
442 $this->logChannel()->info('随机域名', array_column($random_data, 'url')); 432 $this->logChannel()->info('随机域名', array_column($random_data, 'url'));
443 foreach ($random_data as $item) { 433 foreach ($random_data as $item) {
444 - //手机号过滤  
445 - $phone = $form->phone;  
446 - $filter_phone = $this->get_rand($this->filter_phone);  
447 - if($filter_phone == 0){  
448 - $phone = trim(str_replace("+", '', $phone));  
449 - }elseif($filter_phone == 1){  
450 - $phone = ''; 434 + $times = 1;
  435 + $inquiry_time = 1;
  436 +
  437 + //需要多个ip访问的国家 随机2-5次访问,只有一次询盘
  438 + if (in_array($form->country_name, $this->multiple_ip_visit_country)) {
  439 + $times = mt_rand(2, 5); //随机次数
  440 + $inquiry_time = mt_rand(1, $times); //第几次询盘
  441 + $this->output('多次访问模拟:' . $times);
451 } 442 }
  443 + for ($i = 1; $i <= $times; $i++) {
  444 + $is_inquiry = $inquiry_time == $i;
  445 + //手机号过滤
  446 + $phone = $form->phone;
  447 + $filter_phone = $this->get_rand($this->filter_phone);
  448 + if($filter_phone == 0){
  449 + $phone = trim(str_replace("+", '', $phone));
  450 + }elseif($filter_phone == 1){
  451 + $phone = '';
  452 + }
452 453
453 - // 推送站点  
454 - $domain = $item['url'];  
455 - $is_v6 = $item['is_v6'];  
456 - $re_website = 'https://' . $domain . '/';  
457 -  
458 - //urls  
459 - list($urls, $lang, $inquiry_product_url) = $this->getUrls($is_v6, $domain, $re_website, $form, $task);  
460 - if(!$urls){  
461 - continue;  
462 - }  
463 -  
464 - //ip  
465 - $ip_data = $this->getIpData($form->country_name);  
466 - $ip = $ip_data->ip;  
467 - $country_name = $ip_data->ip_area;  
468 -  
469 - //message  
470 - list($message, $message_id, $msg_lang) = $this->getMessage($task, $form->message, $domain, $inquiry_product_url);  
471 - $lang = $lang ?: $msg_lang; 454 + // 推送站点
  455 + $domain = $item['url'];
  456 + $is_v6 = $item['is_v6'];
  457 + $re_website = 'https://' . $domain . '/';
472 458
473 - $this->output('获取转发设备信息');  
474 - // 客户端 头信息 来源  
475 - $device_port = $form->email ? '1' : '2'; //1 pc 2移动端  
476 - $user_agent = $form->email ? Arr::random($this->pc_ua) : Arr::random($this->mobile_ua);  
477 - $referrer = $this->getReferer($country_name, $lang);  
478 - $this->output('写入数据'); 459 + //urls
  460 + list($urls, $lang, $inquiry_product_url) = $this->getUrls($is_v6, $domain, $re_website, $form, $task);
  461 + if(!$urls){
  462 + continue;
  463 + }
479 464
480 - $pre = 0;  
481 - $start_time = time();  
482 - $seconds = rand(300, 7200); // 开始时间 从5-2小时后开始  
483 - $exists = ReInquiryDetail::where('re_website', $domain)->where('email', $form->email)->first();  
484 - if($exists){  
485 - $this->output('转发站点邮件已存在');  
486 - continue;  
487 - }  
488 - // 写入推送详情  
489 - $re_detail = ReInquiryDetail::createInquiry($task['id'], $form->id, $domain, $country_name, $ip, $form->full_name, $form->email, $phone, $message, $message_id, $device_port,  
490 - $user_agent, $referrer, $urls, $is_v6, date('Y-m-d H:i:s', $start_time + $seconds));  
491 - foreach ($urls as $k=>$v){  
492 - $pre++;  
493 - $seconds += rand(5,60);  
494 - ReInquiryDetailLog::createInquiryLog($re_detail->id, ReInquiryDetailLog::TYPE_VISIT, $pre, $v, date('Y-m-d H:i:s', $start_time + $seconds));  
495 - // 最后一次访问询盘 加上询盘  
496 - if($is_inquiry && $k+1 >= count($urls)){  
497 - $seconds += rand(30,120); 465 + //ip
  466 + $ip_data = $this->getIpData($form->country_name);
  467 + $ip = $ip_data->ip;
  468 + $country_name = $ip_data->ip_area;
  469 +
  470 + //message
  471 + list($message, $message_id, $msg_lang) = $this->getMessage($task, $form->message, $domain, $inquiry_product_url);
  472 + $lang = $lang ?: $msg_lang;
  473 +
  474 + $this->output('获取转发设备信息');
  475 + // 客户端 头信息 来源
  476 + $device_port = $form->email ? '1' : '2'; //1 pc 2移动端
  477 + $user_agent = $form->email ? Arr::random($this->pc_ua) : Arr::random($this->mobile_ua);
  478 + $referrer = $this->getReferer($country_name, $lang);
  479 + $this->output('写入数据');
  480 +
  481 + $pre = 0;
  482 + $start_time = time();
  483 + $seconds = rand(300, 7200); // 开始时间 从5-2小时后开始
  484 + if($is_inquiry) {
  485 + $exists = ReInquiryDetail::where('re_website', $domain)->where('email', $form->email)->first();
  486 + if ($exists) {
  487 + $this->output('转发站点邮件已存在');
  488 + continue;
  489 + }
  490 + }
  491 + // 写入推送详情
  492 + $re_detail = ReInquiryDetail::createInquiry($task['id'], $form->id, $domain, $country_name, $ip, $form->full_name, $form->email, $phone, $message, $message_id, $device_port,
  493 + $user_agent, $referrer, $urls, $is_v6, date('Y-m-d H:i:s', $start_time + $seconds));
  494 + foreach ($urls as $k=>$v){
498 $pre++; 495 $pre++;
499 - ReInquiryDetailLog::createInquiryLog($re_detail->id, ReInquiryDetailLog::TYPE_INQUIRY, $pre, $v, date('Y-m-d H:i:s', $start_time + $seconds)); 496 + $seconds += rand(5,60);
  497 + ReInquiryDetailLog::createInquiryLog($re_detail->id, ReInquiryDetailLog::TYPE_VISIT, $pre, $v, date('Y-m-d H:i:s', $start_time + $seconds));
  498 + // 最后一次访问询盘 加上询盘
  499 + if($is_inquiry && $k+1 >= count($urls)){
  500 + $seconds += rand(30,120);
  501 + $pre++;
  502 + ReInquiryDetailLog::createInquiryLog($re_detail->id, ReInquiryDetailLog::TYPE_INQUIRY, $pre, $v, date('Y-m-d H:i:s', $start_time + $seconds));
  503 + }
500 } 504 }
501 } 505 }
502 } 506 }
@@ -601,16 +605,20 @@ class RelayInquiry extends Command @@ -601,16 +605,20 @@ class RelayInquiry extends Command
601 $form_message = $message; 605 $form_message = $message;
602 $message_id = 0; 606 $message_id = 0;
603 607
604 - // TODO 当原始询盘内容长度大于15个字符, 直接发送原始内容。 608 + // TODO 当原始询盘内容长度大于15个字符, 60%几率直接发送原始内容。
605 if (strlen($message) >= 15) { 609 if (strlen($message) >= 15) {
606 - //原内容非英语,转为对应语种  
607 - if (is_numeric($form_message)) { //数字会被识别为中文  
608 - $lang = 'en';  
609 - } else {  
610 - $translateSl = Translate::translateSl($form_message);  
611 - $lang = $translateSl['texts']['sl'] ?? 'en'; 610 + $not_use_probability = AiCommand::where('key', 'fb_inquiry_text')->value('not_use_probability');
  611 + $randomNumber = rand(0, 100);
  612 + if($randomNumber < $not_use_probability){
  613 + //原内容非英语,转为对应语种
  614 + if (is_numeric($form_message)) { //数字会被识别为中文
  615 + $lang = 'en';
  616 + } else {
  617 + $translateSl = Translate::translateSl($form_message);
  618 + $lang = $translateSl['texts']['sl'] ?? 'en';
  619 + }
  620 + return [$message, $message_id, $lang??''];
612 } 621 }
613 - return [$message, $message_id, $lang??''];  
614 } 622 }
615 623
616 //开启文案替换 624 //开启文案替换
@@ -41,9 +41,9 @@ class SyncSubmitTask extends Command @@ -41,9 +41,9 @@ class SyncSubmitTask extends Command
41 $time = time(); 41 $time = time();
42 42
43 43
44 - DB::enableQueryLog(); //启用查询日志  
45 - //清除之前的查询日志  
46 - DB::flushQueryLog(); 44 +// DB::enableQueryLog(); //启用查询日志
  45 +// //清除之前的查询日志
  46 +// DB::flushQueryLog();
47 47
48 $task_info = SyncSubmitTaskModel::find($task_id); 48 $task_info = SyncSubmitTaskModel::find($task_id);
49 if (empty($task_info) || $task_info->status !=3) { 49 if (empty($task_info) || $task_info->status !=3) {
@@ -56,7 +56,9 @@ class SyncSubmitTask extends Command @@ -56,7 +56,9 @@ class SyncSubmitTask extends Command
56 throw new \Exception('项目不存在'); 56 throw new \Exception('项目不存在');
57 } 57 }
58 $task_info->project_id = $project->id; 58 $task_info->project_id = $project->id;
  59 + $time2 = time();
59 SyncSubmitTaskService::handler($task_info); 60 SyncSubmitTaskService::handler($task_info);
  61 + $this->output('处理用时:' . (time() - $time2));
60 $task_info->status = 1; 62 $task_info->status = 1;
61 $task_info->save(); 63 $task_info->save();
62 64
@@ -85,10 +87,11 @@ class SyncSubmitTask extends Command @@ -85,10 +87,11 @@ class SyncSubmitTask extends Command
85 $use_time = time() - $time; 87 $use_time = time() - $time;
86 if($use_time > 1){ 88 if($use_time > 1){
87 //数据库查询 89 //数据库查询
88 - $this->output('任务用时:' .$use_time . ' | ' . json_encode(DB::getQueryLog(),JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); 90 + $this->output('任务用时:' .$use_time);
  91 +// $this->output('任务用时:' .$use_time . ' | ' . json_encode(DB::getQueryLog(),JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
89 } 92 }
90 //清除之前的查询日志 93 //清除之前的查询日志
91 - DB::flushQueryLog(); 94 +// DB::flushQueryLog();
92 } 95 }
93 } 96 }
94 97
@@ -65,10 +65,20 @@ class Gpt @@ -65,10 +65,20 @@ class Gpt
65 65
66 $time = time(); 66 $time = time();
67 try { 67 try {
68 - $result = Http::withHeaders($this->header)->withOptions(['verify' => false])->acceptJson()  
69 - ->withBody(json_encode($data, JSON_UNESCAPED_UNICODE), 'application/json')  
70 - ->post($url);  
71 - $json = $result->json(); 68 +// $result = Http::withHeaders($this->header)->withOptions(['verify' => false])->acceptJson()
  69 +// ->withBody(json_encode($data, JSON_UNESCAPED_UNICODE), 'application/json')
  70 +// ->post($url);
  71 +// $json = $result->json();
  72 +
  73 + $client = new \GuzzleHttp\Client();
  74 + $result = $client->request('POST', $url, [
  75 + 'proxy' => 'http://104.255.171.237:51395', // 代理服务器地址和端口号
  76 + 'headers' => $this->header,
  77 + 'json' => $data,
  78 + 'verify' => false,
  79 + ])->getBody()->getContents();
  80 + $json = json_decode($result, true);
  81 +
72 if (!isset($json['text']) || $json['code'] !==200) { 82 if (!isset($json['text']) || $json['code'] !==200) {
73 Log::error('openai_chat_qqs data:', $data); 83 Log::error('openai_chat_qqs data:', $data);
74 Log::error('openai_chat_qqs result:' . (time() - $time), $json === null ? ['null'] : $json); 84 Log::error('openai_chat_qqs result:' . (time() - $time), $json === null ? ['null'] : $json);
@@ -153,4 +153,16 @@ class DomainInfo extends Base @@ -153,4 +153,16 @@ class DomainInfo extends Base
153 $value = Arr::s2a($value); 153 $value = Arr::s2a($value);
154 return $value; 154 return $value;
155 } 155 }
  156 +
  157 + public static function getCacheInfoByProjectId($project_id){
  158 + $cache_key = 'DOMAIN_INFO_BY_PROJECT_ID_' . $project_id;
  159 + $data = Cache::get($cache_key);
  160 + if(!$data){
  161 + $data = DomainInfo::where('project_id', $project_id)->first();
  162 + if($data){
  163 + Cache::put($cache_key, $data, 3600);
  164 + }
  165 + }
  166 + return $data;
  167 + }
156 } 168 }
@@ -75,7 +75,7 @@ class SyncSubmitTaskService @@ -75,7 +75,7 @@ class SyncSubmitTaskService
75 } 75 }
76 76
77 //域名 过滤国家或ip 77 //域名 过滤国家或ip
78 - $domain_info = DomainInfo::where('project_id', $project['id'])->first(); 78 + $domain_info = DomainInfo::getCacheInfoByProjectId($project['id']);
79 if(!empty($domain_info['not_allow_country'])){ 79 if(!empty($domain_info['not_allow_country'])){
80 $not_allow_countries = CountryCode::whereIn('id', $domain_info['not_allow_country'])->pluck('c_name')->toArray(); 80 $not_allow_countries = CountryCode::whereIn('id', $domain_info['not_allow_country'])->pluck('c_name')->toArray();
81 if(in_array($data['country'], $not_allow_countries)){ 81 if(in_array($data['country'], $not_allow_countries)){