Ken 1 هفته پیش
والد
کامیت
3ce61ebf3c
3فایلهای تغییر یافته به همراه28 افزوده شده و 0 حذف شده
  1. 25 0
      app/Http/Controllers/api/ActivityReward.php
  2. 2 0
      app/Http/Controllers/api/Home.php
  3. 1 0
      routes/api.php

+ 25 - 0
app/Http/Controllers/api/ActivityReward.php

@@ -9,6 +9,7 @@ use App\Services\ActivityRewardService;
 use App\Services\ActivityUserService;
 use App\Services\UserService;
 use Illuminate\Http\JsonResponse;
+use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Validation\ValidationException;
 use Exception;
@@ -17,6 +18,30 @@ use Exception;
 class ActivityReward extends BaseController
 {
 
+    //发送手机验证码
+    public function sendPhoneCode()
+    {
+        try {
+            $params = request()->validate([
+                'member_id' => ['required', 'integer'],
+                'phone' => ['required', 'string'],
+            ]);
+            $params['action'] = request()->action;
+            $key = 'api_request_' . md5(json_encode($params));
+            if (Cache::has($key)) throw new Exception("请求太频繁,请稍后再试。", HttpStatus::CUSTOM_ERROR);
+            Cache::put($key, true, 3);
+
+
+        } catch (ValidationException $e) {
+
+            return $this->error($e->validator->errors()->first());
+        } catch (Exception $e) {
+
+            return $this->error($e->getMessage(), [], $e->getCode());
+        }
+
+    }
+
     public function participate(): JsonResponse
     {
         DB::beginTransaction();

+ 2 - 0
app/Http/Controllers/api/Home.php

@@ -23,6 +23,8 @@ class Home extends Controller
         return view('login');
     }
 
+
+
     public function home()
     {
         $menu = [

+ 1 - 0
routes/api.php

@@ -21,6 +21,7 @@ Route::get("/setA", [Home::class, 'setA']);
 Route::prefix('/ActivityReward')->group(function () {
     Route::get('/', [ActivityReward::class, 'index']);
     Route::post('/participate', [ActivityReward::class, 'participate']);
+    Route::post('/sendPhoneCode', [ActivityReward::class, 'sendPhoneCode']);
 });