alipay-notify.php 1.6 KB

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