From 478e6066f23507bd120834a648e3ea34cb20bd13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=B8=9C=E4=BA=91?= Date: Tue, 26 Jul 2022 18:21:57 +0800 Subject: [PATCH] =?UTF-8?q?feat(utils):=20=E5=A2=9E=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李东云 --- publish/common.php | 30 +++++++++++++-- src/Utils/Service/EmailService.php | 62 ++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 src/Utils/Service/EmailService.php diff --git a/publish/common.php b/publish/common.php index cfb1179..d7f39b6 100644 --- a/publish/common.php +++ b/publish/common.php @@ -36,8 +36,8 @@ return [ ], 'app' => [ 'expire_time' => 30 * 24 * 60 * 60, - 'prefix_key' => 'token:' - ] + 'prefix_key' => 'token:', + ], ], // redis 补充配置 @@ -48,7 +48,7 @@ return [ env('APP_ENV', 'product') ), // 强烈建议按此格式划分 ], - + // account http请求配置 'http_request' => [ 'account' => [ @@ -56,5 +56,27 @@ return [ 'rpc_base_uri' => env('RPC_BASE_URI', ''), ], ], - + + // 第三方服务 + 'third_party' => [ + 'email' => [ + 'dsn' => 'smtp://account@luxcreo.ai:Qfsd8866@smtp.qiye.aliyun.com:465', + 'mailer_sender' => 'account@luxcreo.ai', // 发件邮箱 + 'mailer_sender_name' => 'LuxCreo', // 发件人名称 + ], + 'sms' => [ + 'aliyun' => [ + 'access_key_id' => env('ACCESS_KEY_ID', ''), + 'access_key_secret' => env('ACCESS_KEY_SECRET', ''), + 'sign' => '', // 短信签名名称 + 'template_code' => '', // 短信模板CODE + ], + ], + 'storage' => [ + 'oss' => [ + 'access_key_id' => env('ACCESS_KEY_ID', ''), + 'access_key_secret' => env('ACCESS_KEY_SECRET', ''), + ], + ], + ], ]; \ No newline at end of file diff --git a/src/Utils/Service/EmailService.php b/src/Utils/Service/EmailService.php new file mode 100644 index 0000000..e932927 --- /dev/null +++ b/src/Utils/Service/EmailService.php @@ -0,0 +1,62 @@ +mailer = new Mailer($transport); + } + + /** + * 发送邮件 + * + * @param string $target + * @param string $subject + * @param string $text + * + * @return bool + * @throws \Symfony\Component\Mailer\Exception\TransportExceptionInterface + */ + public function sendCode( + string $target, + string $subject = '', + string $text = '' + ): bool { + $from = config('mailer_sender_name') . ' <' . config('mailer_sender') . '>'; + $email = (new Email()) + ->from(Address::create($from)) + ->to($target) + ->subject($subject) + ->text($text); + + $this->mailer->send($email); + + return true; + } +}