AlipayNotify.php 908 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace ln\services\alipay;
  3. use Payment\Contracts\IPayNotify;
  4. use think\exception\ValidateException;
  5. use think\facade\Log;
  6. class AlipayNotify implements IPayNotify
  7. {
  8. private $type;
  9. public function __construct($type)
  10. {
  11. $this->type = $type;
  12. }
  13. public function handle(string $channel, string $notifyType, string $notifyWay, array $notifyData)
  14. {
  15. Log::info('支付宝支付回调' . var_export($notifyData, 1));
  16. if (!in_array($notifyData['trade_status'], ['TRADE_SUCCESS', 'TRADE_FINISHED']))
  17. throw new ValidateException('未支付');
  18. try {
  19. event('pay_success_' . $this->type, ['order_sn' => $notifyData['out_trade_no'], 'data' => $notifyData]);
  20. return true;
  21. } catch (\Exception$e) {
  22. Log::info('支付宝支付回调失败:' . $e->getMessage());
  23. }
  24. return false;
  25. }
  26. }