Ken před 3 dny
rodič
revize
c46d2fd428
3 změnil soubory, kde provedl 18 přidání a 6 odebrání
  1. 8 6
      app/Services/SmsService.php
  2. 5 0
      config/services.php
  3. 5 0
      example.env

+ 8 - 6
app/Services/SmsService.php

@@ -8,9 +8,6 @@ use Exception;
 class SmsService
 class SmsService
 {
 {
     private static string $uri = "https://api.smsbao.com/sms";
     private static string $uri = "https://api.smsbao.com/sms";
-    private static string $username = "even7788";
-    private static string $password = "Lpy@19920122";
-    private static string $content = "【二八科技】您的验证码是{code}。如非本人操作,请忽略本短信";
     private static array $errors = [
     private static array $errors = [
         '30' => '错误密码',
         '30' => '错误密码',
         '40' => '账号不存在',
         '40' => '账号不存在',
@@ -27,11 +24,16 @@ class SmsService
      */
      */
     public static function sendPhoneCode($phone): bool
     public static function sendPhoneCode($phone): bool
     {
     {
+
+        $username = config('services.sms.username');
+        $password = config('services.sms.password');
+        $content = config("services.sms.content");
+
+
         $code = mt_rand(100000, 999999);
         $code = mt_rand(100000, 999999);
-        $password = md5(static::$password);
+        $content = str_replace("{code}", $code, $content);
 
 
-        $content = str_replace("{code}", $code, static::$content);
-        $url = static::$uri . "?u=" . static::$username . "&p=" . $password;
+        $url = static::$uri . "?u=" . $username . "&p=" . md5($password);
         $url .= "&c=" . urlencode($content);
         $url .= "&c=" . urlencode($content);
         $url .= "&m=" . $phone;
         $url .= "&m=" . $phone;
         $code = file_get_contents($url);
         $code = file_get_contents($url);

+ 5 - 0
config/services.php

@@ -2,6 +2,11 @@
 
 
 return [
 return [
 
 
+    'sms' => [
+        'username' => env('SMS_USERNAME', 'even7788'),//用户名
+        'password' => env('SMS_PASSWORD', 'Lpy@19920122'),//密码
+        'content' => env("SMS_CONTENT", '【二八科技】您的验证码是{code}。如非本人操作,请忽略本短信'),//短信内容
+    ],
 
 
     'telegram' => [
     'telegram' => [
         'token' => env('TELEGRAM_BOT_TOKEN'),
         'token' => env('TELEGRAM_BOT_TOKEN'),

+ 5 - 0
example.env

@@ -5,6 +5,11 @@ APP_NAME=Bot
 APP_DEBUG=true
 APP_DEBUG=true
 APP_URL=
 APP_URL=
 
 
+# 短信宝
+SMS_USERNAME=
+SMS_PASSWORD=
+SMS_CONTENT=
+
 # TG机器人
 # TG机器人
 TELEGRAM_BOT_TOKEN=
 TELEGRAM_BOT_TOKEN=
 TELEGRAM_BOT_USERNAME=
 TELEGRAM_BOT_USERNAME=