notify.php 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Description of notify.php
  4. * 九游充值结果回调接口
  5. * @version
  6. * 1.0.0 Created at 2017-12-21. by --gwang
  7. * @author gwang (mail@wanggangzero.cn)
  8. * @copyright ? 2017-12-21, SJZ LoyalSoft Corporation & gwang. All rights reserved.
  9. */
  10. /**
  11. * 1. 提取参数
  12. * 2. 校验
  13. * 3. 转成订单数据
  14. * 4. 分析订单状态
  15. * 5. 依状态处理对应逻辑
  16. * 6. 入库mysql+日志
  17. * 7. 返回
  18. */
  19. // 导入game库
  20. include_once __DIR__ . '/../../../main.php';
  21. require_once __DIR__ . '/service/SDKServerService.php';
  22. require_once __DIR__ . '/model/SDKException.php';
  23. require_once __DIR__ . '/util/ConfigHelper.php';
  24. require_once __DIR__ . '/util/LoggerHelper.php';
  25. require_once __DIR__ . '/../Mo/OrderNotice.php';
  26. use loyalsoft\CLog;
  27. use loyalsoft\HttpUtil;
  28. use loyalsoft\pay\OrderNotice;
  29. try {
  30. $request = HttpUtil::getQueryString(); // 接收HTTP POST信息
  31. CLog::pay('[uc.notify]收到的支付回调请求:' . $request);
  32. $responseData = json_decode($request, true); // 处理支付回调请求
  33. if ($responseData != null) {
  34. CLog::pay('[uc.notify]' . var_export($responseData, true));
  35. $baseService = new BaseSDKService();
  36. $signSource = $baseService->getSignData($responseData['data'])
  37. . ConfigHelper::getStrVal("sdkserver.game.apikey"); //组装签名原文
  38. $sign = md5($signSource); //MD5加密签名
  39. CLog::pay("[uc.notify][签名原文]:" . $signSource);
  40. CLog::pay("[uc.notify][签名结果]:" . $sign);
  41. if ($sign == $responseData['sign']) {
  42. //游戏需根据orderStatus参数的值判断是否给玩家过账虚拟货币。(S为充值成功、F为充值失败,避免假卡、无效卡充值成功)
  43. $order = OrderNotice::Parse_UcOrder($responseData);
  44. if ($order->Check()) { # 校验订单
  45. if ($order->status == 1) { # 订单状态是成功
  46. $order->UpdateOrderStatus(); # 更新订单状态,->已付款
  47. CLog::pay("[uc.notify][发货] 订单ID: " . $order->cpOrderId . ", 金额(分): " . $order->amount);
  48. } else if ($order->status == 2) { # status为2(failed)的情况
  49. $order->UpdateOrderStatus(); # 直接更新订单状态,->支付失败
  50. CLog::pay("[uc.notify][不发货] 订单ID: " . $order->cpOrderId);
  51. } else {
  52. echo 'FAILURE';
  53. CLog::pay("[uc.notify][处理结果]: FAILURE (未知的支付状态)"); # 日志
  54. return;
  55. }
  56. CLog::pay("[uc.notify][处理结果]:" . "SUCCESS");
  57. echo 'SUCCESS'; //返回给sdk server的响应内容
  58. return;
  59. }
  60. }
  61. CLog::pay("[uc.notify][处理结果]:" . "FAILURE");
  62. echo 'FAILURE'; //返回给sdk server的响应内容 ,对于重复多次通知失败的订单,请参考文档中通知机制。
  63. return;
  64. } else {
  65. CLog::pay("[uc.notify] 提取参数失败:" . $request);
  66. throw new exception('json_decode()异常');
  67. }
  68. } catch (SDKException $e) {
  69. CLog::pay("[uc.notify] 程序执行异常:" . $e->getMessage());
  70. throw new exception($e->getMessage());
  71. }