作者 刘锟

update

@@ -47,6 +47,27 @@ class PostInquiryForward extends Command @@ -47,6 +47,27 @@ class PostInquiryForward extends Command
47 parent::__construct(); 47 parent::__construct();
48 } 48 }
49 49
  50 + /**
  51 + * 芯片网站
  52 + * @var array
  53 + */
  54 + protected $xp_websites = [
  55 + 'www.shinecomponents.com',
  56 + 'www.hk-allchips.com',
  57 + 'www.xinjiada-ic.com',
  58 + 'www.sic-components.com',
  59 + 'www.chip1-vip.com',
  60 + 'www.flash-turtle.com',
  61 + 'www.xinteerchip.com',
  62 + 'www.conevoelec.com'
  63 + ];
  64 +
  65 + /**
  66 + * 5.0询盘转发到自己站点的网站
  67 + * @var array
  68 + */
  69 + protected $self_websites = [205570, 64532, 150535, 292114, 124579, 237114, 194809, 278184, 166223, 366238, 277923, 297045, 309218, 75191, 57616];
  70 +
50 71
51 public function handle() 72 public function handle()
52 { 73 {
@@ -129,21 +150,23 @@ class PostInquiryForward extends Command @@ -129,21 +150,23 @@ class PostInquiryForward extends Command
129 'referrer_url' => $detail['referrer'], 150 'referrer_url' => $detail['referrer'],
130 'user_agent' => $detail['user_agent'], 151 'user_agent' => $detail['user_agent'],
131 ]; 152 ];
132 - $res = Http::withoutVerifying()->timeout(30)->post($website . 'api/traffic_visit/', $data)->json(); 153 + $url = $website . 'api/traffic_visit/';
  154 + $res = Http::withoutVerifying()->timeout(30)->post($url, $data)->json();
133 if (empty($res['status']) || $res['status'] != 200) { 155 if (empty($res['status']) || $res['status'] != 200) {
134 $log->status = InquiryRelayDetailLog::STATUS_FAIL; 156 $log->status = InquiryRelayDetailLog::STATUS_FAIL;
135 $log->remark = mb_substr($res['message'] ?? '', 0, 200); 157 $log->remark = mb_substr($res['message'] ?? '', 0, 200);
136 $log->save(); 158 $log->save();
137 159
138 - Log::channel('inquiry_forward')->error('post_inquiry_forward visit error', [$res, $website . 'api/traffic_visit/', $data]); 160 + Log::channel('inquiry_forward')->error('post_inquiry_forward visit error', [$res, $url, $data]);
139 return false; 161 return false;
140 } 162 }
  163 + Log::channel('inquiry_forward')->error('post_inquiry_forward visit success', [$res, $url, $data]);
