作者 周海龙

合并分支 'zhl' 到 'master'

Zhl



查看合并请求 !24
@@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
7 */ 7 */
8 namespace App\Console\Commands\Test; 8 namespace App\Console\Commands\Test;
9 9
  10 +use App\Helper\Common;
10 use App\Models\Blog\Blog; 11 use App\Models\Blog\Blog;
11 use App\Models\Devops\ServerConfig; 12 use App\Models\Devops\ServerConfig;
12 use App\Models\File\Image; 13 use App\Models\File\Image;
@@ -15,6 +16,7 @@ use App\Models\Manage\Dept; @@ -15,6 +16,7 @@ use App\Models\Manage\Dept;
15 use App\Models\Manage\EntryPosition; 16 use App\Models\Manage\EntryPosition;
16 use App\Models\Manage\ManageHr; 17 use App\Models\Manage\ManageHr;
17 use App\Services\ProjectServer; 18 use App\Services\ProjectServer;
  19 +use App\Services\SyncService;
18 use GuzzleHttp\Client; 20 use GuzzleHttp\Client;
19 use Illuminate\Console\Command; 21 use Illuminate\Console\Command;
20 use Illuminate\Support\Facades\DB; 22 use Illuminate\Support\Facades\DB;
@@ -75,6 +77,14 @@ class Demo extends Command @@ -75,6 +77,14 @@ class Demo extends Command
75 */ 77 */
76 public function handle() 78 public function handle()
77 { 79 {
  80 + $result = app(SyncService::class)->projectAcceptAddress(1);
  81 + dd($result);
  82 + $data = [
  83 + 'key' => 'productkey_keyword',
  84 + 'keywords' => 'apple watch'
  85 + ];
  86 + $result = Common::send_openai_msg('v2/openai_chat', $data);
  87 + dd();
78 $string = 'demo.globalso.site/'; 88 $string = 'demo.globalso.site/';
79 $domain_array = parse_url($string); 89 $domain_array = parse_url($string);
80 $domain = $domain_array['host'] ?? $domain_array['path']; 90 $domain = $domain_array['host'] ?? $domain_array['path'];
@@ -7,6 +7,7 @@ use App\Models\Devops\ServerConfig; @@ -7,6 +7,7 @@ use App\Models\Devops\ServerConfig;
7 use App\Models\Project\ProjectRenew; 7 use App\Models\Project\ProjectRenew;
8 use App\Models\User\ProjectMenu; 8 use App\Models\User\ProjectMenu;
9 use App\Models\User\ProjectRole; 9 use App\Models\User\ProjectRole;
  10 +use App\Services\SyncService;
10 use App\Utils\HttpUtils; 11 use App\Utils\HttpUtils;
11 use GuzzleHttp\Exception\GuzzleException; 12 use GuzzleHttp\Exception\GuzzleException;
12 use Illuminate\Support\Arr as SupArr; 13 use Illuminate\Support\Arr as SupArr;
@@ -119,6 +120,7 @@ class ProjectLogic extends BaseLogic @@ -119,6 +120,7 @@ class ProjectLogic extends BaseLogic
119 DB::rollBack(); 120 DB::rollBack();
120 $this->fail('请填写完整后再提交'); 121 $this->fail('请填写完整后再提交');
121 } 122 }
  123 + app(SyncService::class)->projectAcceptAddress($this->param['id']);
122 return $this->success(); 124 return $this->success();
123 } 125 }
124 126
@@ -5,6 +5,7 @@ namespace App\Http\Logic\Bside\Setting; @@ -5,6 +5,7 @@ namespace App\Http\Logic\Bside\Setting;
5 use App\Http\Logic\Bside\BaseLogic; 5 use App\Http\Logic\Bside\BaseLogic;
6 use App\Models\WebSetting\WebSettingReceiving; 6 use App\Models\WebSetting\WebSettingReceiving;
7 use App\Models\WebSetting\WebSettingText; 7 use App\Models\WebSetting\WebSettingText;
  8 +use App\Services\SyncService;
8 9
9 class WebSettingReceivingLogic extends BaseLogic 10 class WebSettingReceivingLogic extends BaseLogic
10 { 11 {
@@ -45,6 +46,7 @@ class WebSettingReceivingLogic extends BaseLogic @@ -45,6 +46,7 @@ class WebSettingReceivingLogic extends BaseLogic
45 }catch (\Exception $e){ 46 }catch (\Exception $e){
46 $this->fail('error'); 47 $this->fail('error');
47 } 48 }
  49 + app(SyncService::class)->projectAcceptAddress($this->user['project_id']);
