RefillCallBack.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace refill\leyou;
  3. require_once(BASE_HELPER_RAPI_PATH . '/leyou/config.php');
  4. use refill;
  5. class RefillCallBack implements refill\IRefillCallBack
  6. {
  7. public function verify($params): bool
  8. {
  9. $sign = $this->sign($params);
  10. if ($params['sign'] == $sign) {
  11. return true;
  12. } else {
  13. return false;
  14. }
  15. }
  16. private function sign($params)
  17. {
  18. $key = config::APP_KEY;
  19. $content = "{$params['username']}{$params['orderNumber']}{$params['number']}{$params['money']}[{$params['status']}]{$params['endTime']}$key";
  20. return md5($content);
  21. }
  22. public function notify($params)
  23. {
  24. $status = intval($params['status']);
  25. $order_sn = $params['orderNumber'];
  26. $order_info = Model('vr_order')->getOrderInfoForNotify(['order_sn' => $order_sn]);
  27. if (empty($order_info)) {
  28. return [false, false, false, false, ''];
  29. }
  30. $order_id = $order_info['order_id'];
  31. if ($status === 5) {
  32. $official_sn = config::extract_official_sn($params['voucher']);
  33. Model('refill_order')->edit($order_id, ['official_sn' => $official_sn]);
  34. return [$order_id, true, false, true, ''];
  35. }
  36. elseif ($status === 6) {
  37. return [$order_id, false, true, true, ''];
  38. }
  39. else {
  40. return [$order_id, false, false, false, ''];
  41. }
  42. }
  43. }