PayNotifyListener.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\listener\pay;
  12. use app\services\pay\PayNotifyServices;
  13. use app\services\wechat\WechatMessageServices;
  14. use crmeb\utils\Hook;
  15. /**
  16. * 支付回调
  17. * Class PayNotifyListener
  18. * @package app\listener\pay
  19. */
  20. class PayNotifyListener
  21. {
  22. /**
  23. * @param $event
  24. * @return bool
  25. * @throws \Psr\SimpleCache\InvalidArgumentException
  26. */
  27. public function handle($event)
  28. {
  29. [$notify] = $event;
  30. if (isset($notify['attach']) && $notify['attach']) {
  31. if (($count = strpos($notify['out_trade_no'], '_')) !== false) {
  32. $notify['out_trade_no'] = substr($notify['out_trade_no'], $count + 1);
  33. }
  34. return (new Hook(PayNotifyServices::class, 'wechat'))->listen($notify['attach'], $notify['out_trade_no'], $notify['transaction_id']);
  35. }
  36. /** @var WechatMessageServices $wechatMessageService */
  37. $wechatMessageService = app()->make(WechatMessageServices::class);
  38. $wechatMessageService->setOnceMessage($notify, $notify['openid'], 'payment_success', $notify['out_trade_no']);
  39. return false;
  40. }
  41. }