feat(utils): 增加了邮件服务

Signed-off-by: 李东云 <dongyun.li@luxcreo.ai>
This commit is contained in:
李东云
2022-07-26 18:21:57 +08:00
parent 2f81f0f7de
commit 478e6066f2
2 changed files with 88 additions and 4 deletions

View File

@@ -36,8 +36,8 @@ return [
], ],
'app' => [ 'app' => [
'expire_time' => 30 * 24 * 60 * 60, 'expire_time' => 30 * 24 * 60 * 60,
'prefix_key' => 'token:' 'prefix_key' => 'token:',
] ],
], ],
// redis 补充配置 // redis 补充配置
@@ -57,4 +57,26 @@ return [
], ],
], ],
// 第三方服务
'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', ''),
],
],
],
]; ];

View File

@@ -0,0 +1,62 @@
<?php
declare(strict_types=1);
/**
* This file is part of LuxAccountX.
*
* @link http://124.126.16.154:8888/WebService/LuxAccountX
* @document https://lux-software.yuque.com/htnx76/vcm2oc
* @contact dongyun.li@luxcreo.ai
*/
namespace Singularity\HDK\Utils\Service;
use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Mailer\Transport;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
/**
* 邮箱验证码
*/
class EmailService
{
/**
* @var \Symfony\Component\Mailer\Mailer
*/
private Mailer $mailer;
public function __construct()
{
$dsn = config('common.third_party.email.dsn');
$transport = Transport::fromDsn($dsn);
$this->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;
}
}