|
|
@@ -2,6 +2,9 @@
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
+use App\Constants\HttpStatus;
|
|
|
+use Exception;
|
|
|
+
|
|
|
class SmsService
|
|
|
{
|
|
|
private static string $uri = "https://api.smsbao.com/sms";
|
|
|
@@ -17,7 +20,12 @@ class SmsService
|
|
|
'51' => '手机号码不正确'
|
|
|
];
|
|
|
|
|
|
- public static function sendPhoneCode($phone): string
|
|
|
+ /**
|
|
|
+ * @param $phone
|
|
|
+ * @return bool
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public static function sendPhoneCode($phone): bool
|
|
|
{
|
|
|
$code = mt_rand(100000, 999999);
|
|
|
$password = md5(static::$password);
|
|
|
@@ -27,9 +35,10 @@ class SmsService
|
|
|
$url .= "&c=" . urlencode($content);
|
|
|
$url .= "&m=" . $phone;
|
|
|
$code = file_get_contents($url);
|
|
|
- if (!empty(static::$errors[$code]))
|
|
|
- return static::$errors[$code];
|
|
|
- if ($code == 0) return '已发送';
|
|
|
- return "发送失败";
|
|
|
+ if (!empty(static::$errors[$code])) {
|
|
|
+ throw new Exception(static::$errors[$code], HttpStatus::CUSTOM_ERROR);
|
|
|
+ }
|
|
|
+ if ($code == 0) return true;
|
|
|
+ throw new Exception("发送失败", HttpStatus::CUSTOM_ERROR);
|
|
|
}
|
|
|
}
|