quguofeng il y a 1 an
Parent
commit
71ea93d939
1 fichiers modifiés avec 23 ajouts et 0 suppressions
  1. 23 0
      application/api/controller/Login.php

+ 23 - 0
application/api/controller/Login.php

@@ -1,6 +1,7 @@
 <?php
 namespace app\api\controller;
 use AlibabaCloud\SDK\Dingtalk\Vcrm_1_0\Models\DescribeRelationMetaResponseBody\relationMetaDTOList\items\props\rule;
+use Firebase\JWT\JWT;
 use think\Db;
 use hg\apidoc\annotation as Apidoc;
 /**
@@ -31,4 +32,26 @@ class Login extends Base
         $user_info = $get_info_obj->get_user_info($user_token);
         var_dump($user_info);exit();
     }
+    public function  get_token(){
+        $uid = input('uid',1);
+        $token = $this->create_jwt($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;
+    }
 }