alipay-notify.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | WeChatDeveloper
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2023 ThinkAdmin [ thinkadmin.top ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: https://thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // | 免责声明 ( https://thinkadmin.top/disclaimer )
  11. // +----------------------------------------------------------------------
  12. // | gitee 代码仓库:https://gitee.com/zoujingli/WeChatDeveloper
  13. // | github 代码仓库:https://github.com/zoujingli/WeChatDeveloper
  14. // +----------------------------------------------------------------------
  15. // 1. 手动加载入口文件
  16. include "../include.php";
  17. // 2. 准备公众号配置参数
  18. $config = include "./alipay.php";
  19. try {
  20. // 实例支付对象
  21. // $pay = \We::AliPayApp($config);
  22. // $pay = new \AliPay\App($config);
  23. $pay = \AliPay\App::instance($config);
  24. $data = $pay->notify();
  25. if (in_array($data['trade_status'], ['TRADE_SUCCESS', 'TRADE_FINISHED'])) {
  26. // @todo 更新订单状态,支付完成
  27. file_put_contents('notify.txt', "收到来自支付宝的异步通知\r\n", FILE_APPEND);
  28. file_put_contents('notify.txt', '订单号:' . $data['out_trade_no'] . "\r\n", FILE_APPEND);
  29. file_put_contents('notify.txt', '订单金额:' . $data['total_amount'] . "\r\n\r\n", FILE_APPEND);
  30. } else {
  31. file_put_contents('notify.txt', "收到异步通知\r\n", FILE_APPEND);
  32. }
  33. } catch (\Exception $e) {
  34. // 异常处理
  35. echo $e->getMessage();
  36. }