| 123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- namespace App\Http\Middleware;
- use App\Model\WxEmployeeOfficial;
- use App\Service\EmployeeService;
- use Closure;
- use Illuminate\Http\Request;
- class CheckWeinxin
- {
- /**
- * Handle an incoming request.
- * 微信公众号中间件
- * @param Request $request
- * @param Closure $next
- * @return mixed
- */
- public function handle($request, Closure $next)
- {
- $token = $request->header('ciphertext');
- if (empty($token)) return response()->json(['code'=>401,'msg'=>'缺少openid','data'=>null]);
- $employee_id = $request->header('employee');
- if (empty($employee_id)) return response()->json(['code'=>401,'msg'=>'缺少人员id','data'=>null]);
- //校验openid是否绑定
- $appid = config("wx_msg.f_appid");
- $bool = WxEmployeeOfficial::where('openid',$token)->where('appid',$appid)->where('employee_id',$employee_id)->exists();
- if (! $bool) return response()->json(['code'=>401,'msg'=>'用户信息错误!','data'=>null]);
- //校验用户
- $checkResult = EmployeeService::checkWxUser($employee_id);
- list($state, $data) = $checkResult;
- if(! $state) return response()->json(['code'=>401,'msg'=>$data,'data'=>null]);
- $request->userData = $data;
- return $next($request);
- }
- }
|