RefillCallBack.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace refill\xingzy;
  3. require_once(BASE_HELPER_RAPI_PATH . '/xingzy/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. unset($input['data']);
  12. $sign = $this->sign($input);
  13. if ($params['sign'] == $sign) {
  14. return true;
  15. } else {
  16. return false;
  17. }
  18. }
  19. private function sign($params)
  20. {
  21. ksort($params);
  22. $body = "";
  23. foreach ($params as $k => $v) {
  24. $body .= "{$k}{$v}";
  25. }
  26. return base64_encode(hash_hmac("sha1", $body, config::ACCESS_SECRET, true));
  27. }
  28. //[$order_id, $success, $can_try, $need_handle]
  29. public function notify($params)
  30. {
  31. $status = intval($params['code']);
  32. $order_sn = $params['out_trade_no'];
  33. $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
  34. if (empty($order_info)) {
  35. return [false, false, false,false];
  36. }
  37. $order_id = $order_info['order_id'];
  38. if ($status === 2) {
  39. $data['official_sn'] = strtolower($params['data']['official_id']) == 'null' ? '' : $params['data']['official_id'];
  40. Model('refill_order')->edit($order_id, $data);
  41. return [$order_id, true, false,true];
  42. }
  43. elseif ($status === 3) {
  44. return [$order_id, false, true,true];
  45. }
  46. else {
  47. return [$order_id, false, false,false];
  48. }
  49. }
  50. }