UserCenterAuth.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * Copyrght (C) 2018 Baidu, Inc. All Rights Reserved.
  4. */
  5. /**
  6. * 用户中心通用认证
  7. */
  8. namespace app\api\controller\v1;
  9. use app\api\controller\Api;
  10. use think\Cache;
  11. use think\Env;
  12. use think\Session;
  13. class UserCenterAuth extends Api
  14. {
  15. protected $memberModel;
  16. protected $uid;
  17. protected $game_id;
  18. protected $username;
  19. protected $userid;
  20. public function _initialize()
  21. {
  22. $token = $this->request->get('token');
  23. if (empty($token) || !Cache::store('default')->get($token)) {
  24. $this->error('请先登录!');
  25. }
  26. list($userid, $username, $gameid,$sub_username,$token_random) = explode('|', auth_code($token, "DECODE", Env::get('auth_key')));
  27. $redisTokenRandom = Cache::store('default')->get('token|sdk|'.$userid.'|'.$gameid);
  28. //redis中玩家登录安全控制的随机码不存在时
  29. if ( !$redisTokenRandom ) {
  30. Cache::store('default')->rm($token);
  31. $this->error('token随机码不存在,请重新登录');
  32. }
  33. //两个token随机码不同时
  34. elseif($redisTokenRandom!=$token_random){
  35. Cache::store('default')->rm($token);
  36. $this->error('token随机码错误,请重新登录');
  37. }
  38. $this->userid = $userid;
  39. $this->username = $username;
  40. $this->game_id = $gameid;
  41. Session::set('username', $this->username);
  42. Session::set('game_id', $this->game_id);
  43. Session::set('userid', $this->userid);
  44. Session::set('sub_username', $sub_username);
  45. }
  46. public function index()
  47. {
  48. $this->redirect(url('v1.user_center/index'));
  49. }
  50. public function identity()
  51. {
  52. $this->redirect(url('v1.identity/index'));
  53. }
  54. // public function isVerified()
  55. // {
  56. // $membersTwoModel = new MembersTwo();
  57. // $membersTwoInfo = $membersTwoModel->where(['userid' => $this->userid])->find();
  58. // if (empty($membersTwoInfo) || empty($membersTwoInfo['realname']) || empty($membersTwoInfo['idcard'])) {
  59. // $isVerified = 0;
  60. // } else if ((-1 == $membersTwoInfo['realname']) && (-1 == $membersTwoInfo['idcard'])) {
  61. // $isVerified = 0;
  62. // } else {
  63. // $isVerified = 1;
  64. // }
  65. // if ($isVerified) {
  66. // $this->result("", 1, '已经名验证成功', 'json');
  67. // } else {
  68. // $this->result("", 0, '未实名验证', 'json');
  69. // }
  70. // }
  71. }