AlipayNotify.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 crmeb\services\alipay;
  12. use Payment\Contracts\IPayNotify;
  13. use think\exception\ValidateException;
  14. use think\facade\Log;
  15. class AlipayNotify implements IPayNotify
  16. {
  17. private $type;
  18. public function __construct($type)
  19. {
  20. $this->type = $type;
  21. }
  22. public function handle(string $channel, string $notifyType, string $notifyWay, array $notifyData)
  23. {
  24. Log::info('支付宝支付回调' . var_export($notifyData, 1));
  25. if (!in_array($notifyData['trade_status'], ['TRADE_SUCCESS', 'TRADE_FINISHED']))
  26. throw new ValidateException('未支付');
  27. try {
  28. event('pay_success_' . $this->type, ['order_sn' => $notifyData['out_trade_no'], 'data' => $notifyData]);
  29. return true;
  30. } catch (\Exception$e) {
  31. Log::info('支付宝支付回调失败:' . $e->getMessage());
  32. }
  33. return false;
  34. }
  35. }