notify.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * 接收金立后台通知(支付)充值后的回调处理,不需要手动运行。运行地址要注册到创建订单中,
  4. * @version
  5. * 1.0.0 Created at 2017-12-30. by --gwang
  6. * @author gwang (mail@wanggangzero.cn)
  7. * @copyright ? 2017-12-30, SJZ LoyalSoft Corporation & gwang. All rights reserved.
  8. *
  9. */
  10. include_once __DIR__ . '/../../../main.php'; # 导入game utils
  11. include_once __DIR__ . '/../Mo/payResp.php'; # 导入通用返回值结构
  12. include_once __DIR__ . '/../Mo/payRequest.php'; # 导入通用返回值结构
  13. require_once __DIR__ . '/../Mo/OrderNotice.php';
  14. require_once __DIR__ . '/config_for_gionee.php'; # 配置文件,
  15. use loyalsoft\CLog;
  16. use loyalsoft\HttpUtil;
  17. use loyalsoft\pay\OrderNotice;
  18. try {
  19. $params = HttpUtil::getQueryParas(); # 请求数组
  20. CLog::pay("[notify.金立]收到支付回调请求: " . HttpUtil::getQueryString()); # 日志
  21. $cfg = config_for_gionee::Inst(); # 配置信息
  22. if (!$cfg->notify_rsa_verify($params)) { # 校验签名
  23. CLog::pay("[notify.金立]" . " 验签失败! ");
  24. die('error sign'); # 签名验证不通过
  25. }
  26. $order = OrderNotice::Parse_gionee($params); # 将参数归一化到order
  27. // var_dump($order);
  28. if ($order != null) {
  29. if ($order->Check()) { # 订单校验,
  30. if ($order->status == 1) { # 订单状态是成功
  31. $order->UpdateOrderStatus(); # 更新订单状态,->已付款
  32. CLog::pay("[notify.金立] [发货] 订单: " . $order->cpOrderId . ", 金额: " . $order->amount);
  33. } else if ($order->status == 2) { # status为2(failed)的情况
  34. $order->UpdateOrderStatus(); # 直接更新订单状态,->支付失败
  35. CLog::pay("[notify.金立] [不发货] 订单: " . $order->cpOrderId);
  36. } else {
  37. CLog::pay("[notify.金立][处理结果]: FAILURE (未知的支付状态)"); # 日志
  38. die('FAILURE');
  39. }
  40. CLog::pay("[notify.金立][处理结果]:" . "SUCCESS"); # 日志
  41. exit('success'); # 返回给sdk server的响应内容
  42. }
  43. }
  44. CLog::pay("[notify.金立][处理结果]:" . "FAILURE"); # 日志
  45. die('FAILURE'); //返回给sdk server的响应内容 ,对于重复多次通知失败的订单,请参考文档中通知机制。
  46. } catch (Exception $e) {
  47. CLog::pay("[notify.金立]" . $e->getMessage()); # 日志
  48. throw new exception($e->getMessage());
  49. }