RefillCallBack.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 ($sms)
  26. {
  27. $officialSn = '';
  28. if (preg_match_all("/(\d+)/", $sms, $matches))
  29. {
  30. foreach ($matches[1] as $item)
  31. {
  32. if (strlen($officialSn) < strlen($item)) {
  33. $officialSn = $item;
  34. }
  35. }
  36. }
  37. return $officialSn;
  38. };
  39. $status = intval($params['status']);
  40. $order_sn = $params['user_order_id'];
  41. $order_info = Model('vr_order')->getOrderInfoForNotify(['order_sn' => $order_sn]);
  42. if (empty($order_info)) {
  43. return [false, false, false, false, ''];
  44. }
  45. $order_id = $order_info['order_id'];
  46. if ($status === 200) {
  47. $official_sn = $extractOfficialSn($params['official_order_id']);
  48. $data['official_sn'] = $official_sn;
  49. Model('refill_order')->edit($order_id, $data);
  50. return [$order_id, true, false, true, $official_sn];
  51. }
  52. elseif ($status === 202) {
  53. return [$order_id, false, true, true, ''];
  54. }
  55. else {
  56. return [$order_id, false, false, false, ''];
  57. }
  58. }
  59. }