RefillCallBack.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace refill\zhenghe;
  3. require_once(BASE_HELPER_RAPI_PATH . '/zhenghe/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)
  17. {
  18. $mchid = config::MCHID;
  19. $key = config::KEY;
  20. $content = "mchid={$mchid}&orderid={$params['orderid']}&oid={$params['oid']}&number={$params['number']}&status={$params['status']}&key={$key}";
  21. return md5($content);
  22. }
  23. public function notify($params)
  24. {
  25. $order_sn = $params['orderid'];
  26. $order_info = Model('vr_order')->getOrderInfoForNotify(['order_sn' => $order_sn]);
  27. if (empty($order_info)) {
  28. return [false, false, false, false, ''];
  29. }
  30. $order_id = $order_info['order_id'];
  31. $status = intval($params['status']);
  32. if ($status === 2) {
  33. $official_sn = strtolower($params['voucher']) == 'null' ? '' : $params['voucher'];
  34. $data['official_sn'] = $official_sn;
  35. Model('refill_order')->edit($order_id, $data);
  36. return [$order_id, true, false, true, $official_sn];
  37. } elseif ($status === 3) {
  38. return [$order_id, false, true, true, ''];
  39. } else {
  40. return [$order_id, false, false, false, ''];
  41. }
  42. }
  43. }