RefillPhone.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace refill\shantong;
  3. require_once(BASE_HELPER_RAPI_PATH . '/shantong/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 req_params(int $phone, int $amount, string $order_sn)
  13. {
  14. $params['mobile'] = $phone;
  15. $params['perValue'] = $amount;
  16. $params['orderId'] = $order_sn;
  17. $params['orderDate'] = date("Y-m-d H:i:s");
  18. $params['agentId'] = config::AGENT_ID;
  19. $params['transactionPin'] = config::transactionPin;
  20. $params['notifyUrl'] = config::NOTIFY_URL;
  21. return $params;
  22. }
  23. public function add($card_no, $card_type, $amount, $input, &$net_errno = 0)
  24. {
  25. $params = config::pub_params();
  26. $data = $this->req_params($card_no, $amount, $input['order_sn']);
  27. $params['reqData'] = json_encode($data);
  28. $params['sign'] = config::sign($params);
  29. $params = json_encode($params);
  30. $resp = http_post_data(config::ORDER_URL, $params , config::ExtHeaders, $net_errno);
  31. if (empty($resp)) {
  32. return [false, '系统错误', true];
  33. }
  34. else
  35. {
  36. Log::record($resp, Log::DEBUG);
  37. $resp = json_decode($resp, true);
  38. $code = $resp['code'];
  39. if (empty($resp)) {
  40. return [false, '系统错误', true];
  41. } elseif ($code === 1) {
  42. return [true, $resp['data']['businessOrderId'], false];
  43. } else {
  44. return [false, $resp['msg'], false];
  45. }
  46. }
  47. }
  48. public function query($refill_info)
  49. {
  50. $params = config::pub_params();
  51. $data['orderId'] = $refill_info['order_sn'];
  52. $data['agentId'] = config::AGENT_ID;
  53. $data['transactionPin'] = config::transactionPin;
  54. $params['reqData'] = json_encode($data);
  55. $params['sign'] = config::sign($params);
  56. $params = json_encode($params);
  57. $resp = http_post_data(config::QUERY_URL, $params , config::ExtHeaders);
  58. if (empty($resp)) {
  59. return [false, '系统错误'];
  60. }
  61. else
  62. {
  63. Log::record($resp, Log::DEBUG);
  64. $resp = json_decode($resp, true);
  65. if (empty($resp)) {
  66. return [false, '系统错误'];
  67. }
  68. elseif($resp['code'] === 1)
  69. {
  70. $status = $resp['data']['orderStatus'];
  71. if ($status === 3) {
  72. $updata['official_sn'] = $resp['data']['ispVoucherId'];
  73. Model('refill_order')->edit($refill_info['order_id'], $updata);
  74. $order_state = ORDER_STATE_SUCCESS;
  75. } elseif ($status === 99) {
  76. $order_state = ORDER_STATE_CANCEL;
  77. } elseif ($status === 1 || $status === 2) {
  78. $order_state = ORDER_STATE_SEND;
  79. } else {
  80. return [false, $status];
  81. }
  82. return [true, $order_state];
  83. }
  84. else
  85. {
  86. return [false, $resp['msg']];
  87. }
  88. }
  89. }
  90. public function balance()
  91. {
  92. $params = config::pub_params();
  93. $data['agentId'] = config::AGENT_ID;
  94. $data['transactionPin'] = config::transactionPin;
  95. $params['reqData'] = json_encode($data);
  96. $params['sign'] = config::sign($params);
  97. $params = json_encode($params);
  98. $resp = http_post_data(config::BALANCE_URL, $params , config::ExtHeaders);
  99. if (empty($resp)) {
  100. return [false, '系统错误'];
  101. }
  102. else
  103. {
  104. Log::record($resp, Log::DEBUG);
  105. $resp = json_decode($resp, true);
  106. if (empty($resp)) {
  107. return [false, '系统错误'];
  108. } elseif ($resp['code'] === 1) {
  109. return [true, $resp['data']['currentBalance']];
  110. } else {
  111. return [false, $resp['msg']];
  112. }
  113. }
  114. }
  115. }