pay-order-notify.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. try {
  16. // 1. 手动加载入口文件
  17. include "../include.php";
  18. // 2. 准备公众号配置参数
  19. $config = include "./config.php";
  20. // 3. 创建接口实例
  21. // $wechat = new \WeChat\Pay($config);
  22. // $wechat = \We::WeChatPay($config);
  23. $wechat = \WeChat\Pay::instance($config);
  24. // 4. 获取通知参数
  25. $data = $wechat->getNotify();
  26. if ($data['return_code'] === 'SUCCESS' && $data['result_code'] === 'SUCCESS') {
  27. // @todo 去更新下原订单的支付状态
  28. $order_no = $data['out_trade_no'];
  29. // 返回接收成功的回复
  30. ob_clean();
  31. echo $wechat->getNotifySuccessReply();
  32. }
  33. } catch (Exception $e) {
  34. // 出错啦,处理下吧
  35. echo $e->getMessage() . PHP_EOL;
  36. }