Enjoy.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. declare(strict_types=1);
  3. namespace app\mobile\controller;
  4. use Exception;
  5. use think\facade\Request;
  6. use Firebase\JWT\JWT;
  7. use openssl\Aes;
  8. use toolkits\Aec;
  9. use think\exception\HttpException;
  10. use think\Request as RequestModel;
  11. class Enjoy
  12. {
  13. public $params;
  14. public $rootId;
  15. public $employeeId;
  16. public $employee;
  17. public function __construct(RequestModel $request){
  18. $param = Request::only(['token'=>'']);
  19. //分享楼书的接口需要传token
  20. //店面id ,分享人id , 楼盘id , 户型id , 案例id , 在施工地id
  21. $arr = ['rootId'=>0,'employeeId'=>0,'buildingId'=>0,'housetypeId'=>0,'cateId'=>0,'constructionId'=>0];
  22. if ($param['token']) {
  23. $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
  24. $value = $aec->decrypt($param['token']);
  25. if (!$value || count(explode('#',$value)) != 6) {
  26. json(['code'=>1,'msg'=>'token错误','data'=>[]])->send();
  27. exit;
  28. }
  29. $str = explode('#',$value);
  30. $arr['rootId'] = $str[0];
  31. $arr['employeeId'] = $str[1];
  32. $arr['buildingId'] = $str[2];
  33. $arr['housetypeId'] = $str[3];
  34. $arr['caseId'] = $str[4];
  35. $arr['constructionId'] = $str[5];
  36. }
  37. $this->params = $arr;
  38. $this->rootId = $arr['rootId'];
  39. $this->employeId = $arr['employeeId'];
  40. //部分接口 需要登陆人员信息
  41. $employee = ['employeeId'=>0,'rootId'=>0,'uid'=>0,'str'=>''];
  42. $jwt = $request->header('Authorization');
  43. if($jwt){
  44. $jwt = str_replace('bearer ', '', $jwt);
  45. $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
  46. try {
  47. JWT::$leeway = 60; //token的弹性有效时间
  48. $decoded = JWT::decode($jwt, config('app.jwt_key'), ['HS256']);
  49. $arr = (array) $decoded;
  50. $aes = new Aes(config('app.jwt_key'));
  51. $queryData = $aes->decrypt($arr['data']);
  52. parse_str($queryData, $token);
  53. $employee['employeeId'] = $token['employee_id'];
  54. $employee['rootId'] = $token['root_id'];
  55. $employee['uid'] = $token['uid'];
  56. $employee['str'] = $aec->encrypt($token['root_id'].'#'.$token['employee_id']);
  57. } catch (Exception $e) {
  58. }
  59. }
  60. $this->employee = $employee;
  61. }
  62. }