总结:
在上一篇文章中,我们使用了中间节对echostr的验证是起不到验证的作用的
这一篇我们对代码进行稍微的改动下图
1.中间件代码优化版本
/* author:咔咔 wechat:fangkangfk */ <?php namespace app\http; use WeixinUtil; use Log; class WeixinMiddleware { public function handle($request, \Closure $next) { // if($request->param('echostr')){ // Log::write('这是第一次校验'); // return response(WeixinUtil::check()); // } // return $next($request); /* 中间件会返回一个response的对象 应用场景比如用户登录 */ if(WeixinUtil::check()){ if($request->param('echostr')){ // 响应(Response)对象用于动态响应客户端请求,控制发送给用户的信息。通常用于输出数据给客户端或者浏览器。 return response($request->param('echostr')); } return $next($request); }else{ return response('对不起访问错误'); } } }