RefillPhone.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace refill\lifang_normal;
  3. require_once(BASE_HELPER_RAPI_PATH . '/lifang_normal/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. private function add_params(int $phone, int $amount, string $order_sn, int $card_type): array
  13. {
  14. $input = [
  15. 'amount' => $amount,
  16. 'outOrderId' => $order_sn,
  17. 'phoneNumber' => $phone,
  18. 'requestDate' => config::time_stamp(),
  19. 'callBackUrl' => config::NOTIFY_URL
  20. ];
  21. $params = config::gen_params($input,config::add_keys);
  22. return $params;
  23. }
  24. //[$state, $errmsg, $neterr]
  25. public function add($card_no, $card_type, $amount, $params, &$net_errno = 0): array
  26. {
  27. $params = $this->add_params($card_no, $amount, $params['order_sn'], $card_type);
  28. if(empty($params)) {
  29. return [false, '提单参数不符合', false];
  30. }
  31. $resp = http_request(config::ORDER_URL, $params, 'POST', false, [], $net_errno);
  32. if (empty($resp)) {
  33. return [false, '系统错误', true];
  34. }
  35. else
  36. {
  37. /// 订单状态,0 充值中 1 充值成功 9 充值失败 6 存疑(人工核实)
  38. Log::record($resp, Log::DEBUG);
  39. $resp = json_decode($resp, true);
  40. if (empty($resp)) {
  41. return [false, '系统错误', true];
  42. } elseif ($resp['code'] === 200) {
  43. return [true, $resp['orderId'], false];
  44. } else {
  45. return [false, $resp['msg'], false];
  46. }
  47. }
  48. }
  49. public function query($refill_info): array
  50. {
  51. $input = [
  52. 'outOrderId' => $refill_info['order_sn'],
  53. 'requestDate' => config::time_stamp()
  54. ];
  55. $params = config::gen_params($input,config::query_keys);
  56. $resp = http_request(config::QUERY_URL, $params , 'POST');
  57. if (empty($resp)) {
  58. return [false, '系统错误', ''];
  59. }
  60. else
  61. {
  62. Log::record($resp, Log::DEBUG);
  63. $resp = json_decode($resp, true);
  64. if (empty($resp)) {
  65. return [false, '系统错误', ''];
  66. }
  67. $code = intval($resp['code']);
  68. if ($code === 200)
  69. {
  70. $val = $resp['data'];
  71. $status = intval($val['status']);
  72. $official_sn = '';
  73. //订单状态,0 充值中 1 充值成功 9 充值失败 6 存疑(人工核实)
  74. if ($status == 1) {
  75. Model('refill_order')->edit($refill_info['order_id'], ['ch_trade_no' => $val['orderId'],'official_sn' => $official_sn]);
  76. $order_state = ORDER_STATE_SUCCESS;
  77. }
  78. elseif ($status == 9) {
  79. Model('refill_order')->edit($refill_info['order_id'], ['ch_trade_no' => $val['orderId']]);
  80. $order_state = ORDER_STATE_CANCEL;
  81. }
  82. else {
  83. $order_state = ORDER_STATE_SEND;
  84. }
  85. return [true, $order_state, $official_sn];
  86. }
  87. elseif($code === 80001 and (time() - $refill_info['commit_time']) >= 300) {
  88. return [true, ORDER_STATE_NOEXIST, ''];
  89. }
  90. else {
  91. return [false, $resp['msg']];
  92. }
  93. }
  94. }
  95. public function balance(): array
  96. {
  97. $input = [
  98. 'requestDate' => config::time_stamp()
  99. ];
  100. $params = config::gen_params($input,config::balance_keys);
  101. $resp = http_request(config::BALANCE_URL, $params , 'POST');
  102. if (empty($resp)) {
  103. return [false, '系统错误'];
  104. }
  105. else
  106. {
  107. Log::record($resp, Log::DEBUG);
  108. $resp = json_decode($resp, true);
  109. if (empty($resp)) {
  110. return [false, '系统错误'];
  111. } elseif ($resp['code'] === 200) {
  112. return [true, ncPriceFormat($resp['data']['leftBalance'])];
  113. } else {
  114. return [false, $resp['msg']];
  115. }
  116. }
  117. }
  118. }