RefillCallBack.php 1.7 KB

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