// +---------------------------------------------------------------------- namespace app\listener\pay; use app\services\pay\PayNotifyServices; use app\services\wechat\WechatMessageServices; use crmeb\utils\Hook; /** * 支付异步回调 * Class NotifyListener * @package app\listener\pay */ class NotifyListener { /** * @param $event * @return bool * @throws \Psr\SimpleCache\InvalidArgumentException */ public function handle($event) { [$notify, $payType] = $event; if (isset($notify['attach']) && $notify['attach']) { if (($count = strpos($notify['out_trade_no'], '_')) !== false) { $notify['out_trade_no'] = substr($notify['out_trade_no'], $count + 1); } return (new Hook(PayNotifyServices::class, 'wechat'))->listen($notify['attach'], $notify['out_trade_no'], $notify['transaction_id'], $payType); } if ($notify['attach'] === 'wechat' && isset($notify['out_trade_no'])) { /** @var WechatMessageServices $wechatMessageService */ $wechatMessageService = app()->make(WechatMessageServices::class); $wechatMessageService->setOnceMessage($notify, $notify['openid'], 'payment_success', $notify['out_trade_no']); } return false; } }