RefillCallBack.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace refill\zhiren_doubi;
  3. require_once(BASE_HELPER_RAPI_PATH . '/zhiren_doubi/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['verifyString']);
  11. $sign = $this->sign($input);
  12. if ($params['verifyString'] == $sign) {
  13. return true;
  14. } else {
  15. return false;
  16. }
  17. }
  18. private function sign($params)
  19. {
  20. ksort($params);
  21. $content = '';
  22. foreach ($params as $key => $value) {
  23. if($this->check_empty($value) === false) {
  24. $content .= "{$key}={$value}&";
  25. }
  26. }
  27. $content = $content . "key=" . config::Key;
  28. return md5($content);
  29. }
  30. private function check_empty($value)
  31. {
  32. if (!isset($value))
  33. return true;
  34. if ($value === null)
  35. return true;
  36. if (trim($value) === "")
  37. return true;
  38. return false;
  39. }
  40. public function notify($params)
  41. {
  42. $status = intval($params['status']);
  43. $order_sn = $params['clientOrderNo'];
  44. $order_info = Model('vr_order')->getOrderInfoForNotify(['order_sn' => $order_sn]);
  45. if (empty($order_info)) {
  46. return [false, false, false,false];
  47. }
  48. $order_id = $order_info['order_id'];
  49. if ($status === 4) {
  50. $data['official_sn'] = strtolower($params['officialOrderNo']) == 'null' ? '' : $params['officialOrderNo'];
  51. Model('refill_order')->edit($order_id, $data);
  52. return [$order_id, true, false, true];
  53. } elseif ($status === 3) {
  54. return [$order_id, false, true, true];
  55. } else {
  56. return [$order_id, false, false, false];
  57. }
  58. }
  59. }