RefillCallBack.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace refill\jiuyi;
  3. require_once(BASE_HELPER_RAPI_PATH . '/jiuyi/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')->getOrderInfoForNotify(['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. $official_sn = strtolower($params['data']['official_id']) == 'null' ? '' : $params['data']['official_id'];
  40. $data['official_sn'] = $official_sn;
  41. Model('refill_order')->edit($order_id, $data);
  42. return [$order_id, true, false, true, $official_sn];
  43. }
  44. elseif ($status === 3) {
  45. return [$order_id, false, true, true, ''];
  46. }
  47. else {
  48. return [$order_id, false, false, false, ''];
  49. }
  50. }
  51. }