| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?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' => '未知运营商,请配置运营商类型'];
- }
- public function sendContent($phone, $content)
- {
- // 判断运营商,以方便发送短信
- $type = config('verifycode.operator_type');
- // 如果是阿里云
- if ($type == 'aliyun') {
- // 发送短信
- $result = Aliyun::sendSms($phone, config('verifycode.aliyun_website.sms_sign'), config('verifycode.aliyun_website.sms_tpl'),$content);
- // 如果code不是03
- if (isset($result['error'])) return ['error' => $result['error'], 'data' => $result];
- // 返回结果
- return $result;
- }
- }
- }
|