notify.php 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. ini_set('date.timezone', 'Asia/Shanghai');
  3. error_reporting(E_ERROR);
  4. require_once __DIR__ . '/../../../../main.php'; # 导入game utils
  5. include_once __DIR__ . '/../../Mo/payResp.php'; # 导入通用返回值结构
  6. include_once __DIR__ . '/../../Mo/payRequest.php'; # 导入通用返回值结构
  7. require_once __DIR__ . '/../../Mo/OrderNotice.php'; # 导入通知数据接收模型
  8. require_once __DIR__ . '/wx.php'; # 导入微信支付lib
  9. use loyalsoft\CLog;
  10. use loyalsoft\HttpUtil;
  11. class PayNotifyCallBack extends WxPayNotify {
  12. //查询订单
  13. public function Queryorder($transaction_id) {
  14. $input = new WxPayOrderQuery();
  15. $input->SetTransaction_id($transaction_id);
  16. $result = WxPayApi::orderQuery($input);
  17. CLog::pay("[notify.wx]query:" . json_encode($result));
  18. if (array_key_exists("return_code", $result) && array_key_exists("result_code", $result)#
  19. && $result["return_code"] == "SUCCESS" #
  20. && $result["result_code"] == "SUCCESS") {
  21. return true;
  22. }
  23. return false;
  24. }
  25. //重写回调处理函数
  26. public function NotifyProcess($data, &$msg) {
  27. CLog::pay("[notify.wx]call back:" . json_encode($data));
  28. // $notfiyOutput = array();
  29. if (!array_key_exists("transaction_id", $data)) {
  30. $msg = "输入参数不正确";
  31. CLog::pay("[notify.wx] $msg"); # 日志
  32. return false;
  33. }
  34. //查询订单,判断订单真实性
  35. if (!$this->Queryorder($data["transaction_id"])) {
  36. $msg = "订单查询失败";
  37. CLog::pay("[notify.wx] $msg"); # 日志
  38. return false;
  39. }
  40. $order = loyalsoft\pay\OrderNotice::Parse_weixinpayOrder($data); # 提取参数
  41. CLog::pay($order);
  42. if ($order == null) { #
  43. $msg = "提取通知参数失败";
  44. CLog::pay("[notify.wx] $msg"); # 日志
  45. return false;
  46. }
  47. if (!$order->Check()) { # 订单校验,
  48. $msg = "订单校验失败";
  49. CLog::pay("[notify.wx] $msg"); # 日志
  50. return false;
  51. }
  52. if ($order->status == 2) { # status为2(failed)的情况
  53. $order->UpdateOrderStatus(); # [数据库操作]直接更新订单状态,->支付失败
  54. $msg = "订单状态异常";
  55. CLog::pay("[notify.wx] 异常的订单状态, 此处微信验证已通过,为啥自己的验证不通过!!!" . $order->cpOrderId);
  56. return false;
  57. }
  58. if ($order->status == 1) { # 订单状态是成功 1代表支付成功
  59. $order->UpdateOrderStatus(); # [数据库操作]更新订单状态,->已付款
  60. // if (PLAT == 'tap') {
  61. loyalsoft\TapDBUtil::PushPayEvent($order, 'wxpay'); # 向tapdb推送充值记录
  62. // }
  63. CLog::pay("[notify.wx] [发货] " . $order->cpOrderId . " >>> " . $order->amount);
  64. $msg = "success";
  65. return true;
  66. }
  67. $msg = "未知的支付状态";
  68. CLog::pay("[notify.wx][处理结果]: FAILURE ($msg)"); # 日志
  69. return false;
  70. }
  71. }
  72. HttpUtil::PostOnly();
  73. CLog::pay("[notify.wx] [收到通知]: " . HttpUtil::getQueryString()); # 日志
  74. $notify = new PayNotifyCallBack();
  75. $notify->Handle(false); # 处理