RefillCallBack.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace refill\langke;
  3. use refill;
  4. class RefillCallBack implements refill\IRefillCallBack
  5. {
  6. public function verify($params): bool
  7. {
  8. $input = $params;
  9. unset($input['sign']);
  10. $sign = $this->sign($input);
  11. if ($params['sign'] == $sign) {
  12. return true;
  13. } else {
  14. return false;
  15. }
  16. }
  17. private function check_empty($value)
  18. {
  19. if (!isset($value))
  20. return true;
  21. if ($value === null)
  22. return true;
  23. if (trim($value) === "")
  24. return true;
  25. return false;
  26. }
  27. private function sign($params)
  28. {
  29. ksort($params);
  30. $body = "";
  31. $i = 0;
  32. foreach ($params as $k => $v)
  33. {
  34. if (false === $this->check_empty($v) && "@" != substr($v, 0, 1))
  35. {
  36. if ($i == 0) {
  37. $body .= "{$k}" . "=" . urldecode($v);
  38. } else {
  39. $body .= "&" . "{$k}" . "=" . urldecode($v);
  40. }
  41. $i++;
  42. }
  43. }
  44. $body .= "&key=" . config::KEY;
  45. return md5($body);
  46. }
  47. public function notify($params)
  48. {
  49. $status = intval($params['status']);
  50. $order_sn = $params['onlystr'];
  51. $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
  52. if (empty($order_info)) {
  53. return [false, false, false,false];
  54. }
  55. $order_id = $order_info['order_id'];
  56. if ($status === 2) {
  57. $data['official_sn'] = strtolower($params['channelno']) == 'null' ? '' : $params['channelno'];
  58. Model('refill_order')->edit($order_id, $data);
  59. return [$order_id, true, false,true];
  60. } elseif ($status === 3) {
  61. return [$order_id, false, true, true];
  62. } else {
  63. return [$order_id, false, false, false];
  64. }
  65. }
  66. }