48 return $this->success(); 50 return $this->success();
49 } 51 }
50 } 52 }
  1 +<?php
  2 +/**
  3 + * Created by PhpStorm.
  4 + * User: zhl
  5 + * Date: 2023/10/26
  6 + * Time: 17:19
  7 + */
  8 +namespace App\Services;
  9 +
  10 +use App\Models\Domain\DomainInfo;
  11 +use App\Models\Project\Project;
  12 +use App\Models\WebSetting\WebSettingReceiving;
  13 +use Illuminate\Support\Facades\Log;
  14 +
  15 +/**
  16 + * TODO 同步数据到其他平台
  17 + * Class SyncService
  18 + * @package App\Services
  19 + */
  20 +class SyncService extends BaseService
  21 +{
  22 + /**
  23 + * 同步信息到表单系统
  24 + * TODO 项目已经上线 && 已经有正式域名 && 用户设置收件邮箱或者手机号码
  25 + * @param int $project_id
  26 + * @return mixed
  27 + */
  28 + public function projectAcceptAddress($project_id = 0)
  29 + {
  30 + try {
  31 + $url = 'https://form.globalso.com/api/globalsov6';
  32 + // 项目信息
  33 + $project = Project::with('deploy_build')->with('deploy_optimize')->where(['id'=>$project_id])->first();
  34 +
  35 + // 收件设置信息
  36 + ProjectServer::useProject($project_id);
  37 + $receive = WebSettingReceiving::where(['project_id' => $project_id])->get();
  38 +
  39 + // 不满足条件 不同步到表单系统
  40 + if (FALSE == in_array($project->type, [Project::TYPE_TWO, Project::TYPE_THREE]) || empty($project->deploy_optimize->domain) || $receive->isEmpty()) {
  41 + return false;
  42 + }
  43 +
  44 + // 生产域名
  45 + $domain = (new DomainInfo())->getDomain($project->deploy_optimize->domain);
  46 +
  47 + // 处理收件信息
  48 + $email = $phone = [];
  49 + foreach ($receive as $value) {
  50 + if ($value->type == 1)
  51 + array_push($email, $value->values);
  52 + if ($value->type == 2)
  53 + array_push($phone, $value->values);
  54 + }
  55 + // 请求参数
  56 + $data = [
  57 + 'id' => $project_id,
  58 + 'company_name' => $project->company,
  59 + 'plan' => Project::planMap()[$project->deploy_build->plan],
  60 + 'emails' => implode(',', $email),
  61 + 'phones' => implode(',', $phone),
  62 + 'main_url' => $domain,
  63 + 'test_url' => $project->deploy_build->test_domain,
  64 + 'token' => md5($project_id . 'qqs' . date('Y-m-d'))
  65 + ];
  66 + list($code, $result) = $this->curlRequest($url, $data);
  67 + Log::info('同步收件信息至表单系统: 项目ID:' . $project_id . ', data: ' . var_export($data, true) . ', result: ' . $result);
  68 + return true;
  69 + } catch (\Exception $e) {
  70 + Log::info('同步收件信息至表单系统: 项目ID:' . $project_id . ', error: ' . $e->getMessage());
  71 + return false;
  72 + }
  73 + }
  74 +
  75 + /**
  76 + * @param $url
  77 + * @param $data
  78 + * @param string $method
  79 + * @param array $header
  80 + * @param int $time_out
  81 + * @return array
  82 + */
  83 + public function curlRequest($url, $data, $method = 'POST', $header = [], $time_out = 60)
  84 + {
  85 + $ch = curl_init();
  86 + curl_setopt($ch, CURLOPT_TIMEOUT, $time_out);
  87 + curl_setopt($ch, CURLOPT_URL, $url);
  88 + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  89 + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  90 + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  91 + if ($data)
  92 + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
  93 + curl_setopt($ch, CURLOPT_HTTPHEADER, array_merge([
  94 + 'Expect:',
  95 + 'Content-type: application/json',
  96 + 'Accept: application/json',
  97 + ], $header)
  98 + );
  99 + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
  100 + $response = curl_exec($ch);
  101 + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  102 + curl_close($ch);
  103 + return [$code, $response];
  104 + }
  105 +}