zhanglinxin 1 年之前
父節點
當前提交
ac17cad01f
共有 2 個文件被更改,包括 14 次插入29 次删除
  1. 9 9
      application/api/controller/Base.php
  2. 5 20
      application/api/controller/Login.php

+ 9 - 9
application/api/controller/Base.php

@@ -58,7 +58,7 @@ class Base extends Controller
         $this->page_num = $page_num ? $page_num : 20;
         $this->off_set = ($this->page * $this->page_num) - $this->page_num;
         $path = explode('/', $this->request->path());
-        if (!empty($this->need_login) && in_array(end($path), $this->need_login)){
+        if (!empty($this->need_login) && in_array(end($path), $this->need_login)) {
             $this->checkLogin();
         }
     }
@@ -72,20 +72,20 @@ class Base extends Controller
         try {
             $key = md5(config('app.jwt'));
             $check_authorization = JWT::decode($authorization, $key, array('HS256'));
-            if ($check_authorization['code'] != 200){
+            if ($check_authorization['code'] != 200) {
                 $this->exception($check_authorization['msg']);
             }
             $authInfo = json_decode(json_encode($check_authorization['data']), true);
-            if(!$authInfo){
+            if (!$authInfo) {
                 $this->error('Token验证不通过,账号不存在', null, 0, -1);
             }
-            $member = User::field('is_deleted',true)
-                ->where('is_deleted',CommonConstant::IS_DELETED_0)
+            $member = User::field('is_deleted', true)
+                ->where('is_deleted', CommonConstant::IS_DELETED_0)
                 ->find($authInfo['uid']);
-            if (!$member){
-                $this->error('账号不存在', null, 0,-1);
+            if (!$member) {
+                $this->error('账号不存在', null, 0, -1);
             }
-            if(!$member['status']){
+            if (!$member['status']) {
                 $this->error('账号已经被禁用', null, 0, -1);
             }
             $this->user_id = $authInfo['uid'];
@@ -111,7 +111,7 @@ class Base extends Controller
             "iat" => $time,
             "nbf" => $time,
             "exp" => $expire,
-            "facility_code" => $facility_code,
+//            "facility_code" => $facility_code,
         );
         $jwt = JWT::encode($token, $key);
         return $jwt;

+ 5 - 20
application/api/controller/Login.php

@@ -4,7 +4,6 @@ namespace app\api\controller;
 
 use app\common\service\DingtalkService;
 use app\common\model\User;
-use Firebase\JWT\JWT;
 use hg\apidoc\annotation as Apidoc;
 
 /**
@@ -42,7 +41,7 @@ class Login extends Base
             $this->error('不是内部人员');
         }
 
-        $token = $this->create_jwt($user);
+        $token = $this->createJwt($user);
         $this->success('登录成功',$token);
     }
 
@@ -55,25 +54,11 @@ class Login extends Base
      */
     public function get_token(){
         $uid = input('uid');
-        $token = $this->create_jwt($uid);
+        if(!$uid){
+            $this->error('uid错误');
+        }
+        $token = $this->createJwt($uid);
         $this->success('获取成功',$token);
     }
 
-    //token加密
-    public function create_jwt($uid)
-    {
-        $key = md5(config('app.jwt')); //jwt的签发密钥,验证token的时候需要用到
-        $time = time(); //签发时间
-        $expire = $time + config('app.jwt_time'); //过期时间
-        $token = array(
-            "uid" => $uid,
-            "iss" => "https://zain.com",//签发组织
-            "aud" => "https://zain.com", //签发作者
-            "iat" => $time,
-            "nbf" => $time,
-            "exp" => $expire
-        );
-        $jwt = JWT::encode($token, $key);
-        return $jwt;
-    }
 }