RefillCallBack.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace refill\gftd;
  3. require_once(BASE_HELPER_RAPI_PATH . '/gftd/config.php');
  4. use refill;
  5. class RefillCallBack implements refill\IRefillCallBack
  6. {
  7. public function verify($params): bool
  8. {
  9. $input = $params;
  10. unset($input['signature']);
  11. $sign = $this->sign($input);
  12. if ($params['signature'] == $sign) {
  13. return true;
  14. } else {
  15. return false;
  16. }
  17. }
  18. private function sign($params)
  19. {
  20. $body = $this->body($params);
  21. $body .= config::APP_SECRET;
  22. return md5($body);
  23. }
  24. protected function check_empty($value)
  25. {
  26. if (!isset($value))
  27. return true;
  28. if ($value === null)
  29. return true;
  30. if (trim($value) === "")
  31. return true;
  32. return false;
  33. }
  34. private function body($params)
  35. {
  36. ksort($params);
  37. $body = "";
  38. $i = 0;
  39. foreach ($params as $k => $v)
  40. {
  41. if (false === $this->check_empty($v) && "@" != substr($v, 0, 1))
  42. {
  43. if ($i == 0) {
  44. $body .= "{$k}" . "=" . $v;
  45. } else {
  46. $body .= "&" . "{$k}" . "=" . $v;
  47. }
  48. $i++;
  49. }
  50. }
  51. return $body;
  52. }
  53. public function notify($params)
  54. {
  55. $status = intval($params['status']);
  56. $order_sn = $params['channelOrderNumber'];
  57. $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
  58. if (empty($order_info)) {
  59. return [false, false, false,false];
  60. }
  61. $order_id = $order_info['order_id'];
  62. $data['official_sn'] = $params['voucher'];
  63. $data['ch_trade_no'] = $params['orderNumber'];
  64. $data['err_msg'] = $params['message'];
  65. Model('refill_order')->edit($order_id, $data);
  66. //[$order_id, 成功失败, 是否能重试,接下来是否需要处理]
  67. if ($status === 101) {
  68. return [$order_id, true, false,true];
  69. }
  70. elseif ($status === 109) {
  71. $this->onError($params['message'],$order_id);
  72. return [$order_id, false, false,true];
  73. }
  74. elseif ($status === 120) {
  75. return [$order_id, false, false,false];
  76. }
  77. else {
  78. return [$order_id, false, false,false];
  79. }
  80. }
  81. public function onError($msg,$order_id)
  82. {
  83. if(in_array($msg,config::BlackMsgs))
  84. {
  85. $refill = Model('refill_order');
  86. $order = $refill->getOrderInfo(['order_id' => $order_id]);
  87. if(empty($order)) return false;
  88. $card_no = $order['card_no'];
  89. if(!empty($card_no)) {
  90. refill\util::set_black($card_no);
  91. return true;
  92. }
  93. }
  94. return false;
  95. }
  96. }