Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

token验证成功,但还是回复暂时不可用,困扰1个星期多了,真心求助!!!有偿都可以!! #922

Closed
NominationP opened this issue Sep 11, 2017 · 18 comments

Comments

@NominationP
Copy link

NominationP commented Sep 11, 2017

我用的环境

PHP 版本:7.0
overtrue/wechat 版本:5.3

用的docker 8080端口。
用nginx反向代理,表面是80端口。

问题及现象

token验证成功。但被动发送消息返回:公众号暂不可用
查看微信平台日志:

类型 文本text
发生时间
2017-9-11 17:05:47

用户openid
ogq-sw7qhbX_2pDucLvZvpMzGt_E

第三方平台名称
无

请求url
http://api.XXXX.cn/laravel/server?signature=1b01baa10f2b0e416be32bfa42bef14a882b1dbe&timestamp=1505120747&nonce=59738028&openid=ogq-sw7qhbX_2pDucLvZvpMzGt_E

第三方URL对应IP
XXXXXXXXXXXXX

请求表单数据
<xml><ToUserName><![CDATA[gh_850c879e4fcd]]></ToUserName> <FromUserName><![CDATA[ogq-sw7qhbX_2pDucLvZvpMzGt_E]]></FromUserName> <CreateTime>1505120747</CreateTime> <MsgType><![CDATA[text]]></MsgType> <Content><![CDATA[发送的信息]]></Content> <MsgId>6464444385366252470</MsgId> </xml>

请求表单数据(解密后)
无

被动回复内容
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <meta name="robots" content="noindex, nofollow" /> <style> body { background-color: #F9F9F9; color: #222; font: 14px/1.4 Helvetica, Arial, sans-serif; margin: 0; padding-bottom: 45px; } a { cursor: pointer; text-decoration: none; } a:hover { text-decoration: underline; } abbr[title] { border-bottom: none; cursor: help; text-decoration: none; } code, pre { font: 13px/1.5 Consolas, Monaco, Menlo, "Ubuntu Mono", "Liberation Mono", monospace; } table, tr, th, td { background: #FFF; border-collapse: collapse; vertical-align: top; } table { background: #FFF; border: 1px solid #E0E0E0; box-shadow: 0px 0px 1px rgba(128, 128, 128, .2); margin: 1em 0; width: 100%; } table th, table td { border: solid #E0E0E0; border-width: 1px 0; padding: 8px 10px; } table th { background-color: #E0E0E0; font-weight: bold; text-align: left; }

被动回复内容(解密后)
无

可以看出是返回的信息内容不对。

laravel日志只能记录到controller初始化之前,刚进函数的日志也记录不到


namespace App\Http\Controllers;
// include '/var/www/vendor/autoload.php'; // 引入 composer 入口文件
use EasyWeChat\Foundation\Application;
use EasyWeChat\Message\Text;
use Illuminate\Http\Request;
use anlutro\cURL\Laravel\cURL;
use \Cache;
use Log;
// define("TOKEN", "hahaha");  
    Log::info(date("H:i:s"));                                   //可以记录到

class Wechat extends Controller                       //以下记录不到

easywechat日志记录信息显示,别无其他了

[2017-09-11 11:43:16] easywechat.DEBUG: Current config: {"debug":true,"app_id":"***f14cb","secret":"***91a95","token":"easywechat","log":{"level":"debug","file":"/var/www/easywechat.log"}} []

困扰了太久了,还请大家帮下忙!!!真的无解,每次做东西都是这样,千奇百怪的错误都被我遇到了

@overtrue
Copy link
Collaborator

代码呢?代码呢?代码呢?

@NominationP
Copy link
Author

NominationP commented Sep 11, 2017

@overtrue

<?php

namespace App\Http\Controllers;
// include '/var/www/vendor/autoload.php'; // 引入 composer 入口文件
use EasyWeChat\Foundation\Application;
use EasyWeChat\Message\Text;


use Illuminate\Http\Request;
use anlutro\cURL\Laravel\cURL;
use \Cache;
use Log;
// define("TOKEN", "hahaha");  
    Log::info(date("H:i:s"));

class Wechat extends Controller
{	
public function server(){

    $options = [
        'debug'  => true,
        'app_id' => 'wx1a15d1b0218f1xxx',
        'secret' => '5f5b2d86ac46bab834641d2xxxx',
        'token'  => 'easywechat',
        // 'aes_key' => null, // 可选
        'log' => [
          'level'      => 'debug',
          // 'permission' => 0777,
          'file'       => '/var/www/easywechat.log',
        ],
        //...
    ];

    $app = new Application($options);

		Log::info("wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww额鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅");

		// 从项目实例中得到服务端应用实例。
		$server = $app->server;

    $server->setMessageHandler(function ($message) {
        return "success";
    });


		$response = $server->serve();
		// $response->send(); // Laravel 里请使用:return $response;
		return $response;

	}
}

web.php

Route::any("/server", 'Wechat@server')->name('server');

@overtrue
Copy link
Collaborator

csrf 添加白名单了么?

@NominationP
Copy link
Author

嗯嗯,可以获取到token @overtrue

@overtrue
Copy link
Collaborator

我问的是 csrf 添加白名单了么?添加了提供截图

@overtrue
Copy link
Collaborator

@NominationP 请不要自做聪明,我问啥你答啥就好,如果你觉得你做得对,那为啥会出问题?请不要浪费宝贵的时间,谢谢!

@NominationP
Copy link
Author

<?php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;

class VerifyCsrfToken extends BaseVerifier
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [

    	
         'valid/*',
         'server/*',

    ];
}

