lgy 4 veckor sedan
förälder
incheckning
652f243e8a

+ 25 - 0
server/application/api/controller/butt/ButtController.php

@@ -398,8 +398,16 @@ class ButtController extends ZskkDefaultApiController
         return $this->success($data);
     }
 
+    public function makeInsToken(ButtService $service)
+    {
+        $params = Request::param(false);
+        $data = $service->getInsToken($params['data'] ?? '');
+        return $this->success($data);
+    }
+    
     public function saveDmExam(ButtService $service)
     {
+        $this->getHeaderToken();
         $params = Request::param(false);
         $data = $this->getDecryptData($params['data']);
         if(is_array($data))
@@ -414,6 +422,7 @@ class ButtController extends ZskkDefaultApiController
 
     public function saveDmReport(ButtService $service)
     {
+        $this->getHeaderToken();
         $params = Request::param(false);
         $data = $this->getDecryptData($params['data']);
         if(is_array($data))
@@ -425,4 +434,20 @@ class ButtController extends ZskkDefaultApiController
             $this->throwError($data,9001);
         }
     }
+
+    public function getHeaderToken()
+    {
+        $header = getallheaders();
+        $auth = $header['Authorization'] ?? '';
+        $data = explode(' ',$auth);
+        if(empty($data[1]))
+        {
+            $this->throwError('token获取失败',9003);
+        }
+        if(empty($this->getCache($data[1])))
+        {
+            $this->throwError('token已过期',9004);
+        }
+        return $data[1] ?? '';
+    }
 }

+ 9 - 1
server/application/api/dao/butt/ButtDao.php

@@ -5,6 +5,7 @@ namespace app\api\dao\butt;
 use app\api\actions\ZskkCache;
 use app\api\dao\ZskkDefaultDao;
 use app\api\model\hr\HrModel;
+use app\api\model\institution\InstitutionModel;
 use app\api\model\monitor\MonitorexamModel;
 use app\api\model\monitor\MonitorreportModel;
 use app\api\model\report\ReportModel;
@@ -22,12 +23,14 @@ class ButtDao extends ZskkDefaultDao {
     protected  $report = null;
     protected  $hrModel = null;
     protected  $monitorreportModel = null;
-    public function __construct(ReportModel $reportModel,HrModel $hrModel,MonitorreportModel $monitorreportModel)
+    protected  $institutionModel = null;
+    public function __construct(ReportModel $reportModel,HrModel $hrModel,MonitorreportModel $monitorreportModel,InstitutionModel $institutionModel)
     {
         parent::__construct();
         $this->report = $reportModel;
         $this->hrModel = $hrModel;
         $this->monitorreportModel = $monitorreportModel;
+        $this->institutionModel = $institutionModel;
 
     }
 
@@ -134,6 +137,11 @@ class ButtDao extends ZskkDefaultDao {
         return $info;
     }
 
+    public function getInstitution($where)
+    {
+        return $this->institutionModel->where($where)->find();
+    }
+
     public function getHistorySend($exam,$study)
     {
         $info = $this->report->getHistorySend($exam,$study);

+ 26 - 0
server/application/api/servies/butt/ButtService.php

@@ -1910,6 +1910,32 @@ class ButtService extends ZskkDefaultService {
         return ['data'=>$data,'count'=>count($data)];
     }
 
+    public function getInsToken($params)
+    {
+        $orgCode = $params['clientid']; //机构编码
+        $authID = $params['clientsecret'];  //授权码
+        if(empty($orgCode) || empty($authID))
+        {
+            $this->throwError('','');
+        }
+        $where = ['id'=>$orgCode,'clientid'=>$authID];
+        $institution = $this->butt->getInstitution($where);
+        if(empty($institution))
+        {
+            return ['msg'=>'机构编码或授权码错误','data'=>[]];
+        }
+        $key = md5($orgCode.rand(0,99));
+        $expire = 3600;
+//        $aesKey = $this->generateRandomLetters();
+        // todo
+        $aesKey = 'zLxapoeqWYpoeqWY';
+        $token = base64_encode(md5($orgCode.$institution['id'].$aesKey));
+        $arr = ['token'=>$token,'key'=>$aesKey,'expire'=>$expire,'appId'=>$key,'orgCode'=>$orgCode];
+        $this->setCache($orgCode,[$orgCode=>$token],$expire);
+        $this->setCache($token,$arr,$expire);
+        return ['msg'=>'success','data'=>$arr];
+    }
+
     public function getExamReport($params)
     {
         $id = $params['id'] ?? '';