RefillCallBack.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace refill\masheng;
  3. require_once(BASE_HELPER_RAPI_PATH . '/masheng/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['sign'] == $sign) {
  11. return true;
  12. } else {
  13. return false;
  14. }
  15. }
  16. private function sign($params): string
  17. {
  18. $userid = config::USER_ID;
  19. $key = config::KEY;
  20. $content = "agent_id=$userid&amount={$params['amount']}&batch_no={$params['batch_no']}&key=$key&order_id={$params['order_id']}&pay_at={$params['pay_at']}&status={$params['status']}";
  21. return md5($content);
  22. }
  23. public function notify($params): array
  24. {
  25. $status = intval($params['status']);
  26. $order_sn = $params['batch_no'];
  27. $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
  28. if (empty($order_info)) {
  29. return [false, false, false, false, ''];
  30. }
  31. $order_id = $order_info['order_id'];
  32. if ($status === 2) {
  33. $official_sn = $params['refid '];
  34. $data['official_sn'] = $official_sn;
  35. $data['ch_trade_no'] = $params['order_id'];
  36. Model('refill_order')->edit($order_id, $data);
  37. return [$order_id, true, false, true, $official_sn];
  38. } elseif ($status === 4) {
  39. Model('refill_order')->edit($order_id, ['ch_trade_no' => $params['order_id']]);
  40. return [$order_id, false, true, true, ''];
  41. } else {
  42. return [$order_id, false, false, false, ''];
  43. }
  44. }
  45. }