RefillPhone.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. namespace refill\kefei_fast;
  3. require_once(BASE_HELPER_RAPI_PATH . '/kefei_fast/config.php');
  4. use app\api\venderapi\card_checker\mtopcard;
  5. use refill;
  6. use Log;
  7. class RefillPhone extends refill\IRefillPhone
  8. {
  9. public function __construct($cfgs)
  10. {
  11. parent::__construct($cfgs);
  12. }
  13. //[$state, $errmsg, $neterr]
  14. public function add($card_no, $card_type, $amount, $params, &$net_errno = 0): array
  15. {
  16. $typer = function ($card_type)
  17. {
  18. $types = [
  19. 4 => '移动',
  20. 5 => '联通',
  21. 6 => '电信'
  22. ];
  23. if(array_key_exists($card_type,$types)) {
  24. return $types[$card_type];
  25. } else {
  26. return false;
  27. }
  28. };
  29. $ispName = $typer($card_type);
  30. if(empty($ispName)) {
  31. return [false, '运营商错误', false];
  32. }
  33. $input = [
  34. "action" => "CZ",
  35. "orderId" => $params['order_sn'],
  36. "chargeAcct" => "$card_no",
  37. "chargeCash" => "$amount",
  38. "chargeType" => "0",
  39. 'ispName' => urlencode($ispName),
  40. "retUrl" => urlencode(config::NOTIFY_URL)
  41. ];
  42. $body = config::gen_body($input);
  43. if(empty($body)) {
  44. return [false, '提单参数不符合', false];
  45. }
  46. $resp = http_post_data(config::ORDER_URL, $body, config::ExtHeaders, $net_errno);
  47. if (empty($resp)) {
  48. return [false, '系统错误', true];
  49. }
  50. else
  51. {
  52. $resp = mb_convert_encoding($resp, "utf8", "gbk");
  53. Log::record($resp, Log::DEBUG);
  54. $resp = json_decode($resp, true);
  55. if (empty($resp)) {
  56. return [false, '系统错误', true];
  57. }
  58. $code = $resp['errorCode'];
  59. if ($code === 1) {
  60. return [true, $resp['chargeId'], false];
  61. } else {
  62. return [false, $resp['errorDesc'], false];
  63. }
  64. }
  65. }
  66. public function query($refill_info): array
  67. {
  68. $input = [
  69. "action" => "CX",
  70. "orderId" => $refill_info['order_sn'],
  71. ];
  72. $body = config::gen_body($input);
  73. $resp = http_post_data(config::ORDER_URL, $body, config::ExtHeaders, $net_errno);
  74. if (empty($resp)) {
  75. return [false, '系统错误', ''];
  76. }
  77. else
  78. {
  79. $resp = mb_convert_encoding($resp, "utf8", "gbk");
  80. Log::record($resp, Log::DEBUG);
  81. $resp = json_decode($resp, true);
  82. if (empty($resp)) {
  83. return [false, '系统错误', ''];
  84. }
  85. $errorCode = $resp['errorCode'];
  86. if ($errorCode === 1)
  87. {
  88. //0 等待处理 -
  89. //1 暂停处理 -
  90. //2 正在处理 -
  91. //6 正在缴费 -
  92. //11 处理成功 充值成功
  93. //16 缴费成功 充值成功
  94. //20 取消处理 充值失败
  95. //21 处理失败 充值失败
  96. //26 缴费失败 充值失败
  97. $status = intval($resp['orderStatuInt']);
  98. $official_sn = '';
  99. if (in_array($status, [11, 16])) {
  100. Model('refill_order')->edit($refill_info['order_id'], ['ch_trade_no' => $resp['chargeId'], 'official_sn' => $official_sn]);
  101. $order_state = ORDER_STATE_SUCCESS;
  102. } elseif (in_array($status, [20, 21, 26])) {
  103. Model('refill_order')->edit($refill_info['order_id'], ['ch_trade_no' => $resp['chargeId']]);
  104. $order_state = ORDER_STATE_CANCEL;
  105. } else {
  106. $order_state = ORDER_STATE_SEND;
  107. }
  108. return [true, $order_state, $official_sn];
  109. }
  110. elseif ($errorCode === -201 and (time() - $refill_info['commit_time']) >= 600) {
  111. return [true, ORDER_STATE_NOEXIST, ''];
  112. }
  113. else {
  114. return [false, $resp['errorDesc']];
  115. }
  116. }
  117. }
  118. public function balance(): array
  119. {
  120. $body = config::gen_body(["action" => "YE"]);
  121. $resp = http_post_data(config::ORDER_URL, $body, config::ExtHeaders, $net_errno);
  122. if (empty($resp)) {
  123. return [false, '系统错误'];
  124. }
  125. else
  126. {
  127. $resp = mb_convert_encoding($resp, "utf8", "gbk");
  128. Log::record($resp, Log::DEBUG);
  129. $resp = json_decode($resp, true);
  130. if (empty($resp)) {
  131. return [false, '系统错误'];
  132. } elseif ($resp['errorCode'] === 1) {
  133. return [true, ncPriceFormat($resp['agentBalance'])];
  134. } else {
  135. return [false, $resp['errorDesc']];
  136. }
  137. }
  138. }
  139. }