RefillCallBack.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace refill\yinghuochong;
  3. require_once(BASE_HELPER_RAPI_PATH . '/yinghuochong/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. if(empty($input['voucher'])) unset($input['voucher']);
  12. $sign = $this->sign($input);
  13. if ($params['sign'] == $sign) {
  14. return true;
  15. } else {
  16. return false;
  17. }
  18. }
  19. private function sign($params)
  20. {
  21. ksort($params);
  22. $content = "";
  23. foreach ($params as $k => $v) {
  24. $content .= "{$k}={$v}&";
  25. }
  26. $content = rtrim($content, '&');
  27. $content .= config::AppSecret;
  28. return strtoupper(md5($content));
  29. }
  30. public function notify($params)
  31. {
  32. $status = intval($params['status']);
  33. $order_sn = $params['customerOrderId'];
  34. $order_info = Model('vr_order')->getOrderInfoForNotify(['order_sn' => $order_sn]);
  35. if (empty($order_info)) {
  36. return [false, false, false,false];
  37. }
  38. $order_id = $order_info['order_id'];
  39. if ($status === 1) {
  40. Model('refill_order')->edit($order_id, ['official_sn' => $params['voucher']]);
  41. return [$order_id, true, false, true];
  42. } elseif ($status === 2) {
  43. return [$order_id, false, true, true];
  44. } else {
  45. return [$order_id, false, false, false];
  46. }
  47. }
  48. }