Przeglądaj źródła

WX小程序中间件

Zhouzhendong 6 lat temu
rodzic
commit
c55be52269

+ 3 - 1
app/Http/Controllers/TestController.php

@@ -14,6 +14,8 @@ use App\Package;
 use App\Rejected;
 use App\RejectedBill;
 use App\RejectedBillItem;
+use App\User;
+use App\UserToken;
 use App\Waybill;
 use App\WMSReflectReceive;
 use Carbon\Carbon;
@@ -126,7 +128,7 @@ class TestController extends Controller
     }
 
     public function test1(){
-        return 7|6;
+        return UserToken::getUser('b2b3c637909997033801f5f733cf1fe3');
     }
 
 

+ 2 - 2
app/Http/Controllers/api/thirdPart/weixin/WxController.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace App\Http\Controllers\Api;
+namespace App\Http\Controllers\Api\thirdPart\weixin;
 /**
  * TODO::接口路径(微信线上)的需要修改,因为route文件和路径都改成了新的标准
  */
@@ -31,7 +31,7 @@ class WxController extends Controller
                 ->whereIn('carrier_id',$carrierArr)->where('status','!=','已完结')->where('status','!=','无模型')->get();
             return ['waybill'=>$waybill,'carriersName'=>$carriersName,'count'=>$count];
         }
-        return ['exception'=>'出错了!'];
+        return ['error'=>'请检查您的登录账号!'];
     }
 
     public function show(Request $request){

+ 1 - 1
app/Http/Controllers/api/thirdPart/weixin/WxLoginController.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace App\Http\Controllers\Api;
+namespace App\Http\Controllers\Api\thirdPart\weixin;
 
 use App\User;
 use Illuminate\Http\Request;

+ 1 - 0
app/Http/Kernel.php

@@ -67,6 +67,7 @@ class Kernel extends HttpKernel
         'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
         'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
         'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
+        'auth.api' => \App\Http\Middleware\ApiAuth::class,
     ];
 
     /**

+ 25 - 0
app/Http/Middleware/ApiAuth.php

@@ -0,0 +1,25 @@
+<?php
+
+namespace App\Http\Middleware;
+
+use Closure;
+use Illuminate\Support\Facades\Cache;
+
+class ApiAuth
+{
+    /**
+     * Handle an incoming request.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  \Closure  $next
+     * @return mixed
+     */
+    public function handle($request, Closure $next)
+    {
+        if ($request->input('api_token')&&Cache::has('tokenStr_'.$request->input('api_token'))){
+
+            return $next($request);
+        }
+        return ['error'=>"请检查您的登录"];
+    }
+}

+ 1 - 1
routes/api/thirdPart/weixin.php

@@ -8,7 +8,7 @@ use Illuminate\Http\Request;
 文件地址前缀:/api/thirdPart/weixin
 */
 
-Route::group(['middleware'=>'auth:api'],function(){
+Route::group(['middleware'=>'auth.api'],function(){
     Route::get('waybill', "WxController@index");//微信小程序数据返回
     Route::post('waybill/show', "WxController@show");//微信小程序数据返回
     Route::post('waybill/update', "WxController@update");//微信小程序数据修改

+ 1 - 1
tests/webApi/test.http

@@ -35,7 +35,7 @@ Content-Type: application/json
 {"name":"zhouzhendong","password":"zhou1792524653"}
 ###
 
-GET https://was.baoshi56.com/api/thirdPart/weixin/waybill?api_token=b2b3c637909997033801f5f733cf1fe3
+GET http://bswas/api/thirdPart/weixin/waybill?api_token=ss
 
 ###