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无法验证 #908

Closed
NominationP opened this issue Sep 5, 2017 · 5 comments
Closed

token无法验证 #908

NominationP opened this issue Sep 5, 2017 · 5 comments

Comments

@NominationP
Copy link

NominationP commented Sep 5, 2017

我用的环境

PHP 版本:7.0(docker)
overtrue/wechat 版本:3.1
laravel 5.4

问题及现象

我把我的步骤以及解决思路写一步一步写上来,请安大神看看问题所在!!!

  1. 这段代码直接放到服务器上(没用到docker,laravel),是可以通过验证的
    http://XXXXXXXXXX/docker_laravel/test_skd
<?php
include __DIR__ . '/vendor/autoload.php'; // 引入 composer 入口文件
use EasyWeChat\Foundation\Application;
$options = [
    'debug'  => true,
    'app_id' => 'wxd9506eba5719xxxx',
    'secret' => 'a27454a19fa4357a182356xxxxxx',
    'token'  => 'easywechat',
    // 'aes_key' => null, // 可选
    'log' => [
        'level' => 'debug',
        'file'  => '/tmp/easywechat.log', // XXX: 绝对路径!!!!
    ],
    //...
];
$app = new Application($options);
$response = $app->server->serve();
// 将响应输出
$response->send(); // Laravel 里请使用:return $response;

  1. 如果放到laravel+docker中,在浏览器刷新http://XXXXXXXXXX:8080/test_skd 返回 Invalid request. 是可以访问到的,说明路径是没错的。
    但是设置的时候还是失败,并且下面代码中的日志 Log::info() 是没有记录的,说明微信配置的时候根本就没有访问到这里
namespace App\Http\Controllers;
include '/var/www/vendor/autoload.php'; // 引入 composer 入口文件 (根据dokcer 的路径)
use EasyWeChat\Foundation\Application;

use Illuminate\Http\Request;
use anlutro\cURL\Laravel\cURL;
use \Cache;
use Log;


class Wechat extends Controller
{	

	public $curl = "";

	function __construct(){

    	$this->curl = new cURL;


	}

	public function test_skd(){

		Log::info("llllllleeeeeeeeewwwww");

		$options = [
		    'debug'  => true,
		    'app_id' => 'wxd9506eba57xxxxx',
		    'secret' => 'a27454a19fa4357a1823563xxxxx',
		    'token'  => 'easywechat',
		    // 'aes_key' => null, // 可选
		    'log' => [
		        'level' => 'debug',
		        'file'  => '/tmp/easywechat.log', // XXX: 绝对路径!!!!
		    ],
		    //...
		];
		$app = new Application($options);
		$response = $app->server->serve();
		// 将响应输出
		// $response->send(); // Laravel 里请使用:return $response;
		return $response;


	}


  1. 于是我认为是微信的请求经过dokcer/laravel 的时候出错了,没传进来,可能是csrf阻挡了?我在VerifyCsrfToken的except中添加了 '/test_skd/*' 还是失败

相关的路由
route/web.php

Route::any("/test_skd", 'Wechat@test_skd')->name('test_skd');
<?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 = [

    	 '/test_skd/*',
        
    ];
}

总结下来,我感觉是在docker laravel 中出现了错误(阻碍),导致微信的请求没有到达?请问安大有碰到过这方面的问题吗?可以给点建议吗,打扰了!!!

@overtrue
Copy link
Collaborator

overtrue commented Sep 5, 2017

请使用 80 端口

@NominationP
Copy link
Author

oooooooh my god !成功了,但是我的那个服务器以前的80端口是有用的,除了把以前的换成其他端口之外(要改好多链接),还有别的办法吗?
微信只能访问到80端口吗?

@overtrue
Copy link
Collaborator

overtrue commented Sep 5, 2017

没有其它办法,微信只支持 80

@overtrue overtrue closed this as completed Sep 5, 2017
@NominationP
Copy link
Author

Thank you very very much !!!

@NominationP
Copy link
Author

端口问题可以用Nginx反向代理来解决

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