| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- namespace App\Servers\Sms;
- use App\Facades\Servers\Sms\GuoDu;
- use App\Facades\Servers\Aliyun\Sms as Aliyun;
- use App\Facades\Servers\Tencent\Sms as Tencent;
- /**
- * 验证码模型
- * @author 唐远望
- * @version 1.0
- * @date 2026-01-15
- *
- */
- class VerifyCode
- {
- public function sendCode($phone, $verifyCode)
- {
- // 判断运营商,以方便发送短信
- $type = config('verifycode.operator_type');
- // 如果是国都
- if ($type == 'guodu') {
- // 发送短信
- $result = GuoDu::sendSms($phone, '您的验证码是:' . $verifyCode . ',5分钟内有效,请勿外泄。', config('verifycode.guodu.sms_sign'));
- // 如果code不是03
- if ($result['code'] != '03' && $result['code'] != '01') return ['error' => '发送失败', 'data' => $result];
- // 返回结果
- return $result;
- }
- // 如果是阿里云
- if ($type == 'aliyun') {
- // 发送短信
- $result = Aliyun::sendSms($phone, config('verifycode.aliyun.sms_sign'), config('verifycode.aliyun.sms_tpl'), ['code' => $verifyCode]);;
- // 如果code不是03
- if (isset($result['error'])) return ['error' => $result['error'], 'data' => $result];
- // 返回结果
- return $result;
- }
- // 如果是阿里云
- if ($type == 'tencent') {
- // 发送短信
- $result = Tencent::sendSms($phone, config('verifycode.tencent.sms_sign'), config('verifycode.tencent.sms_tpl'), [$verifyCode]);
- // 如果code不是03
- if (isset($result['error'])) return ['error' => $result['error'], 'data' => $result];
- // 返回结果
- return $result;
- }
- // 返回结果
- return ['error' => '未知运营商,请配置运营商类型'];
- }
- public function sendRemind($phone, $content)
- {
- // 判断运营商,以方便发送短信
- $type = config('verifycode.operator_type');
- // 如果是国都
- if ($type == 'guodu') {
- // 发送短信
- $result = GuoDu::sendSms($phone, $content, config('verifycode.guodu.sms_sign'));
- // 如果code不是03
- if ($result['code'] != '03' && $result['code'] != '01') return ['error' => '发送失败', 'data' => $result];
- // 返回结果
- return $result;
- }
- // 如果是阿里云
- if ($type == 'aliyun') {
- // 发送短信
- $result = Aliyun::sendSms($phone, config('verifycode.aliyun.sms_sign'), config('verifycode.aliyun.sms_tpl'), ['code' => $content]);;
- // 如果code不是03
- if (isset($result['error'])) return ['error' => $result['error'], 'data' => $result];
- // 返回结果
- return $result;
- }
- // 如果是阿里云
- if ($type == 'tencent') {
- // 发送短信
- $result = Tencent::sendSms($phone, config('verifycode.tencent.sms_sign'), config('verifycode.tencent.sms_tpl'), [$content]);
- // 如果code不是03
- if (isset($result['error'])) return ['error' => $result['error'], 'data' => $result];
- // 返回结果
- return $result;
- }
- // 返回结果
- return ['error' => '未知运营商,请配置运营商类型'];
- }
- }
|