Base.php 941 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace app\api\controller\energy;
  3. use app\hander\HelpHander;
  4. use think\Controller;
  5. use think\Db;
  6. class Base extends Controller
  7. {
  8. protected $userId;
  9. protected $orgId;
  10. protected function initialize()
  11. {
  12. parent::initialize();
  13. // $data = [
  14. // 'userId' => 1,
  15. // 'orgId' => 3,
  16. // 'time' => date('Y-m-d H:i:s')
  17. // ];
  18. //
  19. // $token = think_decrypt(think_encrypt(json_encode($data)));
  20. $token = think_decrypt(input('token','','trim'));
  21. if(!$token){
  22. HelpHander::error('token不正确');
  23. }
  24. $tdata = json_decode($token,true);
  25. // $tdata = json_decode(think_decrypt($token),true);
  26. if(!$tdata || !isset($tdata['userId']) || !isset($tdata['orgId'])){
  27. HelpHander::error('token不正确');
  28. }
  29. $this->userId = $tdata['userId'];
  30. $this->orgId = $tdata['orgId'];
  31. }
  32. }