123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- declare(strict_types=1);
- namespace app\mobile\controller;
- use Exception;
- use think\facade\Request;
- use Firebase\JWT\JWT;
- use openssl\Aes;
- use toolkits\Aec;
- use think\exception\HttpException;
- use think\Request as RequestModel;
- class Enjoy
- {
- public $params;
- public $rootId;
- public $employeeId;
- public $employee;
- public function __construct(RequestModel $request){
- $param = Request::only(['token'=>'']);
- //分享楼书的接口需要传token
- //店面id ,分享人id , 楼盘id , 户型id , 案例id , 在施工地id
- $arr = ['rootId'=>0,'employeeId'=>0,'buildingId'=>0,'housetypeId'=>0,'cateId'=>0,'constructionId'=>0];
- if ($param['token']) {
- $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
- $value = $aec->decrypt($param['token']);
- if (!$value || count(explode('#',$value)) != 6) {
- json(['code'=>1,'msg'=>'token错误','data'=>[]])->send();
- exit;
- }
- $str = explode('#',$value);
- $arr['rootId'] = $str[0];
- $arr['employeeId'] = $str[1];
- $arr['buildingId'] = $str[2];
- $arr['housetypeId'] = $str[3];
- $arr['caseId'] = $str[4];
- $arr['constructionId'] = $str[5];
- }
- $this->params = $arr;
- $this->rootId = $arr['rootId'];
- $this->employeId = $arr['employeeId'];
- //部分接口 需要登陆人员信息
- $employee = ['employeeId'=>0,'rootId'=>0,'uid'=>0,'str'=>''];
- $jwt = $request->header('Authorization');
- if($jwt){
- $jwt = str_replace('bearer ', '', $jwt);
- $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
- try {
- JWT::$leeway = 60; //token的弹性有效时间
- $decoded = JWT::decode($jwt, config('app.jwt_key'), ['HS256']);
- $arr = (array) $decoded;
- $aes = new Aes(config('app.jwt_key'));
- $queryData = $aes->decrypt($arr['data']);
- parse_str($queryData, $token);
- $employee['employeeId'] = $token['employee_id'];
- $employee['rootId'] = $token['root_id'];
- $employee['uid'] = $token['uid'];
- $employee['str'] = $aec->encrypt($token['root_id'].'#'.$token['employee_id']);
- } catch (Exception $e) {
-
- }
- }
- $this->employee = $employee;
- }
- }
|