RefillCallBack.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace refill\yifa;
  3. require_once(BASE_HELPER_PATH . '/refill/yifa/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['sgn'] == $sign) {
  11. return true;
  12. } else {
  13. return false;
  14. }
  15. }
  16. private 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. ksort($params);
  29. $app_secret = config::APP_SECRET;
  30. $body = $app_secret;
  31. foreach ($params as $k => $v) {
  32. if (false === $this->check_empty($v) && "@" != substr($v, 0, 1)) {
  33. $body .= "{$k}{$v}";
  34. }
  35. }
  36. $body .= "&key=" . $app_secret;
  37. return strtoupper(md5($body));
  38. }
  39. public function notify($params)
  40. {
  41. $status = intval($params['status']);
  42. $order_sn = $params['coder_order_sn'];
  43. $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
  44. if (empty($order_info)) {
  45. return [false, false, false,false];
  46. }
  47. $order_id = $order_info['order_id'];
  48. $data['official_sn'] = $params['isp_order_sn'];
  49. $data['ch_trade_no'] = $params['order_sn'];
  50. Model('refill_order')->edit($order_id, $data);
  51. if ($status === 'success') {
  52. return [$order_id, true, false,true,true];
  53. } elseif ($status === 2) {
  54. return [$order_id, false, true,true,true];
  55. }
  56. }
  57. }