RefillPhone.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace refill\pengxinda;
  3. require_once(BASE_HELPER_RAPI_PATH . '/pengxinda/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 $card_type, int $amount, string $order_sn)
  13. {
  14. $product_id = config::Product[$card_type][$amount];
  15. if(empty($product_id)) return false;
  16. $data['api_userid'] = config::API_USER_ID;
  17. $data['product_id'] = $product_id;
  18. $data['mobile'] = $phone;
  19. $data['order_no'] = $order_sn;
  20. $json_str = json_encode($data);
  21. $params['api_userid'] = config::API_USER_ID;
  22. $params['api_data'] = $this->encrypt($json_str);
  23. return $params;
  24. }
  25. public function add($card_no, $card_type, $amount, $input, &$net_errno = 0)
  26. {
  27. $params = $this->req_params($card_no, $card_type, $amount, $input['order_sn']);
  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. Log::record($resp, Log::DEBUG);
  38. $resp = json_decode($resp, true);
  39. $ret_code = $resp['retcode'];
  40. if (empty($resp)) {
  41. return [false, '系统错误', true];
  42. } elseif ($ret_code === 200) {
  43. return [true, '', false];
  44. } else {
  45. return [false, $resp['retmsg'], false];
  46. }
  47. }
  48. }
  49. public function query($refill_info)
  50. {
  51. $data['api_userid'] = config::API_USER_ID;
  52. $data['mobile'] = $refill_info['card_no'];
  53. $data['order_no'] = $refill_info['order_sn'];
  54. $json_str = json_encode($data);
  55. $params['api_userid'] = config::API_USER_ID;
  56. $params['api_data'] = $this->encrypt($json_str);
  57. $resp = http_request(config::QUERY_URL, $params, 'POST');
  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. else
  69. {
  70. $ret_code = $resp['retcode'];
  71. if ($ret_code === 1) {
  72. $updata['official_sn'] = $resp['errcode'];
  73. Model('refill_order')->edit($refill_info['order_id'], $updata);
  74. $order_state = ORDER_STATE_SUCCESS;
  75. } elseif ($ret_code === 0) {
  76. $order_state = ORDER_STATE_CANCEL;
  77. } elseif ($ret_code === 2) {
  78. $order_state = ORDER_STATE_SEND;
  79. } else {
  80. return [false, $ret_code];
  81. }
  82. return [true, $order_state];
  83. }
  84. }
  85. }
  86. public function balance()
  87. {
  88. $data['api_userid'] = config::API_USER_ID;
  89. $json_str = json_encode($data);
  90. $params['api_userid'] = config::API_USER_ID;
  91. $params['api_data'] = $this->encrypt($json_str);
  92. $resp = http_request(config::BALANCE_URL, $params, 'POST');
  93. if (empty($resp)) {
  94. return [false, '系统错误'];
  95. }
  96. else
  97. {
  98. Log::record($resp, Log::DEBUG);
  99. $resp = json_decode($resp, true);
  100. if (empty($resp)) {
  101. return [false, '系统错误'];
  102. } elseif ($resp['retcode'] === 200) {
  103. return [true, $resp['retmsg']];
  104. } else {
  105. return [false, $resp['retmsg']];
  106. }
  107. }
  108. }
  109. //加密
  110. private function encrypt($encrypt)
  111. {
  112. $data = openssl_encrypt($encrypt, 'AES-128-ECB', hex2bin(config::KEY), OPENSSL_RAW_DATA, '');
  113. return bin2hex($data);
  114. }
  115. }