123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- declare (strict_types=1);
- namespace app\zskk\servies;
- use app\zskk\model\Institution;
- use think\facade\Cache;
- class EmpowerServies
- {
- public $institutionModel = null;
- public function __construct(Institution $institutionModel)
- {
- // parent::__construct();
- $this->institutionModel = $institutionModel;
- }
- public function getRecogToken($params): array
- {
- $ID_CARDNUM = $params['ID_CARDNUM'];
- $ORGCODE = $params['ORGCODE'];
- $ORGNAME = $params['ORGNAME'];
- $DOCTORNAME = $params['DOCTORNAME'];
- $DOCTORCODE = $params['DOCTORCODE'];
- $aesKey = $this->generateRandomLetters();
- // todo
- // $aesKey = 'testToken1';
- $expire = 86400;
- $arr = [
- 'ID_CARDNUM'=>$ID_CARDNUM,
- 'ORGCODE'=>$ORGCODE,
- 'ORGNAME'=>$ORGNAME,
- 'DOCTORNAME'=>$DOCTORNAME,
- 'DOCTORCODE'=>$DOCTORCODE,
- 'HR_ITEM_CODE'=>$params['HR_ITEM_CODE'] ?? '',
- 'DEVICE_IP'=>$params['DEVICE_IP'] ?? '',
- 'DEVICE_MAC'=>$params['DEVICE_MAC'] ?? ''
- ];
- Cache::set($aesKey,$arr,$expire);
- return ['TOKEN'=>$aesKey];
- }
- public function getInsToken($params): array
- {
- $orgCode = $params['clientid']; //机构编码
- $authID = $params['clientsecret']; //授权码
- $institution = $this->institutionModel->where('port_empower',$authID)->where('institution_code',$orgCode)->find();
- if(empty($institution))
- {
- return ['msg'=>'机构编码或授权码错误','data'=>[]];
- }
- $key = md5($orgCode.rand(0,99));
- $expire = 3600;
- $aesKey = $this->generateRandomLetters();
- // todo
- // $aesKey = 'zLxapoeqWYpoeqWY';
- // $institution['id'] = '001';
- $token = base64_encode(md5($orgCode.$institution['id'].$aesKey));
- $arr = ['token'=>$token,'key'=>$aesKey,'expire'=>$expire,'appId'=>$key,'orgCode'=>$orgCode];
- // if(empty(Cache::get($orgCode)))
- // {
- Cache::set($orgCode,[[$orgCode=>$token]],$expire);
- // }else{
- // Cache::push($orgCode,[$orgCode=>$token]);
- // }
- Cache::set($token,$arr,$expire);
- return ['msg'=>'success','data'=>$arr];
- }
- public function generateRandomLetters($length = 32): string
- {
- $letters = 'abcdefghijklmnopqrstuvwxyz1234567890'; // ABCDEFGHIJKLMNOPQRSTUVWXYZ
- $lettersLength = strlen($letters);
- $randomLetters = '';
- for ($i = 0; $i < $length; $i++) {
- $randomLetters .= $letters[random_int(0, $lettersLength - 1)];
- }
- return $randomLetters;
- }
- }
|