RefillCallBack.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace refill\xinsj;
  3. require_once(BASE_HELPER_RAPI_PATH . '/xinsj/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['signature']);
  11. $sign = $this->sign($input);
  12. if ($params['appid'] == config::APPID && $params['signature'] == $sign) {
  13. return true;
  14. } else {
  15. return false;
  16. }
  17. }
  18. protected function check_empty($value)
  19. {
  20. if (!isset($value))
  21. return true;
  22. if ($value === null)
  23. return true;
  24. if (trim($value) === "")
  25. return true;
  26. return false;
  27. }
  28. private function sign($input)
  29. {
  30. $key = config::APPKEY;
  31. $body = config::body($input);
  32. $body .= "&token={$key}";
  33. return strtolower(md5($body));
  34. }
  35. //[$order_id, $success, $can_try, $need_handle]
  36. public function notify($params)
  37. {
  38. $status = intval($params['status']);
  39. $order_sn = $params['morder'];
  40. $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
  41. if (empty($order_info)) {
  42. return [false, false, false,false];
  43. }
  44. $order_id = $order_info['order_id'];
  45. if ($status === 2) {
  46. $data['official_sn'] = strtolower($params['vnum']) == 'null' ? '' : $params['vnum'];
  47. Model('refill_order')->edit($order_id, $data);
  48. return [$order_id, true, false,true];
  49. }
  50. elseif ($status === 3) {
  51. return [$order_id, false, true,true];
  52. }
  53. else {
  54. return [$order_id, false, false,false];
  55. }
  56. }
  57. }