From aeff91adf1cb2cfeabe92a4af1d2734e336835d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E6=AD=A3=E8=B6=85?= Date: Tue, 10 Feb 2015 23:19:41 +0800 Subject: [PATCH] =?UTF-8?q?Created=20=E7=9B=91=E5=90=AC=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=20(markdown)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 监听微信事件.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 监听微信事件.md diff --git a/监听微信事件.md b/监听微信事件.md new file mode 100644 index 0000000..09d4354 --- /dev/null +++ b/监听微信事件.md @@ -0,0 +1,36 @@ +所有的事件都可以很方便的监听与处理,与监听消息一样,同样支持监听全部类型或者指定类型,关于事件类型请参考微信官方文档:http://mp.weixin.qq.com/wiki/2/5baf56ce4947d35003b86a9805634b1e.html + +```php +$wechat->on('event', callable $callback); +// or +$wechat->on('event', string $eventType, callable $callback); +``` + +参数说明 + +- `$eventType` string, 指定要处理的消息类型,ex:`image` +- `$callback` callable, 回调函数,closure匿名函数,或者一切可调用的方法或者函数 + +example: + +```php + +use Overtrue\Wechat\Services\Message; + +// 监听所有事件 +$wechat->on('event', function($event) { + error_log('收到取消关注事件,取消关注者openid: ' . $event['FromUserName']); +}); + +// 只监听指定类型事件 +$wechat->on('event', 'subscribe', function($event) { + + error_log('收到关注事件,关注者openid: ' . $event['FromUserName']); + + return Message::make('text')->content('感谢您关注'); +}); + +$result = $wechat->serve(); + +echo $result; +```