141 } else { 164 } else {
142 //v4 v5分离项目 往测试链接推 165 //v4 v5分离项目 往测试链接推
143 $project_info = InquiryProject::select(['is_split', 'test_domain'])->where('domain', 'like', '%' . $detail['website'] . '%')->first(); 166 $project_info = InquiryProject::select(['is_split', 'test_domain'])->where('domain', 'like', '%' . $detail['website'] . '%')->first();
144 if (!$project_info) { 167 if (!$project_info) {
145 $log->status = InquiryRelayDetailLog::STATUS_FAIL; 168 $log->status = InquiryRelayDetailLog::STATUS_FAIL;
146 - $log->remark = '获取域名对应项目失败'; 169 + $log->remark = '获取分离项目测试域名失败';
147 $log->save(); 170 $log->save();
148 171
149 return false; 172 return false;
@@ -161,16 +184,19 @@ class PostInquiryForward extends Command @@ -161,16 +184,19 @@ class PostInquiryForward extends Command
161 'user_agent' => $detail['user_agent'], 184 'user_agent' => $detail['user_agent'],
162 "ip" => $detail['ip'], 185 "ip" => $detail['ip'],
163 ]; 186 ];
164 - $res = Http::get($website . 'wp-admin/admin-ajax.php', $data); 187 + $url = $website . 'wp-admin/admin-ajax.php';
  188 + $res = Http::withoutVerifying()->timeout(30)->get($url, $data);
165 $status = $res->status(); 189 $status = $res->status();
166 if ($status != 200) { 190 if ($status != 200) {
167 $log->status = InquiryRelayDetailLog::STATUS_FAIL; 191 $log->status = InquiryRelayDetailLog::STATUS_FAIL;
168 $log->remark = mb_substr($res->body() ?? '', 0, 200); 192 $log->remark = mb_substr($res->body() ?? '', 0, 200);
169 $log->save(); 193 $log->save();
170 194
171 - Log::channel('inquiry_forward')->error('post_inquiry_forward v4|v5 visit error', [$res->body(), $website . 'wp-admin/admin-ajax.php', $data]); 195 + Log::channel('inquiry_forward')->error('post_inquiry_forward v4|v5 visit error', [$res->body(), $url, $data]);
172 return false; 196 return false;
173 } 197 }
  198 +
  199 + Log::channel('inquiry_forward')->error('post_inquiry_forward v4|v5 visit success', [$res->body(), $url, $data]);
174 } 200 }
175 $log->status = InquiryRelayDetailLog::STATUS_SUCCESS; 201 $log->status = InquiryRelayDetailLog::STATUS_SUCCESS;
176 $log->save(); 202 $log->save();
@@ -179,11 +205,17 @@ class PostInquiryForward extends Command @@ -179,11 +205,17 @@ class PostInquiryForward extends Command
179 205
180 public function inquiry(InquiryRelayDetail $detail, InquiryRelayDetailLog $log) 206 public function inquiry(InquiryRelayDetail $detail, InquiryRelayDetailLog $log)
181 { 207 {
182 - // v6  
183 - if ($detail['is_v6']) {  
184 - $res = $this->v6Inquiry($detail, $log); 208 + if (in_array($detail['website'], $this->xp_websites)) {
  209 + // 芯片网站
  210 + $res = $this->xpInquiry($detail, $log);
185 } else { 211 } else {
186 - $res = $this->v5Inquiry($detail, $log); 212 + if ($detail['is_v6']) {
  213 + // v6
  214 + $res = $this->v6Inquiry($detail, $log);
  215 + } else {
  216 + // v5
  217 + $res = $this->v5Inquiry($detail, $log);
  218 + }
187 } 219 }
188 220
189 if (!$res) { 221 if (!$res) {
@@ -196,6 +228,47 @@ class PostInquiryForward extends Command @@ -196,6 +228,47 @@ class PostInquiryForward extends Command
196 return true; 228 return true;
197 } 229 }
198 230
  231 + public function xpInquiry($detail, $log)
  232 + {
  233 + $data = [
  234 + 'refer' => $log['url'],
  235 + 'contact_name' => $detail['name'],
  236 + 'email' => $detail['email'],
  237 + 'tel' => $detail['phone'],
  238 + 'ip' => $detail['ip'],
  239 + 'remark' => $detail['message'],
  240 + 'submit_time' => date('Y-m-d H:i:s', time() + 20),
  241 + ];
  242 + $url = 'https://' . $detail['website'] . '/api/store/webmail?flag=opencart';
  243 + $post_data = json_encode($data);
  244 + $curl = curl_init($url);
  245 + curl_setopt($curl, CURLOPT_POST, 1);
  246 + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  247 + curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
  248 + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
  249 + curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
  250 + 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');
  251 + curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
  252 + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
  253 + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  254 + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
  255 + curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8', 'Content-Length: ' . strlen($post_data)));
  256 + $curl_response = curl_exec($curl);
  257 + curl_close($curl);
  258 +
  259 + $res = json_decode($curl_response, true);
  260 + if (empty($res['code']) || $res['code'] != 200) {
  261 + $log->status = InquiryRelayDetailLog::STATUS_FAIL;
  262 + $log->remark = mb_substr($res['msg'] ?? '', 0, 200);
  263 + $log->save();
  264 + Log::channel('inquiry_forward')->error('post_inquiry_forward xp inquiry error', [$res, $url, $data]);
  265 + return false;
  266 + }
  267 + Log::channel('inquiry_forward')->error('post_inquiry_forward xp inquiry success', [$res, $url, $data]);
  268 +
  269 + return false;
  270 + }
  271 +
199 public function v6Inquiry($detail, $log) 272 public function v6Inquiry($detail, $log)
200 { 273 {
201 $website = 'https://' . $detail['website'] . '/'; 274 $website = 'https://' . $detail['website'] . '/';
@@ -211,45 +284,70 @@ class PostInquiryForward extends Command @@ -211,45 +284,70 @@ class PostInquiryForward extends Command
211 } else { 284 } else {
212 $data['__amp_source_origin'] = trim($website, '/'); 285 $data['__amp_source_origin'] = trim($website, '/');
213 } 286 }
214 - $res = Http::withoutVerifying()->timeout(30)->withHeaders(['User-Agent' => $detail['user_agent']])->post($website . 'api/inquiryQd?source=5', $data)->json(); 287 + $url = $website . 'api/inquiryQd?source=5';
  288 + $res = Http::withoutVerifying()->timeout(30)->withHeaders(['User-Agent' => $detail['user_agent']])->post($url, $data)->json();
215 if (empty($res['code']) || $res['code'] != 200) { 289 if (empty($res['code']) || $res['code'] != 200) {
216 $log->status = InquiryRelayDetailLog::STATUS_FAIL; 290 $log->status = InquiryRelayDetailLog::STATUS_FAIL;
217 $log->remark = mb_substr($res['message'] ?? '', 0, 200); 291 $log->remark = mb_substr($res['message'] ?? '', 0, 200);
218 $log->save(); 292 $log->save();
219 - Log::channel('inquiry_forward')->error('post_inquiry_forward v6 inquiry error', [$res, $website . 'api/inquiryQd/', $data]); 293 + Log::channel('inquiry_forward')->error('post_inquiry_forward v6 inquiry error', [$res, $url, $data]);
220 return false; 294 return false;
221 } 295 }
  296 + Log::channel('inquiry_forward')->error('post_inquiry_forward v6 inquiry success', [$res, $url, $data]);
222 return true; 297 return true;
223 } 298 }
224 299
225 public function v5Inquiry($detail, $log) 300 public function v5Inquiry($detail, $log)
226 { 301 {
227 - $data = [  
228 - 'name' => $detail['name'],  
229 - 'phone' => $detail['phone'],  
230 - 'message' => $detail['message'],  
231 - 'email' => $detail['email'],  
232 - 'ip' => $detail['ip'],  
233 - 'token' => md5($log['url'] . $detail['name'] . $detail['ip'] . date("Y-m-d")),  
234 - 'refer' => $log['url'],  
235 - 'submit_time' => date('Y-m-d H:i:s'),  
236 - 'source' => 5,  
237 - ];  
238 - $result = Http::withoutVerifying()->timeout(30)->post('https://www.globalso.site/api/external-interface/add/fa043f9cbec6b38f', $data);  
239 - $res['data'][0]['status'] = 'success';  
240 - //兼容接口返回格式  
241 - if (!empty($res['data'][0]['status'])) {  
242 - $res['data'][0]['code'] = $res['data'][0]['status'] == 'success' ? 200 : 400;  
243 - !empty($res['data'][0]['msg']) && $res['message'] = $res['data'][0]['msg'];  
244 - }  
245 - if (empty($res['data'][0]['code']) || !in_array($res['data'][0]['code'], [200, 300])) {  
246 - $log->status = InquiryRelayDetailLog::STATUS_FAIL;  
247 - $log->remark = mb_substr($res['message'] ?? '', 0, 200);  
248 - $log->save(); 302 + $project_id = InquiryProject::where('version', '<', 6)->where('domain', 'like', '%' . $detail['website'] . '%')->value('primary_id') ?? 0;
  303 + if (in_array($project_id, $this->self_websites)) {
  304 + //发送到自己站点项目
  305 + $data = [
  306 + 'Name' => $detail['name'],
  307 + 'Phone' => $detail['phone'],
  308 + 'Message' => $detail['message'],
  309 + 'Email' => $detail['email'],
  310 + 'submit_ip' => $detail['ip'],
  311 + 'refer' => $log['url'],
  312 + 'submit_time' => date('Y-m-d H:i:s', time() + 60)
  313 + ];
  314 + $url = 'https://' . $detail['website'] . '/wp-admin/admin-ajax.php?action=live_remort_receive';
  315 + $res = Http::withoutVerifying()->timeout(30)->withHeaders(['User-Agent' => $detail['user_agent']])->post($url, $data);
  316 + $status = $res->status();
  317 + if ($status != 200) {
  318 + $log->status = InquiryRelayDetailLog::STATUS_FAIL;
  319 + $log->remark = mb_substr($res->body() ?? '', 0, 200);
  320 + $log->save();
249 321
250 - Log::channel('inquiry_forward')->error('post_inquiry_forward v4|v5 inquiry error', [$result->body(), 'https://www.globalso.site/api/external-interface/add/fa043f9cbec6b38f', $data]);  
251 - return false; 322 + Log::channel('inquiry_forward')->error('post_inquiry_forward v4|v5 inquiry error', [$res->body(), $url, $data]);
  323 + return false;
  324 + }
  325 + Log::channel('inquiry_forward')->error('post_inquiry_forward v4|v5 inquiry success', [$res->body(), $url, $data]);
  326 + } else {
  327 + $data = [
  328 + 'name' => $detail['name'],
  329 + 'phone' => $detail['phone'],
  330 + 'message' => $detail['message'],
  331 + 'email' => $detail['email'],
  332 + 'ip' => $detail['ip'],
  333 + 'token' => md5($log['url'] . $detail['name'] . $detail['ip'] . date("Y-m-d")),
  334 + 'refer' => $log['url'],
  335 + 'submit_time' => date('Y-m-d H:i:s'),
  336 + 'source' => 5,
  337 + ];
  338 + $url = 'https://www.globalso.site/api/external-interface/add/fa043f9cbec6b38f';
  339 + $res = Http::withoutVerifying()->timeout(30)->withHeaders(['User-Agent' => $detail['user_agent']])->post($url, $data)->json();
  340 + if (empty($res['status']) || $res['status'] != 200) {
  341 + $log->status = InquiryRelayDetailLog::STATUS_FAIL;
  342 + $log->remark = mb_substr($res['message'] ?? '', 0, 200);
  343 + $log->save();
  344 +
  345 + Log::channel('inquiry_forward')->error('post_inquiry_forward v4|v5 inquiry error', [$res, $url, $data]);
  346 + return false;
  347 + }
  348 + Log::channel('inquiry_forward')->error('post_inquiry_forward v4|v5 inquiry success', [$res, $url, $data]);
252 } 349 }
  350 +
253 return true; 351 return true;
254 } 352 }
255 353
@@ -153,6 +153,20 @@ class RelayInquiryForward extends Command @@ -153,6 +153,20 @@ class RelayInquiryForward extends Command
153 153
154 protected $otherzb = [700, 300]; //模拟访问来源占比 (非美国) google.com|google.其他后缀 154 protected $otherzb = [700, 300]; //模拟访问来源占比 (非美国) google.com|google.其他后缀
155 155
  156 + /**
  157 + * 芯片网站
  158 + * @var array
  159 + */
  160 + protected $xp_websites = [
  161 + 'www.shinecomponents.com',
  162 + 'www.hk-allchips.com',
  163 + 'www.xinjiada-ic.com',
  164 + 'www.sic-components.com',
  165 + 'www.chip1-vip.com',
  166 + 'www.flash-turtle.com',
  167 + 'www.xinteerchip.com',
  168 + 'www.conevoelec.com'
  169 + ];
