0
0

WxAuth.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace app\http\middleware;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. class WxAuth
  6. {
  7. public function handle($request, \Closure $next)
  8. {
  9. $token = $request->param('token');
  10. $userId = $request->param('userId');
  11. if(empty($token) || empty($userId)){
  12. HelpHander::error('登录信息已失效,请重新登录',-100);
  13. }
  14. $arr = explode("9", $token);
  15. if (empty($arr)||count($arr)!=2) {
  16. HelpHander::error('登录信息失效,请重新登录',-100);
  17. }
  18. //八进制转十进制
  19. $userid = octdec($arr[0]);
  20. if (empty($userid)) {
  21. HelpHander::error('登录信息失效,请重新登录',-100);
  22. }
  23. if($userId != $userid){
  24. HelpHander::error('登录信息失效,请重新登录',-100);
  25. }
  26. $ret = Db::name('wxuser')
  27. ->where('token',$token)
  28. ->value('id');
  29. if(!$ret){
  30. HelpHander::error('登录信息失效,请重新登录',-100);
  31. }
  32. if($userId != $ret){
  33. HelpHander::error('登录信息失效,请重新登录',-100);
  34. }
  35. // 检查用户是否被禁用
  36. $user = Db::name('wxuser')->where('id',$userId)->where('del',0)->where('enable',1)->find();
  37. if(!$user){
  38. HelpHander::error('登录信息已失效,请重新登录',-100);
  39. }
  40. return $next($request);
  41. }
  42. }