YiYang

120 经验值

@zhiqueen 如果需要做支付,而且要接收支付后微信的回调请求,记得在VerifyCsrfToken.php里面把回调的uri忽略掉,不然post请求就tokendismatch了。

@dxywx

  server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

root /var/www/alittleone/public;
index index.php index.html index.htm;

# Make site accessible from http://localhost/
server_name 47.90.4.118;

location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    try_files $uri $uri/ /index.php?$query_string; //这里$query_string前面少了个问号
    # Uncomment to enable naxsi on this location
    # include /etc/nginx/naxsi.rules
}

这个是我的配置

@dxywx 我的nginx少了一个问号,等下粘贴配置

问题解决了,我的nginx配置错了。sorry

sorry, 我一开始在你的视频底下发表评论,结果没通过审核貌似。
1.开发者和服务器里面的关于wechat_appid, token等都是一致的. laravel用的是最新版本,服务器部署是参照社区里的教程进行的。

  1. 路由只有两个,一个主页,一个是

Route::any('/wechat','WechatController@serve');

Controller中的代码:

class WechatController extends Controller
{
    //
    /**
     * 处理微信的请求消息
     *
     * @return string
     */
    public function serve()
    {
        Log::info('request arrived.');
        $wechat = app('wechat');
        $wechat->server->setMessageHandler(function($message){
            return "欢迎关注 overtrue!";
        });
        Log::info('return response.');
        return $wechat->server->serve();
    }
}

我查看了easywechat中的Guard.php的源码,结合了storage/logs中的laravel.logwechat.log
其中laravel.log中报错的信息是

BadRequestException in Guard.php line 296: Invalid request.

以下是注释部分我的一些看法,还望指正

public function serve()
    {
        Log::debug('Request received:', [
            'Method' => $this->request->getMethod(),
            'URI' => $this->request->getRequestUri(),
            'Query' => $this->request->getQueryString(),
            'Protocal' => $this->request->server->get('SERVER_PROTOCOL'),
            'Content' => $this->request->getContent(),
        ]);
         //// 在token认证的时候下面这段if里面的内容并没有被执行,我也输出了 $this->request->get('echostr')的结果,日志里显示为null

        if ($str = $this->request->get('echostr')) {            
             Log::debug("Output 'echostr' is '$str'.");
            return new Response($str);
        }
      //下面这段代码反而被执行,在wechat.log中getContent的结果为null,所以handleRequest()方法抛出了异常invalid request
        $result = $this->handleRequest();

        $response = $this->buildResponse($result['to'], $result['from'], $result['response']);

        Log::debug('Server response created:', compact('response'));

        return new Response($response);
    }

第一步微信公众号配置时,token认证总是失败,发现easywechat中get微信传入的echostr时,得到的值一直是null,请问大家有没有遇到过类似的情况