156 170
157 public function handle() 171 public function handle()
158 { 172 {
@@ -207,9 +221,14 @@ class RelayInquiryForward extends Command @@ -207,9 +221,14 @@ class RelayInquiryForward extends Command
207 public function completeDetail($inquiry_detail) 221 public function completeDetail($inquiry_detail)
208 { 222 {
209 //visit urls 223 //visit urls
210 - $visit_urls = $this->getUrls($inquiry_detail['is_v6'], $inquiry_detail['website'], $inquiry_detail['email']);  
211 $inquiry_url = json_decode($inquiry_detail['urls'], true); 224 $inquiry_url = json_decode($inquiry_detail['urls'], true);
212 - $urls = array_merge($visit_urls, $inquiry_url); 225 + if (in_array($inquiry_detail['website'], $this->xp_websites)) {
  226 + //芯片网站无需模拟访问,直接发送询盘
  227 + $urls = $inquiry_url;
  228 + } else {
  229 + $visit_urls = $this->getUrls($inquiry_detail['is_v6'], $inquiry_detail['website'], $inquiry_detail['email']);
  230 + $urls = array_merge($visit_urls, $inquiry_url);
  231 + }
213 232
214 //lang 233 //lang
215 if (is_numeric($inquiry_detail['message'])) { //数字会被识别为中文 234 if (is_numeric($inquiry_detail['message'])) { //数字会被识别为中文
@@ -14,7 +14,6 @@ use App\Models\Inquiry\InquiryProjectRoute; @@ -14,7 +14,6 @@ use App\Models\Inquiry\InquiryProjectRoute;
14 use App\Models\Inquiry\InquiryRelayDetail; 14 use App\Models\Inquiry\InquiryRelayDetail;
15 use Illuminate\Support\Arr; 15 use Illuminate\Support\Arr;
16 use Illuminate\Support\Facades\DB; 16 use Illuminate\Support\Facades\DB;
17 -use Illuminate\Support\Facades\Log;  
18 use Illuminate\Support\Str; 17 use Illuminate\Support\Str;
19 18
20 /** 19 /**
@@ -185,6 +185,12 @@ return [ @@ -185,6 +185,12 @@ return [
185 'level' => 'debug', 185 'level' => 'debug',
186 'days' => 14, 186 'days' => 14,
187 ], 187 ],
  188 + 'inquiry_forward' => [
  189 + 'driver' => 'daily',
  190 + 'path' => storage_path('logs/inquiry_forward/laravel.log'),
  191 + 'level' => 'debug',
  192 + 'days' => 14,
  193 + ],
188 ], 194 ],
189 //操作日志 195 //操作日志
190 'operator_log' =>[ 196 'operator_log' =>[