@overtrue
Copy link
Collaborator

很明显你 “/server ” 匹配不上 "server/*" 啊

@NominationP
Copy link
Author

<?php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;

class VerifyCsrfToken extends BaseVerifier
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [

    	
         'valid/*',
         'server',

    ];
}

@overtrue
Copy link
Collaborator

服务器地址

@NominationP
Copy link
Author

谢谢你 可以用了!

@overtrue
Copy link
Collaborator

这玩意儿还需要调试一周,csrf 问题在日志里不是有异常报告么?所以你从来没看过?

@NominationP
Copy link
Author

为什么明明是验证不通过却没有在laravel日志中显示呢?

@overtrue
Copy link
Collaborator

不可能!日志里绝对有报错日志,你自己不看

@NominationP
Copy link
Author

我也纳闷,日志中是没有的/storage/logs/laravel.log是指这个日志吗

@NominationP
Copy link
Author

除了一些我自己直接用URL的错误,就是我自己标记的,没有别的

[2017-09-11 08:57:57] local.INFO: 08:57:57  
[2017-09-11 08:58:56] local.INFO: 08:58:56  
[2017-09-11 08:59:16] local.INFO: 08:59:16  
[2017-09-11 08:59:39] local.INFO: 08:59:39  
[2017-09-11 09:00:39] local.INFO: 09:00:39  
[2017-09-11 09:00:39] local.INFO: wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww额鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅  
[2017-09-11 09:00:53] local.INFO: 09:00:53  
[2017-09-11 09:01:02] local.INFO: 09:01:02  
[2017-09-11 09:01:15] local.INFO: 09:01:15  
[2017-09-11 09:01:15] local.INFO: wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww额鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅  
[2017-09-11 09:02:44] local.INFO: 09:02:44  
[2017-09-11 09:02:44] local.INFO: wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww额鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅  
[2017-09-11 09:03:06] local.INFO: 09:03:06  
[2017-09-11 09:03:06] local.INFO: wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww额鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅  
[2017-09-11 09:03:18] local.INFO: 09:03:18  
[2017-09-11 09:04:39] local.INFO: 09:04:39  
[2017-09-11 09:04:39] local.INFO: wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww额鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅  
[2017-09-11 09:04:39] local.ERROR: EasyWeChat\Server\BadRequestException: Invalid request. in /var/www/vendor/overtrue/wechat/src/Server/Guard.php:343
Stack trace:
#0 /var/www/vendor/overtrue/wechat/src/Server/Guard.php(359): EasyWeChat\Server\Guard->getMessage()
#1 /var/www/vendor/overtrue/wechat/src/Server/Guard.php(156): EasyWeChat\Server\Guard->handleRequest()
#2 /var/www/app/Http/Controllers/Wechat.php(146): EasyWeChat\Server\Guard->serve()
#3 [internal function]: App\Http\Controllers\Wechat->server()
#4 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(55): call_user_func_array(Array, Array)
#5 /var/www/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(44): Illuminate\Routing\Controller->callAction('server', Array)
#6 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Route.php(203): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(App\Http\Controllers\Wechat), 'server')
#7 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Route.php(160): Illuminate\Routing\Route->runController()
#8 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(572): Illuminate\Routing\Route->run()
#9 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#10 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(41): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#11 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Routing\Middleware\SubstituteBindings->handle(Object(Illuminate\Http\Request), Object(Closure))
#12 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#13 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(65): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#14 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))
#15 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#16 /var/www/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#17 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#18 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#19 /var/www/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#20 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#21 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#22 /var/www/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#23 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
#24 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#25 /var/www/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(59): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#26 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))
#27 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#28 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#29 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(574): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#30 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(533): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#31 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(511): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#32 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(176): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#33 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))
#34 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(30): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#35 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))
#36 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#37 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(30): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#38 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))
#39 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#40 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#41 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle(Object(Illuminate\Http\Request), Object(Closure))
#42 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#43 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(46): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#44 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#45 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#46 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#47 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(151): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#48 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(116): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#49 /var/www/public/index.php(53): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#50 {main}  
[2017-09-11 09:05:47] local.INFO: 09:05:47  

@NominationP
Copy link
Author

NominationP commented Sep 12, 2017

没有日志的原因是因为 app/Exceptions/Handler.php 中默认设置的,注释掉就有了。。。不明白官方为什么要这样做。

    protected $dontReport = [
        \Illuminate\Auth\AuthenticationException::class,
        \Illuminate\Auth\Access\AuthorizationException::class,
        \Symfony\Component\HttpKernel\Exception\HttpException::class,
        \Illuminate\Database\Eloquent\ModelNotFoundException::class,
        \Illuminate\Session\TokenMismatchException::class,             //这行        
        \Illuminate\Validation\ValidationException::class,
    ];

@overtrue
Copy link
Collaborator

😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants