RefillCallBack.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace refill\xinma;
  3. require_once(BASE_HELPER_RAPI_PATH . '/xinma/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. $user_name = config::USER_NAME;
  20. $content = "{$user_name}{$params['sys_order_id']}{$params['user_order_id']}{$key}";
  21. return md5($content);
  22. }
  23. public function notify($params)
  24. {
  25. $extractOfficialSn = function ($officialSnStr) {
  26. $officialSn = '';
  27. $matches = [];
  28. if (preg_match_all("/(\d+)/", $officialSnStr, $matches)) {
  29. foreach ($matches[1] as $item) {
  30. if (strlen($officialSn) < strlen($item)) {
  31. $officialSn = $item;
  32. }
  33. }
  34. }
  35. return $officialSn;
  36. };
  37. $status = intval($params['status']);
  38. $order_sn = $params['user_order_id'];
  39. $order_info = Model('vr_order')->getOrderInfoForNotify(['order_sn' => $order_sn]);
  40. if (empty($order_info)) {
  41. return [false, false, false, false, ''];
  42. }
  43. $order_id = $order_info['order_id'];
  44. if ($status === 200) {
  45. $official_sn = $extractOfficialSn($params['official_order_id']);
  46. $data['official_sn'] = $official_sn;
  47. Model('refill_order')->edit($order_id, $data);
  48. return [$order_id, true, false, true, $official_sn];
  49. }
  50. elseif ($status === 202) {
  51. return [$order_id, false, true, true, ''];
  52. }
  53. else {
  54. return [$order_id, false, false, false, ''];
  55. }
  56. }
  57. }