InquiryRelayService.php
5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2025/2/13
* Time: 11:01
*/
namespace App\Services;
use Illuminate\Support\Facades\Log;
/**
* Class InquiryRelayService
* @package App\Services
*/
class InquiryRelayService
{
/**
* 获取询盘
* @return mixed|string
*/
public function getInquiryRelay()
{
$date = date('Y-m-d');
$token = md5($date . 'qqs');
$url = 'https://www.globalso.site/api/external-interface/echo_inquriy/d1483a8e57cb485a?date=' . $date . '&token=' . $token . '&type=2';
$result = http_get($url);
return $result;
}
/**
* 获取询盘
* @param $id
* @return array|bool
*/
public function getInquirySzcm($id)
{
try {
// 获取数据
$url = "https://api.szcmapi.com/get_inquiry.aspx?id=" . $id;
$json = $this->szcmCurl($url);
// 兼容过去到的数据, 比较乱
$json = trim(str_replace("\r\n", '\n', (string)$json));
$json = str_replace('3/4"', '3/4', $json);
$json = str_replace('"Steklopribor"', 'Steklopribor', $json);
$json = str_replace('"Net30 days"', 'Net30 days', $json);
$json = trim($json);
$json = str_replace("\n", '', $json);
$array = json_decode($json, true);
if (empty($array))
return false;
// 整合最终数据
$title = base64_decode($array['title']);
$title = str_replace("'", '', $title);
$title = html_entity_decode($title, ENT_QUOTES, 'UTF-8');
$title = str_replace("'", '', $title);
$message = html_entity_decode(addslashes(base64_decode($array['Message'])), ENT_QUOTES, 'UTF-8');
$message = str_replace("'", '', $message);
$email = trim($array['Email']);
$name = html_entity_decode($array['Name'], ENT_QUOTES, 'UTF-8');
$name = str_replace("'", '', $name);
$result = [
'image' => $array['image'] ?: '',
'time' => $array['submit_time'] ?: date('Y-m-d H:i:s'),
'name' => $name,
'email' => $email,
'phone' => $array['Phone'] ?: '',
'refer' => $array['refer'] ?: '',
'message' => $message,
'ip' => $array['submit_ip'] ?: '',
'source_address' => 'api.szcmapi.com',
'title' => $title,
'submit_country' => $array['submit_country'] ?: '',
'origin_key' => $array['Id'],
];
return $result;
} catch (\Exception $e) {
Log::error('获取询盘: getInquirySzcm : ' . $id . ', error: ' . $e->getMessage());
return false;
}
}
/**
* @param $url
* @return bool|string
*/
public function szcmCurl($url)
{
$agent = 'ChuangMao_API_Bot';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSLVERSION, 'all');
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
/**
* 获取findsupply询盘
* @param $url
* @return array
* @throws \Exception
* @author Akun
* @date 2025/03/04 10:48
*/
public function getInquiryFs($url)
{
$re = curl_get($url);
$result = [];
$next_page_url = '';
if (isset($re['status']) && $re['status'] == 200) {
$next_page_url = $re['data']['next_page_url'];
foreach ($re['data']['data'] as $v) {
$dateTime = new \DateTime($v['created_at']);
$time = $dateTime->format('Y-m-d H:i:s');
$result[] = [
'time' => $time,
'name' => $v['NAME'] ?: '',
'email' => $v['email'] ?: '',
'phone' => $v['phone_number'] ?: '',
'refer' => $v['page_url'] ?: '',
'message' => $v['content'] ?: '',
'ip' => $v['ip'] ?: '',
'source_address' => 'www.findsupply.com',
'title' => $v['products_title'] ?: '',
'submit_country' => $v['country'] ?: ''
];
}
}
return ['next_page_url' => $next_page_url, 'data' => $result];
}
########################################################################################################################
# 询盘结束, 同步项目及路由 #
########################################################################################################################
}