RefillPhone.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace refill\yifutong;
  3. require_once(BASE_HELPER_RAPI_PATH . '/yifutong/config.php');
  4. use refill;
  5. use Log;
  6. class RefillPhone extends refill\IRefillPhone
  7. {
  8. public function __construct($cfgs)
  9. {
  10. parent::__construct($cfgs);
  11. }
  12. public function add($card_no, $card_type, $amount, $params, &$net_errno = 0): array
  13. {
  14. $mod_refill = Model('refill_order');
  15. $order_sn = $params['order_sn'];
  16. $refill_info = $mod_refill->getOrderInfo(['order_sn' => $order_sn]);
  17. $mch_order = $refill_info['mch_order'];
  18. $cbparams = refill\util::read_yifutong_order($mch_order);
  19. $this->send_normal($order_sn, $cbparams);
  20. return [true, '', false];
  21. }
  22. public static function send_normal($order_sn,$cbparams)
  23. {
  24. go(function () use ($order_sn,$cbparams)
  25. {
  26. sleep(1);
  27. while (true)
  28. {
  29. $net_errno = 0;
  30. $resp = http_request($cbparams['notify_url'],['status' => $cbparams['status'],'order_sn' => $order_sn],'GET', false, [], $net_errno);
  31. if($resp == 'SUCCESS') {
  32. break;
  33. }
  34. }
  35. Log::record("resp = $resp",Log::DEBUG);
  36. });
  37. }
  38. public function query($refill_info): array
  39. {
  40. $mod_order = Model('vr_order');
  41. $order_sn = $refill_info['order_sn'];
  42. $order_info = $mod_order->getOrderInfo(['order_sn' => $order_sn]);
  43. if (empty($order_info)) {
  44. $order_state = ORDER_STATE_NOEXIST;
  45. } else {
  46. $order_state = intval($order_info['order_state']);
  47. }
  48. return [true, $order_state, ''];
  49. }
  50. }