VerifyCode.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace App\Servers\Sms;
  3. use App\Facades\Servers\Sms\GuoDu;
  4. use App\Facades\Servers\Aliyun\Sms as Aliyun;
  5. use App\Facades\Servers\Tencent\Sms as Tencent;
  6. /**
  7. * 验证码模型
  8. * @author 唐远望
  9. * @version 1.0
  10. * @date 2026-01-15
  11. *
  12. */
  13. class VerifyCode
  14. {
  15. public function sendCode($phone, $verifyCode)
  16. {
  17. // 判断运营商,以方便发送短信
  18. $type = config('verifycode.operator_type');
  19. // 如果是国都
  20. if ($type == 'guodu') {
  21. // 发送短信
  22. $result = GuoDu::sendSms($phone, '您的验证码是:' . $verifyCode . ',5分钟内有效,请勿外泄。', config('verifycode.guodu.sms_sign'));
  23. // 如果code不是03
  24. if ($result['code'] != '03' && $result['code'] != '01') return ['error' => '发送失败', 'data' => $result];
  25. // 返回结果
  26. return $result;
  27. }
  28. // 如果是阿里云
  29. if ($type == 'aliyun') {
  30. // 发送短信
  31. $result = Aliyun::sendSms($phone, config('verifycode.aliyun.sms_sign'), config('verifycode.aliyun.sms_tpl'), ['code' => $verifyCode]);;
  32. // 如果code不是03
  33. if (isset($result['error'])) return ['error' => $result['error'], 'data' => $result];
  34. // 返回结果
  35. return $result;
  36. }
  37. // 如果是阿里云
  38. if ($type == 'tencent') {
  39. // 发送短信
  40. $result = Tencent::sendSms($phone, config('verifycode.tencent.sms_sign'), config('verifycode.tencent.sms_tpl'), [$verifyCode]);
  41. // 如果code不是03
  42. if (isset($result['error'])) return ['error' => $result['error'], 'data' => $result];
  43. // 返回结果
  44. return $result;
  45. }
  46. // 返回结果
  47. return ['error' => '未知运营商,请配置运营商类型'];
  48. }
  49. public function sendRemind($phone, $content)
  50. {
  51. // 判断运营商,以方便发送短信
  52. $type = config('verifycode.operator_type');
  53. // 如果是国都
  54. if ($type == 'guodu') {
  55. // 发送短信
  56. $result = GuoDu::sendSms($phone, $content, config('verifycode.guodu.sms_sign'));
  57. // 如果code不是03
  58. if ($result['code'] != '03' && $result['code'] != '01') return ['error' => '发送失败', 'data' => $result];
  59. // 返回结果
  60. return $result;
  61. }
  62. // 如果是阿里云
  63. if ($type == 'aliyun') {
  64. // 发送短信
  65. $result = Aliyun::sendSms($phone, config('verifycode.aliyun.sms_sign'), config('verifycode.aliyun.sms_tpl'), ['code' => $content]);
  66. // 如果code不是03
  67. if (isset($result['error'])) return ['error' => $result['error'], 'data' => $result];
  68. // 返回结果
  69. return $result;
  70. }
  71. // 如果是阿里云
  72. if ($type == 'tencent') {
  73. // 发送短信
  74. $result = Tencent::sendSms($phone, config('verifycode.tencent.sms_sign'), config('verifycode.tencent.sms_tpl'), [$content]);
  75. // 如果code不是03
  76. if (isset($result['error'])) return ['error' => $result['error'], 'data' => $result];
  77. // 返回结果
  78. return $result;
  79. }
  80. // 返回结果
  81. return ['error' => '未知运营商,请配置运营商类型'];
  82. }
  83. public function sendContent($phone, $content)
  84. {
  85. // 判断运营商,以方便发送短信
  86. $type = config('verifycode.operator_type');
  87. // 如果是阿里云
  88. if ($type == 'aliyun') {
  89. // 发送短信
  90. $result = Aliyun::sendSms($phone, config('verifycode.aliyun_website.sms_sign'), config('verifycode.aliyun_website.sms_tpl'),$content);
  91. // 如果code不是03
  92. if (isset($result['error'])) return ['error' => $result['error'], 'data' => $result];
  93. // 返回结果
  94. return $result;
  95. }
  96. }