RefillCallBack.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace refill\moxj_new;
  3. require_once(BASE_HELPER_RAPI_PATH . '/moxj_new/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['sign']);
  11. $sign = $this->sign($input);
  12. if ($params['sign'] == $sign) {
  13. return true;
  14. } else {
  15. return false;
  16. }
  17. }
  18. private function sign($params)
  19. {
  20. ksort($params);
  21. $body = "";
  22. $key = config::KEY;
  23. foreach ($params as $k => $v)
  24. {
  25. $body .= "{$k}={$v}&";
  26. }
  27. $body .= "key={$key}";
  28. return strtoupper(md5($body));
  29. }
  30. //[$order_id, $success, $can_try, $need_handle]
  31. public function notify($params)
  32. {
  33. $status = intval($params['code']);
  34. $order_sn = $params['partner_order_no'];
  35. $order_info = Model('vr_order')->getOrderInfoForNotify(['order_sn' => $order_sn]);
  36. if (empty($order_info)) {
  37. return [false, false, false,false];
  38. }
  39. $order_id = $order_info['order_id'];
  40. if ($status === 2001) {
  41. $data['official_sn'] = strtolower($params['official_order_no']) == 'null' ? '' : $params['official_order_no'];
  42. Model('refill_order')->edit($order_id, $data);
  43. return [$order_id, true, false,true];
  44. }
  45. elseif ($status === 2000) {
  46. //2000为充值中
  47. return [$order_id, false, false,false];
  48. }
  49. else {
  50. //其余皆失败
  51. return [$order_id, false, true,true];
  52. }
  53. }
  54. }