RefillCallBack.php 1.8 KB

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