作者 lyh

Merge branch 'master' of http://47.244.231.31:8099/zhl/globalso-v6 into master-server

... ... @@ -62,7 +62,7 @@ class InquiryDelay extends Command
* @time :2023/7/13 14:39
*/
public function inquiryForward($post_data){
$url = 'https://form.globalso.com/api/external-interface/add/fa043f9cbec6b38f';
$url = 'https://www.globalso.site/api/external-interface/add/fa043f9cbec6b38f';
$post_data_new = [];
$post_data_new['refer'] = $post_data['url'];
$post_data_new['name'] = $post_data['name'];
... ...
... ... @@ -57,8 +57,11 @@ class SyncInquiryProject extends Command
*/
public function handle()
{
echo '开始同步v5' . PHP_EOL;
$this->syncGloV5();
echo '开始同步v6' . PHP_EOL;
$this->syncGloV6();
echo '删除过期数据' . PHP_EOL;
$this->deleteExpire();
return true;
}
... ... @@ -73,12 +76,14 @@ class SyncInquiryProject extends Command
$channel = Channel::pluck('contact_mobile', 'id')->toArray();
foreach ($result as $key=>$val)
{
echo '同步项目:' . $val['postid'] . ' - ' . $val['company'] . PHP_EOL;
// 记录渠道商, 如果渠道有问题, 记录日志, 跳过当前项目, 处理数据后, 第二天再重新同步
$channel_flag = false;
$channel_tmp = [];
foreach ($val['agent'] as $v) {
$channel_id = array_search($v, $channel);
if (empty($channel_id)) {
$this->log('ERROR 代理商找不到不记录当前项目, 代理商手机号码:' . $v);
$channel_flag = true;
break;
}
... ... @@ -106,16 +111,32 @@ class SyncInquiryProject extends Command
*/
public function syncGloV5Route($project_id, $route_domain)
{
$result = http_get($route_domain . 'k_u_api.php');
try{
$result = http_get($route_domain . 'k_u_api.php');
if (empty($result)) {
$this->log('syncGloV5Route 未获取到路由信息:' . $project_id . ', 路由获取地址:' . $route_domain . 'k_u_api.php');
return false;
}
} catch (\Exception $e) {
$this->log('syncGloV5Route 未获取到路由信息:' . $project_id . ', 路由获取地址:' . $route_domain . 'k_u_api.php' . ', 错误信息:' . $e->getMessage());
echo 'syncGloV5Route 未获取到路由信息:' . $project_id . ', 路由获取地址:' . $route_domain . 'k_u_api.php' . ', 错误信息:' . $e->getMessage() . PHP_EOL;
return false;
}
foreach ($result as $key=>$val) {
try {
$tmp = explode('|', $val);
$url_tmp = parse_url($tmp[0]);
$route = trim($url_tmp['path'], '/');
$title = str_replace('+', ' ', $tmp[1]);
if (strlen($title) > 200 || strlen($route) > 200) {
$this->log('syncGloV5Route 路由或标题过长,无效记录');
continue;
}
InquiryProjectRoute::saveProjectRoute($project_id, $title, $route);
} catch (\Exception $e) {
$this->log('syncGloV5Route 解析路径:' . $val . ', 错误信息:' . $e->getMessage());
echo 'syncGloV5Route 解析路径:' . $val . ', 错误信息:' . $e->getMessage() . PHP_EOL;
}
}
return true;
... ... @@ -140,6 +161,7 @@ class SyncInquiryProject extends Command
// 获取所有项目域名
$domains = DomainInfo::whereIn('project_id', $project->pluck('id')->toArray())->pluck('domain', 'project_id')->toArray();
foreach ($project as $key=>$val) {
echo '同步项目:' . $val->id . ' - ' . $val->title . PHP_EOL;
// 过滤暂停优化项目, 映射类型2, model没有定义常量
if (in_array(2, $val->level))
continue;
... ... @@ -167,6 +189,7 @@ class SyncInquiryProject extends Command
// 产品数量会比较多, 所以使用分页 同步数据
$id = 0;
while (true) {
echo '同步项目路由:' . $id . PHP_EOL;
$product = Product::where('status', Product::STATUS_ON)->where('id', '>', $id)->orderBy('id', 'asc')->limit(1000)->get(['id', 'title', 'route']);
if ($product->isEmpty())
break;
... ...
... ... @@ -243,7 +243,7 @@ class postInquiry extends Command
'source' => 5,
];
$result = Http::withoutVerifying()->timeout(30)->post('https://form.globalso.com/api/external-interface/add/fa043f9cbec6b38f', $data);
$result = Http::withoutVerifying()->timeout(30)->post('https://www.globalso.site/api/external-interface/add/fa043f9cbec6b38f', $data);
$res = $result->json();
//兼容接口返回格式
if (!empty($res['data'][0]['status'])) {
... ... @@ -255,7 +255,7 @@ class postInquiry extends Command
$log->remark = mb_substr($res['message'] ?? '', 0, 200);
$log->save();
Log::channel('inquiry_relay')->error('inquiry_relay v4|v5 inquiry error', [$result->body(), 'https://form.globalso.com/api/external-interface/add/fa043f9cbec6b38f', $data]);
Log::channel('inquiry_relay')->error('inquiry_relay v4|v5 inquiry error', [$result->body(), 'https://www.globalso.site/api/external-interface/add/fa043f9cbec6b38f', $data]);
return false;
}
return true;
... ...
... ... @@ -17,7 +17,7 @@ use GuzzleHttp\Exception\GuzzleException;
class FormGlobalsoApi
{
//接口地址
protected $url = 'https://form.globalso.com';
protected $url = 'https://www.globalso.site';
/**
* 设置询盘通知
... ... @@ -179,7 +179,7 @@ class FormGlobalsoApi
'num'=>15,
];
$queryString = http_build_query($data);
$url = "https://form.globalso.com/api/external-interface/domain_con/15243d63ed5a5738?".$queryString;
$url = "https://www.globalso.site/api/external-interface/domain_con/15243d63ed5a5738?".$queryString;
try {
$res = http_get($url,['charset=utf-8']);
} catch (\Exception | GuzzleException $e) {
... ... @@ -207,7 +207,7 @@ class FormGlobalsoApi
'sta_date'=>$month,
];
$queryString = http_build_query($data);
$url = 'https://form.globalso.com/api/external-interface/country_con/15243d63ed5a5738?'.$queryString;
$url = 'https://www.globalso.site/api/external-interface/country_con/15243d63ed5a5738?'.$queryString;
$res = http_get($url,['charset=utf-8']);
echo date('Y-m-d H:i:s') . '数据:'.json_encode($res) . PHP_EOL;
return $res;
... ...
... ... @@ -501,7 +501,7 @@ if (!function_exists('getInquiryInformation')) {
{
$token = md5($domain . date("Y-m-d"));
$source = '1,3';
$url = "https://form.globalso.com/api/external-interface/country_con/15243d63ed5a5738?domain={$domain}&token={$token}&source={$source}&sta_date={$sta_date}";
$url = "https://www.globalso.site/api/external-interface/country_con/15243d63ed5a5738?domain={$domain}&token={$token}&source={$source}&sta_date={$sta_date}";
$client = new Client(['verify' => false]);
$http = $client->get($url);
$data = [];
... ...
... ... @@ -172,7 +172,7 @@ class InquiryInfoLogic extends BaseLogic
* @time :2023/7/13 14:39
*/
public function inquiryForward($post_data){
$url = 'https://form.globalso.com/api/external-interface/add/fa043f9cbec6b38f';
$url = 'https://www.globalso.site/api/external-interface/add/fa043f9cbec6b38f';
$post_data_new = [];
$post_data_new['refer'] = $post_data['url'];
$post_data_new['name'] = $post_data['name'];
... ...
... ... @@ -153,4 +153,16 @@ class DomainInfo extends Base
$value = Arr::s2a($value);
return $value;
}
public static function getCacheInfoByProjectId($project_id){
$cache_key = 'DOMAIN_INFO_BY_PROJECT_ID_' . $project_id;
$data = Cache::get($cache_key);
if(!$data){
$data = DomainInfo::where('project_id', $project_id)->first();
if($data){
Cache::put($cache_key, $data, 3600);
}
}
return $data;
}
}
... ...
... ... @@ -23,7 +23,7 @@ class InquiryRelayService
{
$date = date('Y-m-d');
$token = md5($date . 'qqs');
$url = 'https://form.globalso.com/api/external-interface/echo_inquriy/d1483a8e57cb485a?date=' . $date . '&token=' . $token . '&type=2';
$url = 'https://www.globalso.site/api/external-interface/echo_inquriy/d1483a8e57cb485a?date=' . $date . '&token=' . $token . '&type=2';
$result = http_get($url);
return $result;
}
... ... @@ -105,4 +105,8 @@ class InquiryRelayService
curl_close($ch);
return $result;
}
########################################################################################################################
# 询盘结束, 同步项目及路由 #
########################################################################################################################
}
\ No newline at end of file
... ...
... ... @@ -29,7 +29,7 @@ class SyncService
public function projectAcceptAddress($project_id = 0)
{
try {
$url = 'https://form.globalso.com/api/globalsov6';
$url = 'https://www.globalso.site/api/globalsov6';
// 项目信息
$project = Project::with('deploy_build')->with('deploy_optimize')->where(['id'=>$project_id])->first();
// 不满足条件 不同步到表单系统
... ...
... ... @@ -75,7 +75,7 @@ class SyncSubmitTaskService
}
//域名 过滤国家或ip
$domain_info = DomainInfo::where('project_id', $project['id'])->first();
$domain_info = DomainInfo::getCacheInfoByProjectId($project['id']);
if(!empty($domain_info['not_allow_country'])){
$not_allow_countries = CountryCode::whereIn('id', $domain_info['not_allow_country'])->pluck('c_name')->toArray();
if(in_array($data['country'], $not_allow_countries)){
... ... @@ -88,9 +88,11 @@ class SyncSubmitTaskService
}
}
$time = time();
if(!ProjectServer::useProject($project['id'])){
return false;
}
echo date('Y-m-d H:i:s') . ' | useProject time:' . (time() - $time) . PHP_EOL;
$action = $task['type'];
... ... @@ -106,7 +108,7 @@ class SyncSubmitTaskService
}
$filed == 'email' && $action = 'subscribe';
}
$handler = new self();
return $handler->$action($data, $date, $task['id'], $task['traffic']);
}
... ... @@ -297,6 +299,17 @@ class SyncSubmitTaskService
if(!$ip){
return '';
}
// $client = new \GuzzleHttp\Client();
// $res = $client->request('GET', "http://ip.globalso.com?ip=".$ip, [
// 'proxy' => env('CURL_PROXY'), // 代理服务器地址和端口号
// ]);
// if($res->getStatusCode() == 200){
// return $res->getBody()->getContents();
// }else{
// return '';
// }
$res = Http::withoutVerifying()->get('http://ip.globalso.com', ['ip' => $ip]);
if($res->status() == 200){
return $res->body();
... ... @@ -334,7 +347,9 @@ class SyncSubmitTaskService
if($ip == "127.0.0.1"){
throw new InquiryFilterException('127.0.0.1过滤');
}
$time = time();
$country = self::getCountryByIp($ip);
echo date('Y-m-d H:i:s') . ' | getCountryByIp time:' . (time() - $time) . PHP_EOL;
//访问记录过滤国内
if ($type == SyncSubmitTask::TYPE_VISIT && $country == "中国" && !$project->is_record_china_visit){
throw new InquiryFilterException('中国内地过滤');
... ...