RefillPhone.php 4.3 KB

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