wugg пре 2 година
родитељ
комит
923610a4bf
2 измењених фајлова са 28 додато и 27 уклоњено
  1. 28 0
      app/middleware/CheckAuth.php
  2. 0 27
      app/service/Account.php

+ 28 - 0
app/middleware/CheckAuth.php

@@ -3,6 +3,7 @@ declare (strict_types = 1);
 
 namespace app\middleware;
 
+use think\facade\Db;
 class CheckAuth
 {
     /**
@@ -17,6 +18,33 @@ class CheckAuth
     	if($request->isOptions()){
     		return json();
     	}
+    	$header =$request->header();
+    	$param =$request->post();
+    	$check =$this->check($header,$param);
+    	 if($check['code']==1){
+	    	return json_show(104,$check['msg']);
+		}
        return $next($request);
     }
+
+	/**数据接口签名验证
+	* @param $data
+	* @param $param
+	* @return array
+	*/
+    private  function check($data,$param){
+        //check sign
+        if (!isset($data['appid']) || !$data['appid']) {
+            return ['code'=>1,'msg'=>'发送的应用参数不存在'];
+        }
+        $appinf =Db::name("auth")->where(["app_id"=>$data['appid'],"is_del"=>0,"status"=>1])->findOrEmpty();
+        if(empty($appinf)){
+        	  return ['code'=>1,'msg'=>'发送的应用参数错误'];
+        }
+		$mege=["appid"=>$data['appid'],"noce"=>$data['noce']??'',"sign"=>$data['sign']??'',"timestamp"=>$data['timestamp']??''];
+        $value =array_merge($mege,$param);
+        $Sign= new \Sign($appinf['app_id'],$appinf['app_key']);
+        $result =$Sign->verifySign($value);
+        return $result;
+    }
 }

+ 0 - 27
app/service/Account.php

@@ -1,27 +0,0 @@
-<?php
-declare (strict_types = 1);
-
-namespace app\service;
-
-class Account extends \think\Service
-{
-    /**
-     * 注册服务
-     *
-     * @return mixed
-     */
-    public function register()
-    {
-    	//
-    }
-
-    /**
-     * 执行服务
-     *
-     * @return mixed
-     */
-    public function boot()
-    {
-        //
-    }
-}