|
...
|
...
|
@@ -11,9 +11,13 @@ namespace App\Console\Commands\Inquiry; |
|
|
|
use App\Helper\Translate;
|
|
|
|
use App\Helper\Validate;
|
|
|
|
use App\Models\Inquiry\InquiryInfo;
|
|
|
|
use App\Models\Project\InquiryFilterConfig;
|
|
|
|
use App\Models\Project\Project;
|
|
|
|
use App\Services\InquiryRelayService;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Illuminate\Support\Facades\URL;
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
|
|
|
class SyncInquiryRelay extends Command
|
|
|
|
{
|
|
...
|
...
|
@@ -65,10 +69,6 @@ class SyncInquiryRelay extends Command |
|
|
|
if (isset($result['status']) && $result['status'] == 200) {
|
|
|
|
$data = $result['data'] ?? [];
|
|
|
|
foreach ($data as $item) {
|
|
|
|
if (substr($item['phone'], 0, 3) == '+86') {
|
|
|
|
//+86区号过滤
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$this->saveDate($item, $item['source_type']);
|
|
|
|
}
|
|
|
|
}
|
|
...
|
...
|
@@ -214,11 +214,126 @@ class SyncInquiryRelay extends Command |
|
|
|
$phone_status = $check_phone ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$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 = md5($data['email'] . $data['message']);
|
|
|
|
|
|
|
|
//过滤数据:邮箱内容唯一性,国家,ip,内容,来源,邮箱,电话,姓名
|
|
|
|
$remark = $this->inquiryFilter($unique_sign, $country, $data['ip'], $data['message'], $data['refer'], $data['email'], $data['phone'], $data['name']);
|
|
|
|
$status = $remark ? InquiryInfo::STATUS_INVALID : InquiryInfo::STATUS_INIT;
|
|
|
|
|
|
|
|
$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);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 过滤数据
|
|
|
|
* @param $unique_sign
|
|
|
|
* @param $country
|
|
|
|
* @param $ip
|
|
|
|
* @param $message
|
|
|
|
* @param $refer
|
|
|
|
* @param $email
|
|
|
|
* @param $phone
|
|
|
|
* @param $name
|
|
|
|
* @return string
|
|
|
|
* @author Akun
|
|
|
|
* @date 2025/03/06 15:09
|
|
|
|
*/
|
|
|
|
public function inquiryFilter($unique_sign, $country, $ip, $message, $refer, $email, $phone, $name)
|
|
|
|
{
|
|
|
|
//邮箱和内容唯一性
|
|
|
|
if (InquiryInfo::where('unique_sign', $unique_sign)->first()) {
|
|
|
|
return '邮箱内容重复过滤';
|
|
|
|
}
|
|
|
|
|
|
|
|
//国内ip
|
|
|
|
if ($country == '中国') {
|
|
|
|
return '中国内地过滤';
|
|
|
|
}
|
|
|
|
|
|
|
|
//QQ邮箱
|
|
|
|
if (substr($email, -6) == 'qq.com') {
|
|
|
|
return 'QQ邮箱过滤';
|
|
|
|
}
|
|
|
|
|
|
|
|
//86开头的手机号
|
|
|
|
$num_phone = preg_replace('/\D/', '', $phone) ?? ''; // \D 匹配所有非数字字符
|
|
|
|
if (substr($num_phone, 0, 2) == '86') {
|
|
|
|
return '86开头手机号过滤';
|
|
|
|
}
|
|
|
|
|
|
|
|
//公共规则
|
|
|
|
$config = InquiryFilterConfig::getCacheInfoByProjectId(Project::DEMO_PROJECT_ID);
|
|
|
|
//过滤国家
|
|
|
|
if (!empty($config['filter_countries']) && in_array($country, $config['filter_countries'])) {
|
|
|
|
return '过滤国家:' . $country;
|
|
|
|
}
|
|
|
|
//过滤ip
|
|
|
|
if (!empty($config['black_ips']) && in_array($ip, $config['black_ips'])) {
|
|
|
|
return '过滤黑名单IP:' . $ip;
|
|
|
|
}
|
|
|
|
//过滤内容关键字
|
|
|
|
if (!empty($config['filter_contents'])) {
|
|
|
|
foreach ($config['filter_contents'] as $filter_content) {
|
|
|
|
//中文直接包含
|
|
|
|
if (preg_match("/^[\x{4e00}-\x{9fa5}]+$/u", $filter_content)) {
|
|
|
|
if (Str::contains($message, $filter_content)) {
|
|
|
|
return '过滤内容:' . $filter_content;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//英文要指定词才过滤
|
|
|
|
if (preg_match("/\b" . preg_quote($filter_content, "/") . "\b/i", $message)) {
|
|
|
|
return '过滤内容:' . $filter_content;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//过滤内容是否允许包含链接
|
|
|
|
if (isset($config['is_allow_link']) && $config['is_allow_link'] == 0) {
|
|
|
|
if (Str::contains(strtolower($message), ['http://', 'https://', 'www.'])) {
|
|
|
|
return '内容包含链接过滤';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//过滤来源
|
|
|
|
if (!empty($config['filter_referers'])) {
|
|
|
|
//只比较path路径
|
|
|
|
$paths = array_map(function ($v) {
|
|
|
|
return trim(parse_url(Url::to($v), PHP_URL_PATH), '/');
|
|
|
|
}, $config['filter_referers']);
|
|
|
|
|
|
|
|
if (in_array(trim(parse_url($refer, PHP_URL_PATH), '/'), $paths)) {
|
|
|
|
return '过滤来源链接:' . $refer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//过滤邮箱
|
|
|
|
if (!empty($config['filter_emails'])) {
|
|
|
|
foreach ($config['filter_emails'] as $filter_email) {
|
|
|
|
if (Str::contains(strtolower($email), strtolower($filter_email))) {
|
|
|
|
return '过滤邮箱:' . $filter_email;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//过滤电话
|
|
|
|
if (!empty($config['filter_mobiles'])) {
|
|
|
|
foreach ($config['filter_mobiles'] as $filter_mobile) {
|
|
|
|
if (Str::contains(strtolower($phone), strtolower($filter_mobile))) {
|
|
|
|
return '过滤电话:' . $filter_mobile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//过滤姓名
|
|
|
|
if (!empty($config['filter_names'])) {
|
|
|
|
foreach ($config['filter_names'] as $filter_name) {
|
|
|
|
if (Str::contains(strtolower($name), strtolower($filter_name))) {
|
|
|
|
return '过滤姓名:' . $filter_name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取国家随机ip
|
|
|
|
* @param $country_name
|
|
|
|
* @return mixed|string
|
...
|
...
|
|