作者 zhl

u

... ... @@ -7,6 +7,7 @@
*/
namespace App\Console\Commands\Test;
use App\Helper\Common;
use App\Models\Blog\Blog;
use App\Models\Devops\ServerConfig;
use App\Models\File\Image;
... ... @@ -15,6 +16,7 @@ use App\Models\Manage\Dept;
use App\Models\Manage\EntryPosition;
use App\Models\Manage\ManageHr;
use App\Services\ProjectServer;
use App\Services\SyncService;
use GuzzleHttp\Client;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
... ... @@ -75,6 +77,14 @@ class Demo extends Command
*/
public function handle()
{
$result = app(SyncService::class)->projectAcceptAddress(1);
dd($result);
$data = [
'key' => 'productkey_keyword',
'keywords' => 'apple watch'
];
$result = Common::send_openai_msg('v2/openai_chat', $data);
dd();
$string = 'demo.globalso.site/';
$domain_array = parse_url($string);
$domain = $domain_array['host'] ?? $domain_array['path'];
... ...
... ... @@ -7,6 +7,7 @@ use App\Models\Devops\ServerConfig;
use App\Models\Project\ProjectRenew;
use App\Models\User\ProjectMenu;
use App\Models\User\ProjectRole;
use App\Services\SyncService;
use App\Utils\HttpUtils;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Arr as SupArr;
... ... @@ -119,6 +120,7 @@ class ProjectLogic extends BaseLogic
DB::rollBack();
$this->fail('请填写完整后再提交');
}
app(SyncService::class)->projectAcceptAddress($this->param['id']);
return $this->success();
}
... ...
... ... @@ -5,6 +5,7 @@ namespace App\Http\Logic\Bside\Setting;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\WebSetting\WebSettingReceiving;
use App\Models\WebSetting\WebSettingText;
use App\Services\SyncService;
class WebSettingReceivingLogic extends BaseLogic
{
... ... @@ -45,6 +46,7 @@ class WebSettingReceivingLogic extends BaseLogic
}catch (\Exception $e){
$this->fail('error');
}
app(SyncService::class)->projectAcceptAddress($this->user['project_id']);
return $this->success();
}
}
... ...
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2023/10/26
* Time: 17:19
*/
namespace App\Services;
use App\Models\Domain\DomainInfo;
use App\Models\Project\Project;
use App\Models\WebSetting\WebSettingReceiving;
use Illuminate\Support\Facades\Log;
/**
* TODO 同步数据到其他平台
* Class SyncService
* @package App\Services
*/
class SyncService extends BaseService
{
/**
* 同步信息到表单系统
* TODO 项目已经上线 && 已经有正式域名 && 用户设置收件邮箱或者手机号码
* @param int $project_id
* @return mixed
*/
public function projectAcceptAddress($project_id = 0)
{
try {
$url = 'https://form.globalso.com/api/globalsov6';
// 项目信息
$project = Project::with('deploy_build')->with('deploy_optimize')->where(['id'=>$project_id])->first();
// 收件设置信息
ProjectServer::useProject($project_id);
$receive = WebSettingReceiving::where(['project_id' => $project_id])->get();
// 不满足条件 不同步到表单系统
if (FALSE == in_array($project->type, [Project::TYPE_TWO, Project::TYPE_THREE]) || empty($project->deploy_optimize->domain) || $receive->isEmpty()) {
return false;
}
// 生产域名
$domain = (new DomainInfo())->getDomain($project->deploy_optimize->domain);
// 处理收件信息
$email = $phone = [];
foreach ($receive as $value) {
if ($value->type == 1)
array_push($email, $value->values);
if ($value->type == 2)
array_push($phone, $value->values);
}
// 请求参数
$data = [
'id' => $project_id,
'company_name' => $project->company,
'plan' => Project::planMap()[$project->deploy_build->plan],
'emails' => implode(',', $email),
'phones' => implode(',', $phone),
'main_url' => $domain,
'test_url' => $project->deploy_build->test_domain,
'token' => md5($project_id . 'qqs' . date('Y-m-d'))
];
list($code, $result) = $this->curlRequest($url, $data);
Log::info('同步收件信息至表单系统: 项目ID:' . $project_id . ', data: ' . var_export($data, true) . ', result: ' . $result);
return true;
} catch (\Exception $e) {
Log::info('同步收件信息至表单系统: 项目ID:' . $project_id . ', error: ' . $e->getMessage());
return false;
}
}
/**
* @param $url
* @param $data
* @param string $method
* @param array $header
* @param int $time_out
* @return array
*/
public function curlRequest($url, $data, $method = 'POST', $header = [], $time_out = 60)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_TIMEOUT, $time_out);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
if ($data)
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array_merge([
'Expect:',
'Content-type: application/json',
'Accept: application/json',
], $header)
);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
$response = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return [$code, $response];
}
}
\ No newline at end of file
... ...