|
@@ -0,0 +1,167 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace refill\feihan_hf;
|
|
|
+
|
|
|
+require_once(BASE_HELPER_RAPI_PATH . '/feihan_hf/config.php');
|
|
|
+
|
|
|
+use refill;
|
|
|
+use Log;
|
|
|
+
|
|
|
+class RefillPhone extends refill\IRefillPhone
|
|
|
+{
|
|
|
+ public function __construct($cfgs)
|
|
|
+ {
|
|
|
+ parent::__construct($cfgs);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function req_params(int $card_no, int $amount, int $card_type, string $order_sn)
|
|
|
+ {
|
|
|
+ $params['userid'] = config::USER_ID;
|
|
|
+ $params['userpws'] = md5(config::USER_PWS);
|
|
|
+ $params['cardid'] = config::goods_id;
|
|
|
+ $params['cardnum'] = $amount;
|
|
|
+ $params['sporder_id'] = $order_sn;
|
|
|
+ $params['sporder_time'] = date("YmdHis");
|
|
|
+ $params['game_userid'] = $card_no;
|
|
|
+ $params['ret_url'] = config::NOTIFY_URL;
|
|
|
+ $params['version'] = '6.0';
|
|
|
+ return $params;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
|
|
|
+ {
|
|
|
+ $order_sn = $params['order_sn'];
|
|
|
+ $params = $this->req_params($card_no, $amount, $card_type, $order_sn);
|
|
|
+
|
|
|
+ $sign = $this->sign($params);
|
|
|
+ $params['md5_str'] = $sign;
|
|
|
+
|
|
|
+ $resp = http_request(config::ORDER_URL, $params, 'POST', false, config::ExtHeaders, $net_errno);
|
|
|
+
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '网络错误', true];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Log::record($resp, Log::DEBUG);
|
|
|
+ $resp = $this->xmlToArray($resp);
|
|
|
+
|
|
|
+ $retCode = $resp['retcode'];
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '网络错误', true];
|
|
|
+ } elseif ($retCode === '1') {
|
|
|
+ return [true, $resp['orderid'], false];
|
|
|
+ } elseif (in_array($retCode, config::ERR_NOS, true)) {
|
|
|
+ return [false, $resp['err_msg'], false];
|
|
|
+ } elseif ($retCode === '9999') {
|
|
|
+ $net_errno = "HTTP-{$retCode}";
|
|
|
+ return [false, $resp['err_msg'], true];
|
|
|
+ } else {
|
|
|
+ $err = 998;
|
|
|
+ $net_errno = "HTTP-{$err}";
|
|
|
+ return [false, $resp['err_msg'], true];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function query($refill_info)
|
|
|
+ {
|
|
|
+ $params['userid'] = config::USER_ID;
|
|
|
+ $params['userpws'] = md5(config::USER_PWS);
|
|
|
+ $params['sporder_id'] = $refill_info['order_sn'];
|
|
|
+ $params['version'] = '6.0';
|
|
|
+
|
|
|
+ $key = config::KEY;
|
|
|
+ $content = "{$params['userid']}{$params['userpws']}{$params['sporder_id']}{$key}";
|
|
|
+ $params['md5_str'] = strtoupper(md5($content));
|
|
|
+
|
|
|
+ $resp = http_request(config::QUERY_URL, $params, 'POST', false, config::ExtHeaders);
|
|
|
+
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '网络错误'];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Log::record($resp, Log::DEBUG);
|
|
|
+ $resp = $this->xmlToArray($resp, 'GB2312');
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '网络错误'];
|
|
|
+ }
|
|
|
+ elseif ($resp['retcode'] === '1')
|
|
|
+ {
|
|
|
+ $status = $resp['game_state'];
|
|
|
+ if ($status === '1') {
|
|
|
+ $order_state = ORDER_STATE_SUCCESS;
|
|
|
+ } elseif ($status === '9') {
|
|
|
+ $order_state = ORDER_STATE_CANCEL;
|
|
|
+ } elseif ($status === '0') {
|
|
|
+ $order_state = ORDER_STATE_SEND;
|
|
|
+ } else {
|
|
|
+ return [false, $resp['err_msg']];
|
|
|
+ }
|
|
|
+ return [true, $order_state];
|
|
|
+ }
|
|
|
+ elseif ($resp['retcode'] === '1010' && (time() - $refill_info['commit_time'] > 600))
|
|
|
+ {
|
|
|
+ return [true, ORDER_STATE_NOEXIST];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return [false, $resp['err_msg']];
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function balance()
|
|
|
+ {
|
|
|
+ $params['userid'] = config::USER_ID;
|
|
|
+ $params['userpws'] = md5(config::USER_PWS);
|
|
|
+ $params['version'] = '6.0';
|
|
|
+
|
|
|
+ $resp = http_request(config::BALANCE_URL, $params, 'POST', false, config::ExtHeaders);
|
|
|
+
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '网络错误'];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Log::record($resp, Log::DEBUG);
|
|
|
+ $resp = $this->xmlToArray($resp, 'GB2312');
|
|
|
+
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '网络错误'];
|
|
|
+ } elseif ($resp['retcode'] === '1') {
|
|
|
+ return [true, $resp['totalBalance']];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['err_msg']];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function sign($params)
|
|
|
+ {
|
|
|
+ $key = config::KEY;
|
|
|
+ $content = "{$params['userid']}{$params['userpws']}{$params['cardid']}{$params['cardnum']}{$params['sporder_id']}{$params['sporder_time']}{$params['game_userid']}";
|
|
|
+ $content .= $key;
|
|
|
+ return strtoupper(md5($content));
|
|
|
+ }
|
|
|
+
|
|
|
+ public function xmlToArray($xml, $encode = 'GBK')
|
|
|
+ {
|
|
|
+ $getEncoder = function ($xml,$default_encode)
|
|
|
+ {
|
|
|
+ $ret = preg_match("/<?xml\s+[\s\S]*(encoding=[\"']([^\"']*)[\"'])[\s\S]*?>/", $xml, $res);
|
|
|
+ if($ret !== false && count($res) === 3) {
|
|
|
+ return [$res[2], $res[1]];
|
|
|
+ } else {
|
|
|
+ return [$default_encode,'encoding="' . $default_encode . '"'];
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ [$encode, $replace_str] = $getEncoder($xml, $encode);
|
|
|
+ $xml = mb_convert_encoding($xml,"utf-8","{$encode}");
|
|
|
+ $xml = str_replace($replace_str, "encoding='utf-8'", $xml);
|
|
|
+ return refill\util::xmlToArray($xml);
|
|
|
+ }
|
|
|
+}
|