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

好奇怪啊,开发者中心的服务器配置已经提交并验证成功了,可是message不起作用 #10

Closed
phoenixg opened this issue Apr 29, 2015 · 17 comments

Comments

@phoenixg
Copy link

require "./autoload.php";

use Overtrue\Wechat\Server;

$appId          = 'myapp';
$token          = 'testtoken';
$encodingAESKey = 'myaeskey';

$server = new Server($appId, $token, $encodingAESKey);

$server->on('message', function($message){
    return "您好!欢迎关注 overtrue!";
});

为什么用户给公众号发消息却收不到“您好!欢迎关注 overtrue!"“

@overtrue
Copy link
Collaborator

你服务器上有日志吗?看看有没有啥报错之类的

@phoenixg
Copy link
Author

查看了服务器日志没有报错,点开firebug net标签,200状态,但是响应内容html是:
Reload the page to get source for: http://(隐藏)/overtrue-wechat/dork.php

@overtrue
Copy link
Collaborator

require "./autoload.php";

use Overtrue\Wechat\Server;

$appId          = 'myapp';
$token          = 'testtoken';
$encodingAESKey = 'myaeskey';

$server = new Server($appId, $token, $encodingAESKey);

$server->on('message', function($message){
    return "您好!欢迎关注 overtrue!";
});

// 貌似你少了这句
echo $server->serve();

@phoenixg
Copy link
Author

echo这句是我注释掉了,但是我加了这句还是没有输出啊

@18601673727
Copy link

我也碰到这问题了

<?php

use Overtrue\Wechat\Message;
use Overtrue\Wechat\Server;

class WechatController extends BaseController
{

    public function test()
    {
        $appId = '***';
        $appSecret = '***';
        $token = '***';
        $encodingAESKey = '***';

        $server = new Server($appId, $token, $encodingAESKey);

        // 监听所有类型
        $server->on('message', function ($message) {
            Log::error($message);
            return Message::make('text')->content('您好!');
        });

        // 监听指定类型
        $server->on('message', 'image', function ($message) {
            return Message::make('text')->content('我们已经收到您发送的图片!');
        });

        // 监听所有事件
        $server->on('event', function ($event) {
            Log::error('收到取消关注事件,取消关注者openid: ' . $event['FromUserName']);
        });

        // 只监听指定类型事件
        $server->on('event', 'subscribe', function ($event) {

            Log::error('收到关注事件,关注者openid: ' . $event['FromUserName']);

            return Message::make('text')->content('感谢您关注');
        });

        $result = $server->serve();

        echo $result;
    }

}

@phoenixg
Copy link
Author

@18601673727 你这是写在laravel里面的? 我是独立调用

@18601673727
Copy link

@phoenixg 是的,无任何log或其他线索,routes.php里是这样的:

Route::any('wechat', ['uses' => 'WechatController@test']);

@18601673727
Copy link

不光message不能用,event也不行的

@overtrue
Copy link
Collaborator

@phoenixg @18601673727 不好意思,是一个隐形bug

@18601673727
Copy link

还是不行,"该公众号暂时无法提供服务,请稍后再试"

@overtrue
Copy link
Collaborator

更新了?

@overtrue overtrue reopened this Apr 30, 2015
@overtrue overtrue closed this as completed May 1, 2015
@18601673727
Copy link

肯定是最新版,因为我当时看到你关闭了这个issue,以为解决了

// 回调内
Log::info($message); // 正常json
Log::info(var_dump(Message::make('text')->content('您好'))); // [2015-05-04 17:47:40] production.INFO:  [] []

// 回调外部
Log::info($result); // 正常xml
Log::info(var_dump($server)); // [2015-05-04 17:47:40] production.INFO:  [] []

我的Laravel 版本是4.2,未加入alias/provider,只是在<?php 后面use了一把,这个没关系吧?

@18601673727
Copy link

@phoenixg 你已经搞定啦?

@phoenixg
Copy link
Author

phoenixg commented May 4, 2015

@18601673727 yes, download latest version and try, but I'm not using with laravel, I'm using the standalone version

@overtrue
Copy link
Collaborator

overtrue commented May 4, 2015

@18601673727 同学,var_dump没有返回值:

Log::info(var_dump(Message::make('text')->content('您好')));

应该是:

Log::info(Message::make('text')->content('您好'));

@18601673727
Copy link

@overtrue

学到了,谢谢,不过在我写这些Log::info()之前就**“该公众号暂时无法提供服务,请稍后再试”**,调了几小时最终删掉外网vendor文件夹重新上传搞定了,之前都是覆盖……

@overtrue
Copy link
Collaborator

overtrue commented May 5, 2015

@18601673727 好吧。。。

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

3 participants