RefillCallBack.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace refill\piaoyi_oil;
  3. require_once(BASE_HELPER_RAPI_PATH . '/piaoyi_oil/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. $content = '';
  22. foreach ($params as $key => $value) {
  23. if($this->check_empty($value) === false) {
  24. $content .= "{$key}{$value}";
  25. }
  26. }
  27. $content .= 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['orderStatus']);
  43. $order_sn = $params['outOrderNumber'];
  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 === 200) {
  50. $official_sn = strtolower($params['brandOrderNumber']) == 'null' ? '' : $params['brandOrderNumber'];
  51. $data['official_sn'] = $official_sn;
  52. Model('refill_order')->edit($order_id, $data);
  53. return [$order_id, true, false, true, $official_sn];
  54. }
  55. elseif ($status === 300) {
  56. return [$order_id, false, true, true, ''];
  57. }
  58. else {
  59. return [$order_id, false, false, false, ''];
  60. }
  61. }
  62. }