下面以支付宝支付插件(apipay)的原理通俗的说明事件的调用原理:
* **事件的调用方式,实例 event(‘Pay’, \['pay\_type' => 'alipay'\]);**
* **查询可实现Pay事件的插件列表:**
* ~~~
通过查询插件配置文件的event.php
return [
'bind' => [
],
'listen' => [
//支付异步回调
'PayNotify' => [
'addon\alipay\event\PayNotify'
],
//支付方式,后台查询
'PayType' => [
'addon\alipay\event\PayType'
],
//支付,前台应用
'Pay' => [
'addon\alipay\event\Pay'
],
'PayClose' => [
'addon\alipay\event\PayClose'
],
'PayRefund' => [
'addon\alipay\event\PayRefund'
],
'PayTransfer' => [
'addon\alipay\event\PayTransfer'
],
'TransferType' => [
'addon\alipay\event\TransferType'
]
],
'subscribe' => [
],
~~~
\];
* **通过实例化对应事件的类文件,建立对象,同时执行对应的方法**
~~~php
例如:事件配置文件中:'addon\alipay\event\Pay',首先创建对象:
$class = new addon\alipay\event\Pay();
其次调用对应handle($param):
$res = $class->handle(['pay_type' => 'alipay']);
~~~
* **循环执行插件配置文件event.php依次返回数据**