12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace app\http\middleware;
- use app\hander\HelpHander;
- use think\Db;
- class WxAuth
- {
- public function handle($request, \Closure $next)
- {
- $token = $request->param('token');
- $userId = $request->param('userId');
- if(empty($token) || empty($userId)){
- HelpHander::error('登录信息已失效,请重新登录',-100);
- }
- $arr = explode("9", $token);
- if (empty($arr)||count($arr)!=2) {
- HelpHander::error('登录信息失效,请重新登录',-100);
- }
- //八进制转十进制
- $userid = octdec($arr[0]);
- if (empty($userid)) {
- HelpHander::error('登录信息失效,请重新登录',-100);
- }
- if($userId != $userid){
- HelpHander::error('登录信息失效,请重新登录',-100);
- }
- $ret = Db::name('wxuser')
- ->where('token',$token)
- ->value('id');
- if(!$ret){
- HelpHander::error('登录信息失效,请重新登录',-100);
- }
- if($userId != $ret){
- HelpHander::error('登录信息失效,请重新登录',-100);
- }
- // 检查用户是否被禁用
- $user = Db::name('wxuser')->where('id',$userId)->where('del',0)->where('enable',1)->find();
- if(!$user){
- HelpHander::error('登录信息已失效,请重新登录',-100);
- }
- return $next($request);
- }
- }
|