mirror of
https://github.com/w7corp/easywechat.git
synced 2025-01-22 19:52:10 +00:00
Created 监听微信事件 (markdown)
parent
f8809bec5d
commit
aeff91adf1
36
监听微信事件.md
Normal file
36
监听微信事件.md
Normal file
@ -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;
|
||||||
|
```
|
Loading…
Reference in New Issue
Block a user