正在显示
3 个修改的文件
包含
271 行增加
和
1 行删除
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * Created by PhpStorm. | ||
| 4 | + * User: zhl | ||
| 5 | + * Date: 2025/2/13 | ||
| 6 | + * Time: 16:45 | ||
| 7 | + */ | ||
| 8 | +namespace App\Console\Commands\Inquiry; | ||
| 9 | + | ||
| 10 | +use App\Services\InquiryRelayService; | ||
| 11 | +use Illuminate\Console\Command; | ||
| 12 | + | ||
| 13 | +class SyncInquiryRelay extends Command | ||
| 14 | +{ | ||
| 15 | + /** | ||
| 16 | + * The name and signature of the console command. | ||
| 17 | + * | ||
| 18 | + * @var string | ||
| 19 | + */ | ||
| 20 | + protected $signature = 'sync_inquiry_relay'; | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * The console command description. | ||
| 24 | + * | ||
| 25 | + * @var string | ||
| 26 | + */ | ||
| 27 | + protected $description = '同步询盘信息:站群询盘,'; | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * Create a new command instance. | ||
| 31 | + * | ||
| 32 | + * @return void | ||
| 33 | + */ | ||
| 34 | + public function __construct() | ||
| 35 | + { | ||
| 36 | + parent::__construct(); | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + /** | ||
| 40 | + * @return bool | ||
| 41 | + */ | ||
| 42 | + public function handle() | ||
| 43 | + { | ||
| 44 | + $this->getInquiryForm(); | ||
| 45 | + $this->getInquirySzcm(); | ||
| 46 | + return true; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + /** | ||
| 50 | + * 获取表单系统中询盘信息 | ||
| 51 | + */ | ||
| 52 | + public function getInquiryForm() | ||
| 53 | + {} | ||
| 54 | + | ||
| 55 | + /** | ||
| 56 | + * 获取秋哥asp采集询盘信息 | ||
| 57 | + */ | ||
| 58 | + public function getInquirySzcm() | ||
| 59 | + { | ||
| 60 | + $serveice = new InquiryRelayService(); | ||
| 61 | + $result = $serveice->getInquirySzcm(1); | ||
| 62 | + dd($result); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + public function saveDate($data) | ||
| 66 | + { | ||
| 67 | + // 数据里面 可能没有 IP 这时候需要通过 submit_country 字段获取对应国家,在通过国家随机获取IP , 如果IP submit_country 都没有就原样记录 | ||
| 68 | + if (empty($data['ip'])) { | ||
| 69 | + | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + $country = file_get_contents("http://ip.globalso.com?ip=" . $data['ip']); | ||
| 73 | + } | ||
| 74 | +} |
| @@ -12,6 +12,12 @@ use App\Models\Base; | @@ -12,6 +12,12 @@ use App\Models\Base; | ||
| 12 | */ | 12 | */ |
| 13 | class InquiryInfo extends Base | 13 | class InquiryInfo extends Base |
| 14 | { | 14 | { |
| 15 | + /** | ||
| 16 | + * @var string 数据表 | ||
| 17 | + */ | ||
| 18 | + protected $table = 'gl_inquiry_info'; | ||
| 19 | + | ||
| 20 | + // TODO 之前的状态, 留下可以找到之前的程序 | ||
| 15 | const STATUS_ZERO = 0;//未转发 | 21 | const STATUS_ZERO = 0;//未转发 |
| 16 | const STATUS_ONE = 1;//无效 | 22 | const STATUS_ONE = 1;//无效 |
| 17 | 23 | ||
| @@ -21,5 +27,87 @@ class InquiryInfo extends Base | @@ -21,5 +27,87 @@ class InquiryInfo extends Base | ||
| 21 | 27 | ||
| 22 | const STATUS_FOUR = 4;//延时转发中 | 28 | const STATUS_FOUR = 4;//延时转发中 |
| 23 | 29 | ||
| 24 | - protected $table = 'gl_inquiry_info'; | 30 | + const STATUS_INIT = 0; |
| 31 | + const STATUS_FINISH = 1; | ||
| 32 | + const STATUS_INVALID = 2; | ||
| 33 | + const STATUS_FAIL = 9; | ||
| 34 | + | ||
| 35 | + | ||
| 36 | + const TYPE_SITE_GROUP = 1; | ||
| 37 | + const TYPE_ADS = 2; | ||
| 38 | + const TYPE_AI_SITE_GROUP = 3; | ||
| 39 | + const TYPE_SPIDER = 4; | ||
| 40 | + | ||
| 41 | + /** | ||
| 42 | + * 状态映射 | ||
| 43 | + * @return array | ||
| 44 | + */ | ||
| 45 | + public function statusMap() | ||
| 46 | + { | ||
| 47 | + return [ | ||
| 48 | + self::STATUS_INIT => '未处理', | ||
| 49 | + self::STATUS_FINISH => '已处理', | ||
| 50 | + self::STATUS_INVALID => '无效数据', | ||
| 51 | + self::STATUS_FAIL => '失败数据', | ||
| 52 | + ]; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + /** | ||
| 56 | + * 类型映射 | ||
| 57 | + * @return array | ||
| 58 | + */ | ||
| 59 | + public function typeMap() | ||
| 60 | + { | ||
| 61 | + return [ | ||
| 62 | + self::TYPE_SITE_GROUP => '站群询盘', | ||
| 63 | + self::TYPE_ADS => 'ads采集站询盘', | ||
| 64 | + self::TYPE_AI_SITE_GROUP => 'AI站群询盘', | ||
| 65 | + self::TYPE_SPIDER => '蜘蛛询盘', | ||
| 66 | + ]; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + /** | ||
| 70 | + * 创建新盘信息 | ||
| 71 | + * @param $name | ||
| 72 | + * @param $phone | ||
| 73 | + * @param $email | ||
| 74 | + * @param $ip | ||
| 75 | + * @param $country | ||
| 76 | + * @param $message | ||
| 77 | + * @param $message_cn | ||
| 78 | + * @param $type | ||
| 79 | + * @param $inquiry_date | ||
| 80 | + * @param $url | ||
| 81 | + * @param $url_title | ||
| 82 | + * @param $url_keyword | ||
| 83 | + * @param $message_sign | ||
| 84 | + * @param $origin_key | ||
| 85 | + * @param string $image | ||
| 86 | + * @return bool | ||
| 87 | + */ | ||
| 88 | + public function createInquiry($name, $phone, $email, $ip, $country, $message, $message_cn, $type, $inquiry_date, $url, $url_title, $url_keyword, $message_sign, $origin_key, $image = '') | ||
| 89 | + { | ||
| 90 | + try { | ||
| 91 | + $self = new self(); | ||
| 92 | + $self->name = $name; | ||
| 93 | + $self->phone = $phone; | ||
| 94 | + $self->email = $email; | ||
| 95 | + $self->ip = $ip; | ||
| 96 | + $self->country = $country; | ||
| 97 | + $self->message = $message; | ||
| 98 | + $self->message_cn = $message_cn; | ||
| 99 | + $self->type = $type; | ||
| 100 | + $self->inquiry_date = $inquiry_date; | ||
| 101 | + $self->url = $url; | ||
| 102 | + $self->url_title = $url_title; | ||
| 103 | + $self->url_keyword = $url_keyword; | ||
| 104 | + $self->image = $image; | ||
| 105 | + $self->origin_key = $origin_key; | ||
| 106 | + $self->message_sign = $message_sign; | ||
| 107 | + $self->save(); | ||
| 108 | + return true; | ||
| 109 | + } catch (\Exception $e) { | ||
| 110 | + return false; | ||
| 111 | + } | ||
| 112 | + } | ||
| 25 | } | 113 | } |
app/Services/InquiryRelayService.php
0 → 100644
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * Created by PhpStorm. | ||
| 4 | + * User: zhl | ||
| 5 | + * Date: 2025/2/13 | ||
| 6 | + * Time: 11:01 | ||
| 7 | + */ | ||
| 8 | +namespace App\Services; | ||
| 9 | + | ||
| 10 | +use Illuminate\Support\Facades\Log; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * Class InquiryRelayService | ||
| 14 | + * @package App\Services | ||
| 15 | + */ | ||
| 16 | +class InquiryRelayService | ||
| 17 | +{ | ||
| 18 | + /** | ||
| 19 | + * 获取询盘 | ||
| 20 | + * @return mixed|string | ||
| 21 | + */ | ||
| 22 | + public function getInquiryRelay() | ||
| 23 | + { | ||
| 24 | + $date = date('Y-m-d'); | ||
| 25 | + $token = md5($date . 'qqs'); | ||
| 26 | + $url = 'https://form.globalso.com/api/external-interface/echo_inquriy/d1483a8e57cb485a?date=' . $date . '&token=' . $token . '&type=2'; | ||
| 27 | + $result = http_get($url); | ||
| 28 | + return $result; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * 获取询盘 | ||
| 33 | + * @param $id | ||
| 34 | + * @return array|bool | ||
| 35 | + */ | ||
| 36 | + public function getInquirySzcm($id) | ||
| 37 | + { | ||
| 38 | + try { | ||
| 39 | + // 获取数据 | ||
| 40 | + $url = "https://api.szcmapi.com/get_inquiry.aspx?id=".$id; | ||
| 41 | + $json = $this->szcmCurl($url); | ||
| 42 | + // 兼容过去到的数据, 比较乱 | ||
| 43 | + $json = trim(str_replace("\r\n", '\n', (string) $json)); | ||
| 44 | + $json = str_replace('3/4"','3/4',$json); | ||
| 45 | + $json = str_replace('"Steklopribor"','Steklopribor',$json); | ||
| 46 | + $json = str_replace('"Net30 days"','Net30 days',$json); | ||
| 47 | + $json = trim($json); | ||
| 48 | + $json = str_replace("\n",'',$json); | ||
| 49 | + $array = json_decode($json,true); | ||
| 50 | + | ||
| 51 | + if (empty($array)) | ||
| 52 | + return false; | ||
| 53 | + | ||
| 54 | + // 整合最终数据 | ||
| 55 | + $title = base64_decode($array['title']); | ||
| 56 | + $title = str_replace("'",'',$title); | ||
| 57 | + $title = html_entity_decode($title, ENT_QUOTES, 'UTF-8'); | ||
| 58 | + $title = str_replace("'",'',$title); | ||
| 59 | + $message = html_entity_decode(addslashes(base64_decode($array['Message'])), ENT_QUOTES, 'UTF-8'); | ||
| 60 | + $message = str_replace("'",'',$message); | ||
| 61 | + $email = trim($array['Email']); | ||
| 62 | + $name = html_entity_decode($array['Name'], ENT_QUOTES, 'UTF-8'); | ||
| 63 | + $name = str_replace("'",'',$name); | ||
| 64 | + | ||
| 65 | + $result = [ | ||
| 66 | + 'image' => $array['image'] ?: '', | ||
| 67 | + 'time' => $array['submit_time'] ?: date('Y-m-d H:i:s'), | ||
| 68 | + 'name' => $name, | ||
| 69 | + 'email' => $email, | ||
| 70 | + 'phone' => $array['Phone'] ?: '', | ||
| 71 | + 'refer' => $array['refer'] ?: '', | ||
| 72 | + 'message' => $message, | ||
| 73 | + 'ip' => $array['submit_ip'] ?: '', | ||
| 74 | + 'source_address' => 'api.szcmapi.com', | ||
| 75 | + 'title' => $title, | ||
| 76 | + 'submit_country' => $array['submit_country'] ?: '', | ||
| 77 | + 'origin_key' => $array['Id'], | ||
| 78 | + ]; | ||
| 79 | + return $result; | ||
| 80 | + } catch (\Exception $e) { | ||
| 81 | + Log::error('获取询盘: getInquirySzcm : ' . $id . ', error: ' . $e->getMessage()); | ||
| 82 | + return false; | ||
| 83 | + } | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + /** | ||
| 87 | + * @param $url | ||
| 88 | + * @return bool|string | ||
| 89 | + */ | ||
| 90 | + public function szcmCurl($url) | ||
| 91 | + { | ||
| 92 | + $agent = 'ChuangMao_API_Bot'; | ||
| 93 | + $ch = curl_init($url); | ||
| 94 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
| 95 | + curl_setopt($ch, CURLOPT_HEADER, false); | ||
| 96 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | ||
| 97 | + curl_setopt($ch, CURLOPT_USERAGENT, $agent); | ||
| 98 | + curl_setopt($ch, CURLOPT_AUTOREFERER, true); | ||
| 99 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120); | ||
| 100 | + curl_setopt($ch, CURLOPT_TIMEOUT, 120); | ||
| 101 | + curl_setopt($ch, CURLOPT_MAXREDIRS, 10); | ||
| 102 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | ||
| 103 | + curl_setopt($ch, CURLOPT_SSLVERSION, 'all'); | ||
| 104 | + $result = curl_exec($ch); | ||
| 105 | + curl_close($ch); | ||
| 106 | + return $result; | ||
| 107 | + } | ||
| 108 | +} |
-
请 注册 或 登录 后发表评论