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

Server消息回复必须以事件方式吗? #140

Closed
iam993 opened this issue Oct 28, 2015 · 4 comments
Closed

Server消息回复必须以事件方式吗? #140

iam993 opened this issue Oct 28, 2015 · 4 comments

Comments

@iam993
Copy link

iam993 commented Oct 28, 2015

看了一下代码,如果要回复消息,必须使用server的on方法来驱动。

有没有一种方法,消息类型,内容等自己判断,然后通过类似
setReplyMessage ( Message::make ( 'text' )->content( 'test' ) );
最后使用echo $server->serve();

或者说直接replyMessage ( Message::make ( 'text' )->content( 'test' ) );

总感觉靠server的事件驱动回复有点过度封装了。

@overtrue
Copy link
Collaborator

@iam993 你在事件里做啥都行啊,没做啥封装啊。

@iam993
Copy link
Author

iam993 commented Oct 28, 2015

$str = "test";
$server = new Server($this->appId, $this->token, $this->aeskey);
$server->on('message',function(){
return Message::make('text')->content($str);
});
这样就不行。

那怎么在回调方法内方便的调用方法外的变量呢?

@overtrue
Copy link
Collaborator

http://php.net/manual/zh/functions.anonymous.php

$foo = 1;
function ($xxx) use ($foo, $bar, ....其它)

@iam993
Copy link
Author

iam993 commented Oct 28, 2015

我重构了你server这块,能实现了,但是不那么‘优雅’ ,勉强凑合用吧。

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