正在显示
9 个修改的文件
包含
198 行增加
和
401 行删除
1 | -<?php | ||
2 | -/** | ||
3 | - * Created by PhpStorm. | ||
4 | - * User: zhl | ||
5 | - * Date: 2023/10/25 | ||
6 | - * Time: 14:38 | ||
7 | - */ | ||
8 | - | ||
9 | -namespace App\Http\Controllers\Api; | ||
10 | - | ||
11 | -use App\Console\Commands\CosService; | ||
12 | -use App\Exceptions\TipException; | ||
13 | -use App\Http\Controllers\Controller; | ||
14 | -use App\Models\Project\Project; | ||
15 | -use App\Models\SyncSubmitTask\SyncSubmitTask; | ||
16 | -use App\Models\WebSetting\WebSettingFormBack; | ||
17 | -use Illuminate\Http\Request; | ||
18 | -use Illuminate\Support\Facades\Cache; | ||
19 | - | ||
20 | -/** | ||
21 | - * Class InquiryController | ||
22 | - * @package App\Http\Controllers\Api | ||
23 | - */ | ||
24 | -class InquiryController extends Controller | ||
25 | -{ | ||
26 | - /** | ||
27 | - * C端表单提交 询盘信息 | ||
28 | - * @param Request $request | ||
29 | - * @return mixed | ||
30 | - */ | ||
31 | - public function inquiry(Request $request) | ||
32 | - { | ||
33 | - $data = $request->all(); | ||
34 | - | ||
35 | - $black_ips = ['203.86.233.27', '37.19.221.202']; | ||
36 | - if(in_array(request()->getClientIp(), $black_ips)){ | ||
37 | - $this->responseA(); | ||
38 | - } | ||
39 | - | ||
40 | - | ||
41 | - @file_put_contents(storage_path('logs/form_submit_' . date('Y-m-d') . '.log'), var_export(date('Y-m-d H:i:s') . "-表单提交数据:" . json_encode($data), true) . PHP_EOL, FILE_APPEND); | ||
42 | - | ||
43 | - //同一ip 5秒内超过5次 限制1小时 | ||
44 | - $ip = $request->ip(); | ||
45 | - $lock_key = 'lock_ip_' . $ip; | ||
46 | - $rate_key = 'rate_limit:' . $ip; | ||
47 | - if(Cache::has($lock_key)){ | ||
48 | - $this->responseA(); | ||
49 | - } | ||
50 | - if (Cache::has($rate_key)) { | ||
51 | - $count = Cache::get($rate_key); | ||
52 | - if ($count >= 5) { | ||
53 | - Cache::put($lock_key, 1, 3600); | ||
54 | - $this->responseA(); | ||
55 | - } | ||
56 | - Cache::increment($rate_key); | ||
57 | - } else { | ||
58 | - Cache::put($rate_key, 1, 5); | ||
59 | - } | ||
60 | - | ||
61 | - try { | ||
62 | - $files = $request->allFiles(); | ||
63 | - foreach ($files as $key => $file) { | ||
64 | - $cos = new CosService(); | ||
65 | - $fileinfo = $cos->checkFile($file); | ||
66 | - $fileName = uniqid().rand(10000,99999).'.'.$file->getClientOriginalExtension(); | ||
67 | - $path = $cos->uploadFile($file, '/inquiry/'. date('Ymd'), $fileName); | ||
68 | - $data[$key] = [ | ||
69 | - 'path' => $path, | ||
70 | - 'original_name' => $fileinfo['name'], | ||
71 | - ]; | ||
72 | - } | ||
73 | - }catch (TipException $e){ | ||
74 | - $this->responseA([], 400, $e->getMessage()); | ||
75 | - }catch (\Exception $e){ | ||
76 | - $this->responseA([], 400, 'File upload failed'); | ||
77 | - } | ||
78 | - | ||
79 | - //异步处理 | ||
80 | - if(!SyncSubmitTask::addTask(SyncSubmitTask::TYPE_INQUIRY, $data)){ | ||
81 | - $this->responseA([], 400, 'error'); | ||
82 | - } | ||
83 | - | ||
84 | - $this->responseA($this->inquiryResult()); | ||
85 | - } | ||
86 | - | ||
87 | - /** | ||
88 | - * 收集邮箱或者手机号等其他信息 | ||
89 | - * @param Request $request | ||
90 | - * @return mixed | ||
91 | - */ | ||
92 | - public function inquiryOtherInfo(Request $request) | ||
93 | - { | ||
94 | - return $this->inquiry($request); | ||
95 | - } | ||
96 | - | ||
97 | - /** | ||
98 | - * 起点表单询盘 | ||
99 | - * @param Request $request | ||
100 | - * @return mixed | ||
101 | - * @author zbj | ||
102 | - * @date 2023/12/8 | ||
103 | - */ | ||
104 | - public function inquiryQd(Request $request){ | ||
105 | - $data = $request->post(); | ||
106 | - @file_put_contents(storage_path('logs/form_submit_' . date('Y-m-d') . '.log'), var_export(date('Y-m-d H:i:s') . "-起点表单提交数据:" . json_encode($data), true) . PHP_EOL, FILE_APPEND); | ||
107 | - | ||
108 | - //Name,Email,Phone,Message,submit_ip,submit_time,refer | ||
109 | - $submit_ip = $data['submit_ip'] ?? ''; | ||
110 | - $submit_time = $data['submit_time'] ?? ''; | ||
111 | - $refer = $data['refer'] ?? ''; | ||
112 | - unset($data['submit_ip']); | ||
113 | - unset($data['submit_time']); | ||
114 | - unset($data['refer']); | ||
115 | - | ||
116 | - //异步处理 | ||
117 | - if(!SyncSubmitTask::addTask(SyncSubmitTask::TYPE_INQUIRY, $data, $submit_ip, $refer, $submit_time)){ | ||
118 | - $this->responseA([], 400, 'error'); | ||
119 | - } | ||
120 | - $this->responseA($this->inquiryResult()); | ||
121 | - } | ||
122 | - | ||
123 | - /** | ||
124 | - * @return mixed|string[] | ||
125 | - * @author zbj | ||
126 | - * @date 2023/12/4 | ||
127 | - */ | ||
128 | - protected function inquiryResult(){ | ||
129 | - $domain = request()->getHost(); | ||
130 | - $cache_key = 'inquiry_form_back_' . $domain; | ||
131 | - $result = Cache::get($cache_key); | ||
132 | - if(!$result){ | ||
133 | - $result = [ | ||
134 | - 'message' => "", | ||
135 | - 'url' => "" | ||
136 | - ]; | ||
137 | - $projectDomain = Project::getProjectByDomain($domain); | ||
138 | - $webFormBack = WebSettingFormBack::where("project_id", $projectDomain['project_id']??0)->first(); | ||
139 | - if (!empty($webFormBack)) { | ||
140 | - $result["message"] = $webFormBack->message ?? ""; | ||
141 | - $result["url"] = $webFormBack->url ?? ""; | ||
142 | - Cache::put($cache_key, $result, 3600); | ||
143 | - } | ||
144 | - } | ||
145 | - | ||
146 | - return $result; | ||
147 | - } | ||
148 | -} |
@@ -11,9 +11,8 @@ | @@ -11,9 +11,8 @@ | ||
11 | use Illuminate\Http\Exceptions\HttpResponseException; | 11 | use Illuminate\Http\Exceptions\HttpResponseException; |
12 | use Illuminate\Http\JsonResponse; | 12 | use Illuminate\Http\JsonResponse; |
13 | use Illuminate\Http\Request; | 13 | use Illuminate\Http\Request; |
14 | -use Illuminate\Support\Facades\Log; | ||
15 | -use RecursiveDirectoryIterator; | ||
16 | -use RecursiveIteratorIterator; | 14 | +use Illuminate\Support\Facades\Cache; |
15 | +use Illuminate\Support\Facades\Validator; | ||
17 | use ZipArchive; | 16 | use ZipArchive; |
18 | 17 | ||
19 | /** | 18 | /** |
@@ -52,15 +51,37 @@ protected function error($message = 'error', $status = 400, $data = []) | @@ -52,15 +51,37 @@ protected function error($message = 'error', $status = 400, $data = []) | ||
52 | } | 51 | } |
53 | 52 | ||
54 | /** | 53 | /** |
54 | + * 响应response | ||
55 | + * @param array $data | ||
56 | + * @param int $code | ||
57 | + * @param string $msg | ||
58 | + * @param int $result_code | ||
59 | + * @param string $type | ||
60 | + */ | ||
61 | + public function responseA($data = [], $code = 200, $msg = 'success', $result_code = 200, $type = 'application/json') | ||
62 | + { | ||
63 | + $result = [ | ||
64 | + 'msg' => $msg, | ||
65 | + 'code' => $code, | ||
66 | + 'data' => $data, | ||
67 | + ]; | ||
68 | + $header = [ | ||
69 | + 'Content-Type' => $type, | ||
70 | + ]; | ||
71 | + $response = response($result, $result_code, $header); | ||
72 | + throw new HttpResponseException($response); | ||
73 | + } | ||
74 | + | ||
75 | + /** | ||
55 | * 响应 | 76 | * 响应 |
56 | * @param null $msg | 77 | * @param null $msg |
57 | - * @param string $code | 78 | + * @param int $code |
58 | * @param array $data | 79 | * @param array $data |
59 | * @param int $result_code | 80 | * @param int $result_code |
60 | * @param string $type | 81 | * @param string $type |
61 | - * @return JsonResponse | 82 | + * @return void |
62 | */ | 83 | */ |
63 | - public function response($msg = null,string $code = self::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'): JsonResponse | 84 | + public function response($msg = null,$code = self::SUCCESS,$data = [],$result_code = 200,$type = 'application/json') |
64 | { | 85 | { |
65 | $result = [ | 86 | $result = [ |
66 | 'msg' => $msg, | 87 | 'msg' => $msg, |
@@ -98,8 +119,10 @@ public function curlGet($url){ | @@ -98,8 +119,10 @@ public function curlGet($url){ | ||
98 | 119 | ||
99 | /** | 120 | /** |
100 | * A端上传验证代码 | 121 | * A端上传验证代码 |
122 | + * @param Request $request | ||
123 | + * @return string | ||
101 | */ | 124 | */ |
102 | - public function uploadVerifyFile(Request $request): string | 125 | + public function uploadVerifyFile(Request $request) |
103 | { | 126 | { |
104 | $domain = $request->getHost(); | 127 | $domain = $request->getHost(); |
105 | $files = $request->allFiles(); | 128 | $files = $request->allFiles(); |
@@ -117,7 +140,7 @@ public function uploadVerifyFile(Request $request): string | @@ -117,7 +140,7 @@ public function uploadVerifyFile(Request $request): string | ||
117 | * @param Request $request | 140 | * @param Request $request |
118 | * @return string | 141 | * @return string |
119 | */ | 142 | */ |
120 | - public function uploadAmpVerifyFile(Request $request): string | 143 | + public function uploadAmpVerifyFile(Request $request) |
121 | { | 144 | { |
122 | $domain = $request->getHost(); | 145 | $domain = $request->getHost(); |
123 | 146 | ||
@@ -156,7 +179,6 @@ public function websiteHtml(Request $request){ | @@ -156,7 +179,6 @@ public function websiteHtml(Request $request){ | ||
156 | $requestUrl = $apiUrl."?domain=".$domain."&token=".$token; | 179 | $requestUrl = $apiUrl."?domain=".$domain."&token=".$token; |
157 | @file_put_contents(storage_path('logs/notify_get_url.log'), date('Y-m-d H:i:s') . "接收到通知:". $requestUrl . PHP_EOL, FILE_APPEND); | 180 | @file_put_contents(storage_path('logs/notify_get_url.log'), date('Y-m-d H:i:s') . "接收到通知:". $requestUrl . PHP_EOL, FILE_APPEND); |
158 | 181 | ||
159 | - | ||
160 | try { | 182 | try { |
161 | $res = $this->curlGet($requestUrl); | 183 | $res = $this->curlGet($requestUrl); |
162 | $url = isset($res["data"]["url"]) && !empty($res["data"]["url"]) ? urldecode($res["data"]["url"]) : ""; | 184 | $url = isset($res["data"]["url"]) && !empty($res["data"]["url"]) ? urldecode($res["data"]["url"]) : ""; |
@@ -170,9 +192,10 @@ public function websiteHtml(Request $request){ | @@ -170,9 +192,10 @@ public function websiteHtml(Request $request){ | ||
170 | return $this->websiteHtmlHandle($url,$domain); | 192 | return $this->websiteHtmlHandle($url,$domain); |
171 | } | 193 | } |
172 | 194 | ||
173 | -/** | 195 | + /** |
174 | * 网站html解压 | 196 | * 网站html解压 |
175 | * @param $url | 197 | * @param $url |
198 | + * @param $domain | ||
176 | * @return string | 199 | * @return string |
177 | */ | 200 | */ |
178 | public function websiteHtmlHandle($url,$domain) | 201 | public function websiteHtmlHandle($url,$domain) |
@@ -237,7 +260,7 @@ public function downLoadFile($url){ | @@ -237,7 +260,7 @@ public function downLoadFile($url){ | ||
237 | * @param $path | 260 | * @param $path |
238 | * @return bool | 261 | * @return bool |
239 | */ | 262 | */ |
240 | - public function deleteDirectory($path): bool | 263 | + public function deleteDirectory($path) |
241 | { | 264 | { |
242 | if (!is_dir($path)) { | 265 | if (!is_dir($path)) { |
243 | try { | 266 | try { |
@@ -265,31 +288,156 @@ public function deleteDirectory($path): bool | @@ -265,31 +288,156 @@ public function deleteDirectory($path): bool | ||
265 | } | 288 | } |
266 | 289 | ||
267 | /** | 290 | /** |
291 | + * 客户访问埋点接口 | ||
292 | + * @param Request $request | ||
293 | + * @return JsonResponse | ||
294 | + */ | ||
295 | + public function customerVisit(Request $request) | ||
296 | + { | ||
297 | + $data = $request->all(); | ||
298 | + $data["referrer_url"] = !empty($data["referrer_url"]) ? $data["referrer_url"] : ""; | ||
299 | + $data["url"] = !empty($data["url"]) ? $data["url"] : ""; | ||
300 | + $data["domain"] = !empty($data["domain"]) ? $data["domain"] : ""; | ||
301 | + $data["ip"] = $request->getClientIp(); | ||
302 | + $data["user_agent"] = $request->userAgent(); | ||
303 | + if (empty($data["referrer_url"]) || empty($data["url"]) || empty($data["domain"])){ | ||
304 | + return response()->json([ | ||
305 | + 'code' => self::SUCCESS, | ||
306 | + 'msg' => 'success', | ||
307 | + ]); | ||
308 | + } | ||
309 | + | ||
310 | + //转发data | ||
311 | + | ||
312 | + //埋点成功 | ||
313 | + return response()->json([ | ||
314 | + 'code' => self::SUCCESS, | ||
315 | + 'msg' => 'success', | ||
316 | + ]); | ||
317 | + } | ||
318 | + | ||
319 | + /** | ||
320 | + * 接口 | ||
321 | + * @param Request $request | ||
322 | + * @return string | ||
323 | + */ | ||
324 | + public function trafficVisit(Request $request) | ||
325 | + { | ||
326 | + //获取参数 | ||
327 | + $data = $request->all(); | ||
328 | + $data["id"] = $request->input('ip'); | ||
329 | + $data["url"] = $request->input('url'); | ||
330 | + $data["device_port"] = intval($request->input('device_port')); | ||
331 | + $data["referrer_url"] = $request->input('referrer_url'); | ||
332 | + $data["user_agent"] = $request->input('user_agent'); | ||
333 | + if (empty($data["id"]) || empty($data["url"]) || empty($data["referrer_url"]) || empty($data["user_agent"])){ | ||
334 | + return response()->json([ | ||
335 | + 'code' => self::SUCCESS, | ||
336 | + 'msg' => 'success', | ||
337 | + ]); | ||
338 | + } | ||
339 | + | ||
340 | + //转发data | ||
341 | + | ||
342 | + //成功 | ||
343 | + return response()->json([ | ||
344 | + 'code' => self::SUCCESS, | ||
345 | + 'msg' => 'success', | ||
346 | + ]); | ||
347 | + | ||
348 | + | ||
349 | + } | ||
350 | + | ||
351 | + /** | ||
352 | + * C端表单提交 询盘信息 | ||
353 | + * @param Request $request | ||
354 | + * @return mixed | ||
355 | + */ | ||
356 | + public function inquiry(Request $request) | ||
357 | + { | ||
358 | + $data = $request->all(); | ||
359 | + | ||
360 | + $black_ips = ['203.86.233.27', '37.19.221.202']; | ||
361 | + if(in_array(request()->getClientIp(), $black_ips)){ | ||
362 | + $this->success(); | ||
363 | + } | ||
364 | + | ||
365 | + //同一ip 5秒内超过5次 限制1小时 | ||
366 | + $ip = $request->ip(); | ||
367 | + $lock_key = 'lock_ip_' . $ip; | ||
368 | + $rate_key = 'rate_limit:' . $ip; | ||
369 | + if(Cache::has($lock_key)){ | ||
370 | + $this->success(); | ||
371 | + } | ||
372 | + if (Cache::has($rate_key)) { | ||
373 | + $count = Cache::get($rate_key); | ||
374 | + if ($count >= 5) { | ||
375 | + Cache::put($lock_key, 1, 3600); | ||
376 | + $this->success(); | ||
377 | + } | ||
378 | + Cache::increment($rate_key); | ||
379 | + } else { | ||
380 | + Cache::put($rate_key, 1, 5); | ||
381 | + } | ||
382 | + | ||
383 | + $data["files"] = $request->allFiles(); | ||
384 | + | ||
385 | + //转发data | ||
386 | + //返回数据 | ||
387 | + $res = ""; | ||
388 | + | ||
389 | + return $this->responseA($res); | ||
390 | + } | ||
391 | + | ||
392 | + /** | ||
393 | + * 收集邮箱或者手机号等其他信息 | ||
394 | + * @param Request $request | ||
395 | + * @return mixed | ||
396 | + */ | ||
397 | + public function inquiryOtherInfo(Request $request) | ||
398 | + { | ||
399 | + return $this->inquiry($request); | ||
400 | + } | ||
401 | + | ||
402 | + /** | ||
403 | + * 起点表单询盘 | ||
404 | + * @param Request $request | ||
405 | + * @return void | ||
406 | + */ | ||
407 | + public function inquiryQd(Request $request){ | ||
408 | + $data = $request->post(); | ||
409 | + $data['submit_ip'] = $data['submit_ip'] ? $data['submit_ip'] : ''; | ||
410 | + $data['submit_time'] = $data['submit_time'] ? $data['submit_time'] : ''; | ||
411 | + $data['refer'] = $data['refer'] ? $data['refer'] : ''; | ||
412 | + | ||
413 | + //转发data | ||
414 | + //返回数据 | ||
415 | + $res = ""; | ||
416 | + | ||
417 | + return $this->responseA($res); | ||
418 | + } | ||
419 | + | ||
420 | + /** | ||
268 | * 搜索 | 421 | * 搜索 |
269 | * @param Request $request | 422 | * @param Request $request |
270 | */ | 423 | */ |
271 | public function search(Request $request) | 424 | public function search(Request $request) |
272 | { | 425 | { |
273 | - $project = $request->get('project'); | ||
274 | $data = $request->all(); | 426 | $data = $request->all(); |
275 | 427 | ||
276 | //获取搜索参数 | 428 | //获取搜索参数 |
277 | - $searchContent = ''; | 429 | + $data["search_content"] = ''; |
278 | if (isset($data['s'])) { | 430 | if (isset($data['s'])) { |
279 | - $searchContent = $data['s']; | 431 | + $data["search_content"] = $searchContent = $data['s']; |
280 | } | 432 | } |
281 | if (isset($data['search'])) { | 433 | if (isset($data['search'])) { |
282 | - $searchContent = $data['search']; | 434 | + $data["search_content"] = $data['search']; |
283 | } | 435 | } |
284 | 436 | ||
285 | - $page = 1; | ||
286 | - if (isset($data['page']) && (int)$data['page'] > 1) { | ||
287 | - $page = (int)$data['page']; | ||
288 | - } | 437 | + $data["page"] = isset($data['page']) && (int)$data['page'] > 1 ? (int)$data['page'] : 1; |
289 | 438 | ||
290 | -// $htmlService = new HtmlService(); | 439 | + //转发data |
291 | 440 | ||
292 | 441 | ||
293 | -// return $htmlService->getSearchHtml($project, $data, $searchContent, $page); | ||
294 | } | 442 | } |
295 | } | 443 | } |
1 | -<?php | ||
2 | -/** | ||
3 | - * Created by PhpStorm. | ||
4 | - * User: zhl | ||
5 | - * Date: 2024/1/6 | ||
6 | - * Time: 16:06 | ||
7 | - */ | ||
8 | -namespace App\Http\Controllers\Api; | ||
9 | - | ||
10 | -use App\Http\Controllers\Controller; | ||
11 | -use App\Repositories\SyncSubmitRepository; | ||
12 | -use Illuminate\Http\Request; | ||
13 | -use Illuminate\Support\Facades\Validator; | ||
14 | - | ||
15 | -/** | ||
16 | - * Class TrafficController | ||
17 | - * @package App\Http\Controllers\Api | ||
18 | - */ | ||
19 | -class TrafficController extends Controller | ||
20 | -{ | ||
21 | - /** | ||
22 | - * 特殊访问引流接口 | ||
23 | - * @param Request $request | ||
24 | - * @return string | ||
25 | - */ | ||
26 | - public function trafficVisit(Request $request) | ||
27 | - { | ||
28 | - //获取参数 | ||
29 | - $data = $request->all(); | ||
30 | - $ip = $request->input('ip'); | ||
31 | - $url = $request->input('url'); | ||
32 | - $device_port = intval($request->input('device_port')); | ||
33 | - $referrer_url = $request->input('referrer_url'); | ||
34 | - $user_agent = $request->input('user_agent'); | ||
35 | - | ||
36 | - // FIXME 些日志 观察数据, 完成以后删除代码 | ||
37 | - file_put_contents(storage_path('logs/trafficVisit' . date('Y-m-d') . '.log'), var_export($data, true)); | ||
38 | - //验证参数 | ||
39 | - $validator = Validator::make($data, [ | ||
40 | - 'ip' => 'required', | ||
41 | - 'url' => 'required', | ||
42 | - 'user_agent' => 'required', | ||
43 | - ], [ | ||
44 | - 'ip.required' => 'IP不能为空', | ||
45 | - 'url.required' => '访问链接不能为空', | ||
46 | - 'user_agent.required' => '请求头信息user_agent不能为空', | ||
47 | - ]); | ||
48 | - //判断参数是否正确 | ||
49 | - if ($validator->fails()) { | ||
50 | - return $this->error($validator->errors()->first()); | ||
51 | - } | ||
52 | - | ||
53 | - $result = app(SyncSubmitRepository::class)->trafficVisit($ip, $url, $user_agent, $referrer_url, $device_port, 1); | ||
54 | - return $result ? $this->success() : $this->error(); | ||
55 | - } | ||
56 | - | ||
57 | - | ||
58 | -} |
1 | -<?php | ||
2 | - | ||
3 | -namespace App\Http\Controllers\Cside\Visit; | ||
4 | - | ||
5 | -use App\Enums\Common\Code; | ||
6 | -use App\Http\Controllers\Cside\BaseController; | ||
7 | -use App\Models\Project\Project; | ||
8 | -use App\Models\SyncSubmitTask\SyncSubmitTask; | ||
9 | -use Illuminate\Http\Request; | ||
10 | -use Illuminate\Support\Facades\Log; | ||
11 | - | ||
12 | -class VisitController extends BaseController | ||
13 | -{ | ||
14 | - /** | ||
15 | - * 客户访问埋点接口 | ||
16 | - */ | ||
17 | - public function customerVisit(Request $request): \Illuminate\Http\JsonResponse | ||
18 | - { | ||
19 | - $data = $request->all(); | ||
20 | - | ||
21 | - if ($this->filter($request)){ | ||
22 | - $data = $this->visitInfoHandle($data); | ||
23 | - //异步处理 | ||
24 | - if(!SyncSubmitTask::addTask(SyncSubmitTask::TYPE_VISIT, $data)){ | ||
25 | - $this->responseA([], 400, 'error'); | ||
26 | - } | ||
27 | - } | ||
28 | - | ||
29 | - //埋点成功 | ||
30 | - return response()->json([ | ||
31 | - 'code' => Code::SUCCESS_NUM, | ||
32 | - 'msg' => '客户访问', | ||
33 | - ]); | ||
34 | - } | ||
35 | - | ||
36 | - public function filter($request){ | ||
37 | - if($request->getClientIp() == "127.0.0.1"){ | ||
38 | - return false; | ||
39 | - } | ||
40 | - //判断是否是爬虫 | ||
41 | - $isReptile = $this->isReptile($request); | ||
42 | - if($isReptile){ | ||
43 | - return false; | ||
44 | - } | ||
45 | - //是否允许测试环境 | ||
46 | - $projectDomain = Project::getProjectByDomain($request->getHost()); | ||
47 | - $project = Project::find($projectDomain['project_id']??0); | ||
48 | - if(empty($project)){ | ||
49 | - return false; | ||
50 | - } | ||
51 | - // 测试环境返回信息 | ||
52 | - if (FALSE !== strpos($request->getHost(), 'globalso.site') && !$project->is_record_test_visit) { | ||
53 | - return false; | ||
54 | - } | ||
55 | - return true; | ||
56 | - } | ||
57 | - | ||
58 | - /** | ||
59 | - * 埋点信息处理 | ||
60 | - */ | ||
61 | - public function visitInfoHandle($data) | ||
62 | - { | ||
63 | - //referrer | ||
64 | - if(preg_match('/google|facebook|bing|yahoo|youtobe|linkedin|messefrankfurt|yandex|tiktok|twitter|instagram|reddit|telegram|pinterest|tumblr/', $data['referrer_url'])){ | ||
65 | - }else if($data['referrer_url'] == null){ | ||
66 | - //直访用户 | ||
67 | - $data['referrer_url'] = ""; | ||
68 | - }else{ | ||
69 | - $data['referrer_url'] = "https://www.google.com/"; | ||
70 | - } | ||
71 | - return $data; | ||
72 | - } | ||
73 | - | ||
74 | - /** | ||
75 | - * 是否是爬虫访问 | ||
76 | - */ | ||
77 | - public function isReptile($request): bool | ||
78 | - { | ||
79 | - $agent = $request->header('User-Agent'); | ||
80 | - if (!empty($agent)) { | ||
81 | - $spiderSite= array( | ||
82 | - "TencentTraveler", | ||
83 | - "Baiduspider+", | ||
84 | - "BaiduGame", | ||
85 | - "Googlebot", | ||
86 | - "msnbot", | ||
87 | - "Sosospider+", | ||
88 | - "Sogou web spider", | ||
89 | - "ia_archiver", | ||
90 | - "Yahoo! Slurp", | ||
91 | - "YoudaoBot", | ||
92 | - "Yahoo Slurp", | ||
93 | - "MSNBot", | ||
94 | - "Java (Often spam bot)", | ||
95 | - "BaiDuSpider", | ||
96 | - "Voila", | ||
97 | - "Yandex bot", | ||
98 | - "BSpider", | ||
99 | - "twiceler", | ||
100 | - "Sogou Spider", | ||
101 | - "Speedy Spider", | ||
102 | - "Google AdSense", | ||
103 | - "Heritrix", | ||
104 | - "Python-urllib", | ||
105 | - "Alexa (IA Archiver)", | ||
106 | - "Ask", | ||
107 | - "Exabot", | ||
108 | - "Custo", | ||
109 | - "OutfoxBot/YodaoBot", | ||
110 | - "yacy", | ||
111 | - "SurveyBot", | ||
112 | - "legs", | ||
113 | - "lwp-trivial", | ||
114 | - "Nutch", | ||
115 | - "StackRambler", | ||
116 | - "The web archive (IA Archiver)", | ||
117 | - "Perl tool", | ||
118 | - "MJ12bot", | ||
119 | - "Netcraft", | ||
120 | - "MSIECrawler", | ||
121 | - "WGet tools", | ||
122 | - "larbin", | ||
123 | - "Fish search", | ||
124 | - "yandex.com/bots", | ||
125 | - "google.com/bot", | ||
126 | - "bingbot", | ||
127 | - "YandexMobileBot", | ||
128 | - "BingPreview", | ||
129 | - "AhrefsBot", | ||
130 | - "bot" | ||
131 | - ); | ||
132 | - $flag = 0; | ||
133 | - foreach($spiderSite as $val) { | ||
134 | - $str = strtolower($val); | ||
135 | - if (strpos($agent, $str) !== false) { | ||
136 | - $flag = 1; | ||
137 | - } | ||
138 | - } | ||
139 | - if($flag == 1){ | ||
140 | - return true; | ||
141 | - }else{ | ||
142 | - return false; | ||
143 | - } | ||
144 | - } else { | ||
145 | - return false; | ||
146 | - } | ||
147 | - } | ||
148 | -} |
@@ -9,10 +9,9 @@ class CorsMiddleware | @@ -9,10 +9,9 @@ class CorsMiddleware | ||
9 | { | 9 | { |
10 | /** | 10 | /** |
11 | * Handle an incoming request. | 11 | * Handle an incoming request. |
12 | - * | ||
13 | - * @param \Illuminate\Http\Request $request | ||
14 | - * @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next | ||
15 | - * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse | 12 | + * @param Request $request |
13 | + * @param Closure $next | ||
14 | + * @return mixed | ||
16 | */ | 15 | */ |
17 | public function handle(Request $request, Closure $next) | 16 | public function handle(Request $request, Closure $next) |
18 | { | 17 | { |
@@ -10,12 +10,10 @@ | @@ -10,12 +10,10 @@ | ||
10 | class RedirectIfAuthenticated | 10 | class RedirectIfAuthenticated |
11 | { | 11 | { |
12 | /** | 12 | /** |
13 | - * Handle an incoming request. | ||
14 | - * | ||
15 | - * @param \Illuminate\Http\Request $request | ||
16 | - * @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next | ||
17 | - * @param string|null ...$guards | ||
18 | - * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse | 13 | + * @param Request $request |
14 | + * @param Closure $next | ||
15 | + * @param array $guards | ||
16 | + * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|mixed | ||
19 | */ | 17 | */ |
20 | public function handle(Request $request, Closure $next, ...$guards) | 18 | public function handle(Request $request, Closure $next, ...$guards) |
21 | { | 19 | { |
@@ -13,8 +13,12 @@ class VerifyCsrfToken extends Middleware | @@ -13,8 +13,12 @@ class VerifyCsrfToken extends Middleware | ||
13 | */ | 13 | */ |
14 | protected $except = [ | 14 | protected $except = [ |
15 | "api/customerVisit", | 15 | "api/customerVisit", |
16 | + "api/traffic_visit", | ||
16 | "api/inquiry", | 17 | "api/inquiry", |
17 | "api/inquiryOtherInfo", | 18 | "api/inquiryOtherInfo", |
19 | + "api/inquiryQd", | ||
20 | + "api/upload_verify_file", | ||
21 | + "api/upload_amp_verify_file", | ||
18 | "api/website_html_handle", | 22 | "api/website_html_handle", |
19 | ]; | 23 | ]; |
20 | } | 24 | } |
@@ -17,19 +17,21 @@ | @@ -17,19 +17,21 @@ | ||
17 | | | 17 | | |
18 | */ | 18 | */ |
19 | 19 | ||
20 | -Route::post('/customerVisit',[VisitController::class,'customerVisit']); | ||
21 | -//表单创建 | ||
22 | -Route::post('/traffic_visit',[\App\Http\Controllers\Api\TrafficController::class,'trafficVisit']); | ||
23 | -//表单提交 | ||
24 | -Route::any('/inquiry',[InquiryController::class,'inquiry']); | ||
25 | -//收集邮箱或者手机号 | ||
26 | -Route::any('/inquiryOtherInfo',[InquiryController::class,'inquiryOtherInfo']); | ||
27 | -//起点表单 | ||
28 | -Route::any('/inquiryQd',[InquiryController::class,'inquiryQd']); | ||
29 | -//A端上传验证文件 | ||
30 | -Route::any('/upload_verify_file',[NoticeController::class, 'uploadVerifyFile']); | ||
31 | -//A端上传amp站验证文件 | ||
32 | -Route::any('/upload_amp_verify_file',[NoticeController::class, 'uploadAmpVerifyFile']); | ||
33 | 20 | ||
34 | -//网站html处理 | ||
35 | -Route::any('/website_html_handle',[NoticeController::class, 'websiteHtml']); | 21 | +Route::middleware(['cors'])->group(function () { |
22 | + //埋点 | ||
23 | + Route::any('/customerVisit',[NoticeController::class,'customerVisit']); | ||
24 | + //表单提交 | ||
25 | + Route::any('/traffic_visit',[NoticeController::class,'trafficVisit']); | ||
26 | + Route::any('/inquiry',[NoticeController::class,'inquiry']); | ||
27 | + Route::any('/inquiryQd',[NoticeController::class,'inquiryQd']); | ||
28 | + //收集邮箱或者手机号 | ||
29 | + Route::any('/inquiryOtherInfo',[NoticeController::class,'inquiryOtherInfo']); | ||
30 | + //A端上传验证文件 | ||
31 | + Route::any('/upload_verify_file',[NoticeController::class, 'uploadVerifyFile']); | ||
32 | + //A端上传amp站验证文件 | ||
33 | + Route::any('/upload_amp_verify_file',[NoticeController::class, 'uploadAmpVerifyFile']); | ||
34 | + //网站html处理 | ||
35 | + Route::any('/website_html_handle',[NoticeController::class, 'websiteHtml']); | ||
36 | +}); | ||
37 | + |
@@ -14,7 +14,7 @@ | @@ -14,7 +14,7 @@ | ||
14 | | | 14 | | |
15 | */ | 15 | */ |
16 | 16 | ||
17 | -Route::middleware([ 'cors'])->group(function () { | 17 | +Route::middleware(['cors'])->group(function () { |
18 | //搜索页 | 18 | //搜索页 |
19 | Route::get('/search', [NoticeController::class, 'search']); | 19 | Route::get('/search', [NoticeController::class, 'search']); |
20 | }); | 20 | }); |
-
请 注册 或 登录 后发表评论