SmsService.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace App\Services;
  3. class SmsService
  4. {
  5. private static string $uri = "https://api.smsbao.com/sms";
  6. private static string $username = "even7788";
  7. private static string $password = "Lpy@19920122";
  8. private static string $content = "【二八科技】您的验证码是{code}。如非本人操作,请忽略本短信";
  9. private static array $errors = [
  10. '30' => '错误密码',
  11. '40' => '账号不存在',
  12. '41' => '余额不足',
  13. '43' => "IP地址限制",
  14. '50' => "内容含有敏感词",
  15. '51' => '手机号码不正确'
  16. ];
  17. public static function sendPhoneCode($phone): string
  18. {
  19. $code = mt_rand(100000, 999999);
  20. $password = md5(static::$password);
  21. $content = str_replace("{code}", $code, static::$content);
  22. $url = static::$uri . "?u=" . static::$username . "&p=" . $password;
  23. $url .= "&c=" . urlencode($content);
  24. $url .= "&m=" . $phone;
  25. $code = file_get_contents($url);
  26. if (!empty(static::$errors[$code]))
  27. return static::$errors[$code];
  28. if ($code == 0) return '已发送';
  29. return "发送失败";
  30. }
  31. }