RefillCallBack.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace refill\moxj_yd;
  3. require_once(BASE_HELPER_RAPI_PATH . '/moxj_yd/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. protected function check_empty($value)
  19. {
  20. if (!isset($value))
  21. return true;
  22. if ($value === null)
  23. return true;
  24. if (trim($value) === "")
  25. return true;
  26. return false;
  27. }
  28. private function sign($params)
  29. {
  30. ksort($params);
  31. $body = "";
  32. foreach ($params as $k => $v)
  33. {
  34. if (false === self::check_empty($v) && "@" != substr($v, 0, 1))
  35. {
  36. $body .= "{$k}={$v}&";
  37. }
  38. }
  39. $body .= config::KEY;
  40. return md5($body);
  41. }
  42. //[$order_id, $success, $can_try, $need_handle]
  43. public function notify($params)
  44. {
  45. $status = intval($params['status']);
  46. $order_sn = $params['customer_order_no'];
  47. $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
  48. if (empty($order_info)) {
  49. return [false, false, false,false];
  50. }
  51. $order_id = $order_info['order_id'];
  52. if ($status === 5) {
  53. $data['official_sn'] = strtolower($params['orderId']) == 'null' ? '' : $params['orderId'];
  54. Model('refill_order')->edit($order_id, $data);
  55. return [$order_id, true, false,true];
  56. }
  57. elseif (in_array($status, [1,4])) {
  58. return [$order_id, false, true,true];
  59. }
  60. else {
  61. return [$order_id, false, false,false];
  62. }
  63. }
  64. }