RefillCallBack.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace refill\meihan;
  3. require_once(BASE_HELPER_RAPI_PATH . '/meihan/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. $sign = $this->sign($input);
  12. if ($params['sign'] == $sign) {
  13. return true;
  14. } else {
  15. return false;
  16. }
  17. }
  18. private function sign($params)
  19. {
  20. $params['appSecret'] = config::APP_SECRET;
  21. ksort($params);
  22. $content = '';
  23. foreach ($params as $key => $value) {
  24. if($this->check_empty($value) === false) {
  25. $content .= "{$key}={$value}&";
  26. }
  27. }
  28. $content = rtrim($content, '&');
  29. return md5($content);
  30. }
  31. private function check_empty($value)
  32. {
  33. if (!isset($value))
  34. return true;
  35. if ($value === null)
  36. return true;
  37. if (trim($value) === "")
  38. return true;
  39. return false;
  40. }
  41. public function notify($params)
  42. {
  43. $status = intval($params['orderStatus']);
  44. $order_sn = $params['outOrderId'];
  45. $order_info = Model('vr_order')->getOrderInfoForNotify(['order_sn' => $order_sn]);
  46. if (empty($order_info)) {
  47. return [false, false, false,false];
  48. }
  49. $order_id = $order_info['order_id'];
  50. if ($status === 2) {
  51. $data['official_sn'] = strtolower($params['ext1']) == 'null' ? '' : $params['ext1'];
  52. Model('refill_order')->edit($order_id, $data);
  53. return [$order_id, true, false, true];
  54. } elseif ($status === 3) {
  55. return [$order_id, false, true, true];
  56. } else {
  57. return [$order_id, false, false, false];
  58. }
  59. }
  60. }