123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- namespace refill\pengxinda;
- require_once(BASE_HELPER_RAPI_PATH . '/pengxinda/config.php');
- use refill;
- use Log;
- class RefillPhone extends refill\IRefillPhone
- {
- public function __construct($cfgs)
- {
- parent::__construct($cfgs);
- }
- private function req_params(int $phone, int $card_type, int $amount, string $order_sn)
- {
- $product_id = config::Product[$card_type][$amount];
- if(empty($product_id)) return false;
- $data['api_userid'] = config::API_USER_ID;
- $data['product_id'] = $product_id;
- $data['mobile'] = $phone;
- $data['order_no'] = $order_sn;
- $json_str = json_encode($data);
- $params['api_userid'] = config::API_USER_ID;
- $params['api_data'] = $this->encrypt($json_str);
- return $params;
- }
- public function add($card_no, $card_type, $amount, $input, &$net_errno = 0)
- {
- $params = $this->req_params($card_no, $card_type, $amount, $input['order_sn']);
- if(empty($params)) {
- return [false, '商品编号错误', false];
- }
- $resp = http_request(config::ORDER_URL, $params, 'POST', false, [], $net_errno);
- if (empty($resp)) {
- return [false, '系统错误', true];
- }
- else
- {
- Log::record($resp, Log::DEBUG);
- $resp = json_decode($resp, true);
- $ret_code = $resp['retcode'];
- if (empty($resp)) {
- return [false, '系统错误', true];
- } elseif ($ret_code === 200) {
- return [true, '', false];
- } else {
- return [false, $resp['retmsg'], false];
- }
- }
- }
- public function query($refill_info)
- {
- $data['api_userid'] = config::API_USER_ID;
- $data['mobile'] = $refill_info['card_no'];
- $data['order_no'] = $refill_info['order_sn'];
- $json_str = json_encode($data);
- $params['api_userid'] = config::API_USER_ID;
- $params['api_data'] = $this->encrypt($json_str);
- $resp = http_request(config::QUERY_URL, $params, 'POST');
- if (empty($resp)) {
- return [false, '系统错误'];
- }
- else
- {
- Log::record($resp, Log::DEBUG);
- $resp = json_decode($resp, true);
- if (empty($resp)) {
- return [false, '系统错误'];
- }
- else
- {
- $ret_code = $resp['retcode'];
- if ($ret_code === 1) {
- $updata['official_sn'] = $resp['errcode'];
- Model('refill_order')->edit($refill_info['order_id'], $updata);
- $order_state = ORDER_STATE_SUCCESS;
- } elseif ($ret_code === 0) {
- $order_state = ORDER_STATE_CANCEL;
- } elseif ($ret_code === 2) {
- $order_state = ORDER_STATE_SEND;
- } else {
- return [false, $ret_code];
- }
- return [true, $order_state];
- }
- }
- }
- public function balance()
- {
- $data['api_userid'] = config::API_USER_ID;
- $json_str = json_encode($data);
- $params['api_userid'] = config::API_USER_ID;
- $params['api_data'] = $this->encrypt($json_str);
- $resp = http_request(config::BALANCE_URL, $params, 'POST');
- if (empty($resp)) {
- return [false, '系统错误'];
- }
- else
- {
- Log::record($resp, Log::DEBUG);
- $resp = json_decode($resp, true);
- if (empty($resp)) {
- return [false, '系统错误'];
- } elseif ($resp['retcode'] === 200) {
- return [true, $resp['retmsg']];
- } else {
- return [false, $resp['retmsg']];
- }
- }
- }
- //加密
- private function encrypt($encrypt)
- {
- $data = openssl_encrypt($encrypt, 'AES-128-ECB', hex2bin(config::KEY), OPENSSL_RAW_DATA, '');
- return bin2hex($data);
- }
- }
|