123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace App\Services;
- use Overtrue\EasySms\EasySms;
- use Illuminate\Support\Facades\Log;
- class SmsService
- {
- protected $easySms;
- public function __construct()
- {
- $this->easySms = new EasySms(config('sms'));
- }
- /**
- * 发送验证码短信
- *
- * @param string $mobile 手机号
- * @param string $code 验证码
- * @return bool
- */
- public function sendVerifyCode(string $mobile, string $code): bool
- {
- try {
- $templateId = env('TENCENT_SMS_TEMPLATE_ID');
- // TODO: 发送短信方法,记得打开
- // $result = $this->easySms->send($mobile, [
- // 'template' => $templateId,
- // 'data' => [
- // $code,
- // 5 // 验证码有效期(分钟)
- // ],
- // ]);
- $result = true;
- Log::info('SMS sent', [
- 'mobile' => $mobile,
- 'code' => $code,
- 'result' => $result
- ]);
- return true;
- } catch (\Exception $e) {
- Log::error('SMS sending failed', [
- 'mobile' => $mobile,
- 'error' => $e->getMessage()
- ]);
- throw $e;
- }
- }
- }
|