RefillCallBack.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace refill\haohao;
  3. require_once(BASE_HELPER_RAPI_PATH . '/haohao/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. ksort($params);
  21. $signature_string = '';
  22. foreach ($params as $k => $v) {
  23. if (false === $this->check_empty($v)) {
  24. $signature_string .= $k . '=' . $v . '&';
  25. }
  26. }
  27. $signature_string .= "key=" . config::KEY;
  28. return strtoupper(md5($signature_string));
  29. }
  30. private function check_empty($value)
  31. {
  32. if (!isset($value))
  33. return true;
  34. if ($value === null)
  35. return true;
  36. if (trim($value) === "")
  37. return true;
  38. return false;
  39. }
  40. public function notify($params)
  41. {
  42. $status = intval($params['directStatus']);
  43. $order_sn = $params['mchOrderNo'];
  44. $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
  45. if (empty($order_info)) {
  46. return [false, false, false,false];
  47. }
  48. $order_id = $order_info['order_id'];
  49. if ($status === 5) {
  50. $data['ch_trade_no'] = strtolower($params['thirdOrderNo']) == 'null' ? '' : $params['thirdOrderNo'];
  51. Model('refill_order')->edit($order_id, $data);
  52. return [$order_id, true, false,true];
  53. }
  54. elseif (in_array($status, [2,3])) {
  55. return [$order_id, false, false,true];
  56. }
  57. else {
  58. return [$order_id, false, false,false];
  59. }
  60. }
  61. }