作者 刘锟

update

... ... @@ -47,6 +47,27 @@ class PostInquiryForward extends Command
parent::__construct();
}
/**
* 芯片网站
* @var array
*/
protected $xp_websites = [
'www.shinecomponents.com',
'www.hk-allchips.com',
'www.xinjiada-ic.com',
'www.sic-components.com',
'www.chip1-vip.com',
'www.flash-turtle.com',
'www.xinteerchip.com',
'www.conevoelec.com'
];
/**
* 5.0询盘转发到自己站点的网站
* @var array
*/
protected $self_websites = [205570, 64532, 150535, 292114, 124579, 237114, 194809, 278184, 166223, 366238, 277923, 297045, 309218, 75191, 57616];
public function handle()
{
... ... @@ -129,21 +150,23 @@ class PostInquiryForward extends Command
'referrer_url' => $detail['referrer'],
'user_agent' => $detail['user_agent'],
];
$res = Http::withoutVerifying()->timeout(30)->post($website . 'api/traffic_visit/', $data)->json();
$url = $website . 'api/traffic_visit/';
$res = Http::withoutVerifying()->timeout(30)->post($url, $data)->json();
if (empty($res['status']) || $res['status'] != 200) {
$log->status = InquiryRelayDetailLog::STATUS_FAIL;
$log->remark = mb_substr($res['message'] ?? '', 0, 200);
$log->save();
Log::channel('inquiry_forward')->error('post_inquiry_forward visit error', [$res, $website . 'api/traffic_visit/', $data]);
Log::channel('inquiry_forward')->error('post_inquiry_forward visit error', [$res, $url, $data]);
return false;
}
Log::channel('inquiry_forward')->error('post_inquiry_forward visit success', [$res, $url, $data]);
} else {
//v4 v5分离项目 往测试链接推
$project_info = InquiryProject::select(['is_split', 'test_domain'])->where('domain', 'like', '%' . $detail['website'] . '%')->first();
if (!$project_info) {
$log->status = InquiryRelayDetailLog::STATUS_FAIL;
$log->remark = '获取域名对应项目失败';
$log->remark = '获取分离项目测试域名失败';
$log->save();
return false;
... ... @@ -161,16 +184,19 @@ class PostInquiryForward extends Command
'user_agent' => $detail['user_agent'],
"ip" => $detail['ip'],
];
$res = Http::get($website . 'wp-admin/admin-ajax.php', $data);
$url = $website . 'wp-admin/admin-ajax.php';
$res = Http::withoutVerifying()->timeout(30)->get($url, $data);
$status = $res->status();
if ($status != 200) {
$log->status = InquiryRelayDetailLog::STATUS_FAIL;
$log->remark = mb_substr($res->body() ?? '', 0, 200);
$log->save();
Log::channel('inquiry_forward')->error('post_inquiry_forward v4|v5 visit error', [$res->body(), $website . 'wp-admin/admin-ajax.php', $data]);
Log::channel('inquiry_forward')->error('post_inquiry_forward v4|v5 visit error', [$res->body(), $url, $data]);
return false;
}
Log::channel('inquiry_forward')->error('post_inquiry_forward v4|v5 visit success', [$res->body(), $url, $data]);
}
$log->status = InquiryRelayDetailLog::STATUS_SUCCESS;
$log->save();
... ... @@ -179,11 +205,17 @@ class PostInquiryForward extends Command
public function inquiry(InquiryRelayDetail $detail, InquiryRelayDetailLog $log)
{
// v6
if ($detail['is_v6']) {
$res = $this->v6Inquiry($detail, $log);
if (in_array($detail['website'], $this->xp_websites)) {
// 芯片网站
$res = $this->xpInquiry($detail, $log);
} else {
$res = $this->v5Inquiry($detail, $log);
if ($detail['is_v6']) {
// v6
$res = $this->v6Inquiry($detail, $log);
} else {
// v5
$res = $this->v5Inquiry($detail, $log);
}
}
if (!$res) {
... ... @@ -196,6 +228,47 @@ class PostInquiryForward extends Command
return true;
}
public function xpInquiry($detail, $log)
{
$data = [
'refer' => $log['url'],
'contact_name' => $detail['name'],
'email' => $detail['email'],
'tel' => $detail['phone'],
'ip' => $detail['ip'],
'remark' => $detail['message'],
'submit_time' => date('Y-m-d H:i:s', time() + 20),
];
$url = 'https://' . $detail['website'] . '/api/store/webmail?flag=opencart';
$post_data = json_encode($data);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.87 Safari/537.36');
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8', 'Content-Length: ' . strlen($post_data)));
$curl_response = curl_exec($curl);
curl_close($curl);
$res = json_decode($curl_response, true);
if (empty($res['code']) || $res['code'] != 200) {
$log->status = InquiryRelayDetailLog::STATUS_FAIL;
$log->remark = mb_substr($res['msg'] ?? '', 0, 200);
$log->save();
Log::channel('inquiry_forward')->error('post_inquiry_forward xp inquiry error', [$res, $url, $data]);
return false;
}
Log::channel('inquiry_forward')->error('post_inquiry_forward xp inquiry success', [$res, $url, $data]);
return false;
}
public function v6Inquiry($detail, $log)
{
$website = 'https://' . $detail['website'] . '/';
... ... @@ -211,45 +284,70 @@ class PostInquiryForward extends Command
} else {
$data['__amp_source_origin'] = trim($website, '/');
}
$res = Http::withoutVerifying()->timeout(30)->withHeaders(['User-Agent' => $detail['user_agent']])->post($website . 'api/inquiryQd?source=5', $data)->json();
$url = $website . 'api/inquiryQd?source=5';
$res = Http::withoutVerifying()->timeout(30)->withHeaders(['User-Agent' => $detail['user_agent']])->post($url, $data)->json();
if (empty($res['code']) || $res['code'] != 200) {
$log->status = InquiryRelayDetailLog::STATUS_FAIL;
$log->remark = mb_substr($res['message'] ?? '', 0, 200);
$log->save();
Log::channel('inquiry_forward')->error('post_inquiry_forward v6 inquiry error', [$res, $website . 'api/inquiryQd/', $data]);
Log::channel('inquiry_forward')->error('post_inquiry_forward v6 inquiry error', [$res, $url, $data]);
return false;
}
Log::channel('inquiry_forward')->error('post_inquiry_forward v6 inquiry success', [$res, $url, $data]);
return true;
}
public function v5Inquiry($detail, $log)
{
$data = [
'name' => $detail['name'],
'phone' => $detail['phone'],
'message' => $detail['message'],
'email' => $detail['email'],
'ip' => $detail['ip'],
'token' => md5($log['url'] . $detail['name'] . $detail['ip'] . date("Y-m-d")),
'refer' => $log['url'],
'submit_time' => date('Y-m-d H:i:s'),
'source' => 5,
];
$result = Http::withoutVerifying()->timeout(30)->post('https://www.globalso.site/api/external-interface/add/fa043f9cbec6b38f', $data);
$res['data'][0]['status'] = 'success';
//兼容接口返回格式
if (!empty($res['data'][0]['status'])) {
$res['data'][0]['code'] = $res['data'][0]['status'] == 'success' ? 200 : 400;
!empty($res['data'][0]['msg']) && $res['message'] = $res['data'][0]['msg'];
}
if (empty($res['data'][0]['code']) || !in_array($res['data'][0]['code'], [200, 300])) {
$log->status = InquiryRelayDetailLog::STATUS_FAIL;
$log->remark = mb_substr($res['message'] ?? '', 0, 200);
$log->save();
$project_id = InquiryProject::where('version', '<', 6)->where('domain', 'like', '%' . $detail['website'] . '%')->value('primary_id') ?? 0;
if (in_array($project_id, $this->self_websites)) {
//发送到自己站点项目
$data = [
'Name' => $detail['name'],
'Phone' => $detail['phone'],
'Message' => $detail['message'],
'Email' => $detail['email'],
'submit_ip' => $detail['ip'],
'refer' => $log['url'],
'submit_time' => date('Y-m-d H:i:s', time() + 60)
];
$url = 'https://' . $detail['website'] . '/wp-admin/admin-ajax.php?action=live_remort_receive';
$res = Http::withoutVerifying()->timeout(30)->withHeaders(['User-Agent' => $detail['user_agent']])->post($url, $data);
$status = $res->status();
if ($status != 200) {
$log->status = InquiryRelayDetailLog::STATUS_FAIL;
$log->remark = mb_substr($res->body() ?? '', 0, 200);
$log->save();
Log::channel('inquiry_forward')->error('post_inquiry_forward v4|v5 inquiry error', [$result->body(), 'https://www.globalso.site/api/external-interface/add/fa043f9cbec6b38f', $data]);
return false;
Log::channel('inquiry_forward')->error('post_inquiry_forward v4|v5 inquiry error', [$res->body(), $url, $data]);
return false;
}
Log::channel('inquiry_forward')->error('post_inquiry_forward v4|v5 inquiry success', [$res->body(), $url, $data]);
} else {
$data = [
'name' => $detail['name'],
'phone' => $detail['phone'],
'message' => $detail['message'],
'email' => $detail['email'],
'ip' => $detail['ip'],
'token' => md5($log['url'] . $detail['name'] . $detail['ip'] . date("Y-m-d")),
'refer' => $log['url'],
'submit_time' => date('Y-m-d H:i:s'),
'source' => 5,
];
$url = 'https://www.globalso.site/api/external-interface/add/fa043f9cbec6b38f';
$res = Http::withoutVerifying()->timeout(30)->withHeaders(['User-Agent' => $detail['user_agent']])->post($url, $data)->json();
if (empty($res['status']) || $res['status'] != 200) {
$log->status = InquiryRelayDetailLog::STATUS_FAIL;
$log->remark = mb_substr($res['message'] ?? '', 0, 200);
$log->save();
Log::channel('inquiry_forward')->error('post_inquiry_forward v4|v5 inquiry error', [$res, $url, $data]);
return false;
}
Log::channel('inquiry_forward')->error('post_inquiry_forward v4|v5 inquiry success', [$res, $url, $data]);
}
return true;
}
... ...
... ... @@ -153,6 +153,20 @@ class RelayInquiryForward extends Command
protected $otherzb = [700, 300]; //模拟访问来源占比 (非美国) google.com|google.其他后缀
/**
* 芯片网站
* @var array
*/
protected $xp_websites = [
'www.shinecomponents.com',
'www.hk-allchips.com',
'www.xinjiada-ic.com',
'www.sic-components.com',
'www.chip1-vip.com',
'www.flash-turtle.com',
'www.xinteerchip.com',
'www.conevoelec.com'
];
public function handle()
{
... ... @@ -207,9 +221,14 @@ class RelayInquiryForward extends Command
public function completeDetail($inquiry_detail)
{
//visit urls
$visit_urls = $this->getUrls($inquiry_detail['is_v6'], $inquiry_detail['website'], $inquiry_detail['email']);
$inquiry_url = json_decode($inquiry_detail['urls'], true);
$urls = array_merge($visit_urls, $inquiry_url);
if (in_array($inquiry_detail['website'], $this->xp_websites)) {
//芯片网站无需模拟访问,直接发送询盘
$urls = $inquiry_url;
} else {
$visit_urls = $this->getUrls($inquiry_detail['is_v6'], $inquiry_detail['website'], $inquiry_detail['email']);
$urls = array_merge($visit_urls, $inquiry_url);
}
//lang
if (is_numeric($inquiry_detail['message'])) { //数字会被识别为中文
... ...
... ... @@ -14,7 +14,6 @@ use App\Models\Inquiry\InquiryProjectRoute;
use App\Models\Inquiry\InquiryRelayDetail;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
/**
... ...
... ... @@ -185,6 +185,12 @@ return [
'level' => 'debug',
'days' => 14,
],
'inquiry_forward' => [
'driver' => 'daily',
'path' => storage_path('logs/inquiry_forward/laravel.log'),
'level' => 'debug',
'days' => 14,
],
],
//操作日志
'operator_log' =>[
... ...