|
@@ -11,9 +11,13 @@ namespace App\Console\Commands\Inquiry; |
|
@@ -11,9 +11,13 @@ namespace App\Console\Commands\Inquiry; |
|
11
|
use App\Helper\Translate;
|
11
|
use App\Helper\Translate;
|
|
12
|
use App\Helper\Validate;
|
12
|
use App\Helper\Validate;
|
|
13
|
use App\Models\Inquiry\InquiryInfo;
|
13
|
use App\Models\Inquiry\InquiryInfo;
|
|
|
|
14
|
+use App\Models\Project\InquiryFilterConfig;
|
|
|
|
15
|
+use App\Models\Project\Project;
|
|
14
|
use App\Services\InquiryRelayService;
|
16
|
use App\Services\InquiryRelayService;
|
|
15
|
use Illuminate\Console\Command;
|
17
|
use Illuminate\Console\Command;
|
|
16
|
use Illuminate\Support\Facades\DB;
|
18
|
use Illuminate\Support\Facades\DB;
|
|
|
|
19
|
+use Illuminate\Support\Facades\URL;
|
|
|
|
20
|
+use Illuminate\Support\Str;
|
|
17
|
|
21
|
|
|
18
|
class SyncInquiryRelay extends Command
|
22
|
class SyncInquiryRelay extends Command
|
|
19
|
{
|
23
|
{
|
|
@@ -65,10 +69,6 @@ class SyncInquiryRelay extends Command |
|
@@ -65,10 +69,6 @@ class SyncInquiryRelay extends Command |
|
65
|
if (isset($result['status']) && $result['status'] == 200) {
|
69
|
if (isset($result['status']) && $result['status'] == 200) {
|
|
66
|
$data = $result['data'] ?? [];
|
70
|
$data = $result['data'] ?? [];
|
|
67
|
foreach ($data as $item) {
|
71
|
foreach ($data as $item) {
|
|
68
|
- if (substr($item['phone'], 0, 3) == '+86') {
|
|
|
|
69
|
- //+86区号过滤
|
|
|
|
70
|
- continue;
|
|
|
|
71
|
- }
|
|
|
|
72
|
$this->saveDate($item, $item['source_type']);
|
72
|
$this->saveDate($item, $item['source_type']);
|
|
73
|
}
|
73
|
}
|
|
74
|
}
|
74
|
}
|
|
@@ -214,11 +214,126 @@ class SyncInquiryRelay extends Command |
|
@@ -214,11 +214,126 @@ class SyncInquiryRelay extends Command |
|
214
|
$phone_status = $check_phone ? 1 : 0;
|
214
|
$phone_status = $check_phone ? 1 : 0;
|
|
215
|
}
|
215
|
}
|
|
216
|
|
216
|
|
|
217
|
- $model->createInquiry($data['name'], $data['phone'], $data['email'], $data['ip'], $country, $data['message'], $message_cn, $type, $data['time'], $data['refer'], $data['title'], $keywords, $message_sign, $data['origin_key'], $data['image'], $email_status, $phone_status);
|
217
|
+ //邮箱和内容唯一值
|
|
|
|
218
|
+ $unique_sign = md5($data['email'] . $data['message']);
|
|
|
|
219
|
+
|
|
|
|
220
|
+ //过滤数据:邮箱内容唯一性,国家,ip,内容,来源,邮箱,电话,姓名
|
|
|
|
221
|
+ $remark = $this->inquiryFilter($unique_sign, $country, $data['ip'], $data['message'], $data['refer'], $data['email'], $data['phone'], $data['name']);
|
|
|
|
222
|
+ $status = $remark ? InquiryInfo::STATUS_INVALID : InquiryInfo::STATUS_INIT;
|
|
|
|
223
|
+
|
|
|
|
224
|
+ $model->createInquiry($data['name'], $data['phone'], $data['email'], $data['ip'], $country, $data['message'], $message_cn, $type, $data['time'], $data['refer'], $data['title'], $keywords, $message_sign, $data['origin_key'], $data['image'], $email_status, $phone_status, $unique_sign, $status, $remark);
|
|
218
|
return true;
|
225
|
return true;
|
|
219
|
}
|
226
|
}
|
|
220
|
|
227
|
|
|
221
|
/**
|
228
|
/**
|
|
|
|
229
|
+ * 过滤数据
|
|
|
|
230
|
+ * @param $unique_sign
|
|
|
|
231
|
+ * @param $country
|
|
|
|
232
|
+ * @param $ip
|
|
|
|
233
|
+ * @param $message
|
|
|
|
234
|
+ * @param $refer
|
|
|
|
235
|
+ * @param $email
|
|
|
|
236
|
+ * @param $phone
|
|
|
|
237
|
+ * @param $name
|
|
|
|
238
|
+ * @return string
|
|
|
|
239
|
+ * @author Akun
|
|
|
|
240
|
+ * @date 2025/03/06 15:09
|
|
|
|
241
|
+ */
|
|
|
|
242
|
+ public function inquiryFilter($unique_sign, $country, $ip, $message, $refer, $email, $phone, $name)
|
|
|
|
243
|
+ {
|
|
|
|
244
|
+ //邮箱和内容唯一性
|
|
|
|
245
|
+ if (InquiryInfo::where('unique_sign', $unique_sign)->first()) {
|
|
|
|
246
|
+ return '邮箱内容重复过滤';
|
|
|
|
247
|
+ }
|
|
|
|
248
|
+
|
|
|
|
249
|
+ //国内ip
|
|
|
|
250
|
+ if ($country == '中国') {
|
|
|
|
251
|
+ return '中国内地过滤';
|
|
|
|
252
|
+ }
|
|
|
|
253
|
+
|
|
|
|
254
|
+ //QQ邮箱
|
|
|
|
255
|
+ if (substr($email, -6) == 'qq.com') {
|
|
|
|
256
|
+ return 'QQ邮箱过滤';
|
|
|
|
257
|
+ }
|
|
|
|
258
|
+
|
|
|
|
259
|
+ //86开头的手机号
|
|
|
|
260
|
+ $num_phone = preg_replace('/\D/', '', $phone) ?? ''; // \D 匹配所有非数字字符
|
|
|
|
261
|
+ if (substr($num_phone, 0, 2) == '86') {
|
|
|
|
262
|
+ return '86开头手机号过滤';
|
|
|
|
263
|
+ }
|
|
|
|
264
|
+
|
|
|
|
265
|
+ //公共规则
|
|
|
|
266
|
+ $config = InquiryFilterConfig::getCacheInfoByProjectId(Project::DEMO_PROJECT_ID);
|
|
|
|
267
|
+ //过滤国家
|
|
|
|
268
|
+ if (!empty($config['filter_countries']) && in_array($country, $config['filter_countries'])) {
|
|
|
|
269
|
+ return '过滤国家:' . $country;
|
|
|
|
270
|
+ }
|
|
|
|
271
|
+ //过滤ip
|
|
|
|
272
|
+ if (!empty($config['black_ips']) && in_array($ip, $config['black_ips'])) {
|
|
|
|
273
|
+ return '过滤黑名单IP:' . $ip;
|
|
|
|
274
|
+ }
|
|
|
|
275
|
+ //过滤内容关键字
|
|
|
|
276
|
+ if (!empty($config['filter_contents'])) {
|
|
|
|
277
|
+ foreach ($config['filter_contents'] as $filter_content) {
|
|
|
|
278
|
+ //中文直接包含
|
|
|
|
279
|
+ if (preg_match("/^[\x{4e00}-\x{9fa5}]+$/u", $filter_content)) {
|
|
|
|
280
|
+ if (Str::contains($message, $filter_content)) {
|
|
|
|
281
|
+ return '过滤内容:' . $filter_content;
|
|
|
|
282
|
+ }
|
|
|
|
283
|
+ } else {
|
|
|
|
284
|
+ //英文要指定词才过滤
|
|
|
|
285
|
+ if (preg_match("/\b" . preg_quote($filter_content, "/") . "\b/i", $message)) {
|
|
|
|
286
|
+ return '过滤内容:' . $filter_content;
|
|
|
|
287
|
+ }
|
|
|
|
288
|
+ }
|
|
|
|
289
|
+ }
|
|
|
|
290
|
+ }
|
|
|
|
291
|
+ //过滤内容是否允许包含链接
|
|
|
|
292
|
+ if (isset($config['is_allow_link']) && $config['is_allow_link'] == 0) {
|
|
|
|
293
|
+ if (Str::contains(strtolower($message), ['http://', 'https://', 'www.'])) {
|
|
|
|
294
|
+ return '内容包含链接过滤';
|
|
|
|
295
|
+ }
|
|
|
|
296
|
+ }
|
|
|
|
297
|
+ //过滤来源
|
|
|
|
298
|
+ if (!empty($config['filter_referers'])) {
|
|
|
|
299
|
+ //只比较path路径
|
|
|
|
300
|
+ $paths = array_map(function ($v) {
|
|
|
|
301
|
+ return trim(parse_url(Url::to($v), PHP_URL_PATH), '/');
|
|
|
|
302
|
+ }, $config['filter_referers']);
|
|
|
|
303
|
+
|
|
|
|
304
|
+ if (in_array(trim(parse_url($refer, PHP_URL_PATH), '/'), $paths)) {
|
|
|
|
305
|
+ return '过滤来源链接:' . $refer;
|
|
|
|
306
|
+ }
|
|
|
|
307
|
+ }
|
|
|
|
308
|
+ //过滤邮箱
|
|
|
|
309
|
+ if (!empty($config['filter_emails'])) {
|
|
|
|
310
|
+ foreach ($config['filter_emails'] as $filter_email) {
|
|
|
|
311
|
+ if (Str::contains(strtolower($email), strtolower($filter_email))) {
|
|
|
|
312
|
+ return '过滤邮箱:' . $filter_email;
|
|
|
|
313
|
+ }
|
|
|
|
314
|
+ }
|
|
|
|
315
|
+ }
|
|
|
|
316
|
+ //过滤电话
|
|
|
|
317
|
+ if (!empty($config['filter_mobiles'])) {
|
|
|
|
318
|
+ foreach ($config['filter_mobiles'] as $filter_mobile) {
|
|
|
|
319
|
+ if (Str::contains(strtolower($phone), strtolower($filter_mobile))) {
|
|
|
|
320
|
+ return '过滤电话:' . $filter_mobile;
|
|
|
|
321
|
+ }
|
|
|
|
322
|
+ }
|
|
|
|
323
|
+ }
|
|
|
|
324
|
+ //过滤姓名
|
|
|
|
325
|
+ if (!empty($config['filter_names'])) {
|
|
|
|
326
|
+ foreach ($config['filter_names'] as $filter_name) {
|
|
|
|
327
|
+ if (Str::contains(strtolower($name), strtolower($filter_name))) {
|
|
|
|
328
|
+ return '过滤姓名:' . $filter_name;
|
|
|
|
329
|
+ }
|
|
|
|
330
|
+ }
|
|
|
|
331
|
+ }
|
|
|
|
332
|
+
|
|
|
|
333
|
+ return '';
|
|
|
|
334
|
+ }
|
|
|
|
335
|
+
|
|
|
|
336
|
+ /**
|
|
222
|
* 获取国家随机ip
|
337
|
* 获取国家随机ip
|
|
223
|
* @param $country_name
|
338
|
* @param $country_name
|
|
224
|
* @return mixed|string
|
339
|
* @return mixed|string
|