RefillPhone.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace refill\lifang_normal;
  3. require_once(BASE_HELPER_RAPI_PATH . '/lifang_normal/config.php');
  4. use mtopcard;
  5. use refill;
  6. use Log;
  7. use refill\lifang_normal\config;
  8. class RefillPhone extends refill\IRefillPhone
  9. {
  10. public function __construct($cfgs)
  11. {
  12. parent::__construct($cfgs);
  13. }
  14. private function add_params(int $phone, int $amount, string $order_sn, int $card_type): array
  15. {
  16. $input = [
  17. 'amount' => $amount,
  18. 'outOrderId' => $order_sn,
  19. 'phoneNumber' => $phone,
  20. 'requestDate' => config::time_stamp(),
  21. ];
  22. $input = config::gen_params($input,config::add_keys);
  23. $input['callBackUrl'] = config::NOTIFY_URL;
  24. return $input;
  25. }
  26. //[$state, $errmsg, $neterr]
  27. public function add($card_no, $card_type, $amount, $params, &$net_errno = 0): array
  28. {
  29. $params = $this->add_params($card_no, $amount, $params['order_sn'], $card_type);
  30. if(empty($params)) {
  31. return [false, '提单参数不符合', false];
  32. }
  33. $resp = http_request(config::ORDER_URL, $params, 'POST', false, [], $net_errno);
  34. if (empty($resp)) {
  35. return [false, '系统错误', true];
  36. }
  37. else
  38. {
  39. /// 订单状态,0 充值中 1 充值成功 9 充值失败 6 存疑(人工核实)
  40. Log::record($resp, Log::DEBUG);
  41. $resp = json_decode($resp, true);
  42. if (empty($resp)) {
  43. return [false, '系统错误', true];
  44. } elseif ($resp['code'] === 200) {
  45. return [true, $resp['orderId'], false];
  46. } else {
  47. return [false, $resp['msg'], false];
  48. }
  49. }
  50. }
  51. public function query($refill_info): array
  52. {
  53. $input = [
  54. 'outOrderId' => $refill_info['order_sn'],
  55. 'requestDate' => config::time_stamp()
  56. ];
  57. $params = config::gen_params($input,config::query_keys);
  58. $resp = http_request(config::QUERY_URL, $params , 'POST');
  59. if (empty($resp)) {
  60. return [false, '系统错误', ''];
  61. }
  62. else
  63. {
  64. Log::record($resp, Log::DEBUG);
  65. $resp = json_decode($resp, true);
  66. if (empty($resp)) {
  67. return [false, '系统错误', ''];
  68. }
  69. $code = intval($resp['code']);
  70. if ($code === 200)
  71. {
  72. $val = $resp['data'];
  73. $status = intval($val['status']);
  74. $official_sn = '';
  75. //订单状态,0 充值中 1 充值成功 9 充值失败 6 存疑(人工核实)
  76. if ($status == 1) {
  77. Model('refill_order')->edit($refill_info['order_id'], ['ch_trade_no' => $val['orderId'],'official_sn' => $official_sn]);
  78. $order_state = ORDER_STATE_SUCCESS;
  79. }
  80. elseif ($status == 9) {
  81. Model('refill_order')->edit($refill_info['order_id'], ['ch_trade_no' => $val['orderId']]);
  82. $order_state = ORDER_STATE_CANCEL;
  83. }
  84. else {
  85. $order_state = ORDER_STATE_SEND;
  86. }
  87. return [true, $order_state, $official_sn];
  88. }
  89. else
  90. {
  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. }