RefillCallBack.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. } elseif ($status === 2) {
  44. return [$order_id, false, false, true];
  45. } else {
  46. return [$order_id, false, false, false];
  47. }
  48. }
  49. protected function check_empty($value)
  50. {
  51. if (!isset($value))
  52. return true;
  53. if ($value === null)
  54. return true;
  55. if (trim($value) === "")
  56. return true;
  57. return false;
  58. }
  59. }