Ken пре 3 дана
родитељ
комит
91f59ac1f1
2 измењених фајлова са 26 додато и 1 уклоњено
  1. 3 1
      app/Http/Controllers/api/ActivityReward.php
  2. 23 0
      app/Services/SmsService.php

+ 3 - 1
app/Http/Controllers/api/ActivityReward.php

@@ -7,6 +7,7 @@ use App\Models\ActivityReward as ActivityRewardModel;
 use App\Models\ActivityUser;
 use App\Services\ActivityRewardService;
 use App\Services\ActivityUserService;
+use App\Services\SmsService;
 use App\Services\UserService;
 use Illuminate\Http\JsonResponse;
 use Illuminate\Support\Facades\Cache;
@@ -33,6 +34,7 @@ class ActivityReward extends BaseController
             $key = 'api_request_' . md5(json_encode($keys));
             if (Cache::has($key)) throw new Exception("请求太频繁,请稍后再试。", HttpStatus::CUSTOM_ERROR);
             Cache::put($key, true, 60);
+            $res = SmsService::sendPhoneCode($params['phone']);
 
 
         } catch (ValidationException $e) {
@@ -42,7 +44,7 @@ class ActivityReward extends BaseController
 
             return $this->error($e->getMessage(), [], $e->getCode());
         }
-        return $this->error('开发中');
+        return $this->success($res);
     }
 
     public function participate(): JsonResponse

+ 23 - 0
app/Services/SmsService.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace App\Services;
+
+class SmsService
+{
+    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}。如非本人操作,请忽略本短信";
+
+    public static function sendPhoneCode($phone)
+    {
+        $code = mt_rand(100000, 999999);
+        $content = str_replace("{code}", $code, static::$content);
+        $url = static::$uri . "?u=" . static::$username . "&p=" . static::$password;
+        $url .= "&c=" . urlencode($content);
+        $url .= "&m=" . $phone;
+        $res = file_get_contents($url);
+        return $res;
+
+    }
+}