|
@@ -17,28 +17,30 @@ class RefillPhone extends refill\IRefillPhone
|
|
|
|
|
|
private function add_params(int $phone, int $amount, string $order_sn, int $card_type): array
|
|
|
{
|
|
|
- $nSortType = function ($card_type)
|
|
|
+ $nSortType_getter = function ($card_type)
|
|
|
{
|
|
|
- if($card_type == mtopcard\ChinaMobileCard) {
|
|
|
+ if ($card_type == mtopcard\ChinaMobileCard) {
|
|
|
return 1;
|
|
|
- }
|
|
|
- elseif($card_type == mtopcard\ChinaUnicomCard) {
|
|
|
+ } elseif ($card_type == mtopcard\ChinaUnicomCard) {
|
|
|
return 2;
|
|
|
- }
|
|
|
- elseif($card_type == mtopcard\ChinaTelecomCard) {
|
|
|
+ } elseif ($card_type == mtopcard\ChinaTelecomCard) {
|
|
|
return 3;
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
return false;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+ $nSortType = $nSortType_getter($card_type);
|
|
|
+ if($nSortType === false) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
$params = [
|
|
|
'szAgentId' => config::szAgentId,
|
|
|
'szOrderId' => $order_sn,
|
|
|
'szPhoneNum'=> "$phone",
|
|
|
'nMoney' => $amount,
|
|
|
- 'nSortType' => $nSortType($card_type),
|
|
|
+ 'nSortType' => $nSortType,
|
|
|
'nProductClass' => 1,
|
|
|
'nProductType' =>"1",
|
|
|
'szTimeStamp'=> date("Y-m-d H:i:s"),
|
|
@@ -46,9 +48,10 @@ class RefillPhone extends refill\IRefillPhone
|
|
|
];
|
|
|
|
|
|
$params['szVerifyString'] = config::sign($params,config::add_keys);
|
|
|
-
|
|
|
return $params;
|
|
|
}
|
|
|
+
|
|
|
+ //[$state, $errmsg, $neterr]
|
|
|
public function add($card_no, $card_type, $amount, $params, &$net_errno = 0): array
|
|
|
{
|
|
|
$params = $this->add_params($card_no, $amount, $params['order_sn'], $card_type);
|
|
@@ -57,7 +60,6 @@ class RefillPhone extends refill\IRefillPhone
|
|
|
}
|
|
|
|
|
|
$resp = http_request(config::ORDER_URL, $params , 'POST' , false , [] , $net_errno);
|
|
|
-
|
|
|
if (empty($resp)) {
|
|
|
return [false, '网络错误', true];
|
|
|
}
|
|
@@ -73,12 +75,12 @@ class RefillPhone extends refill\IRefillPhone
|
|
|
$nRtn = $resp['nRtn'];
|
|
|
if ($nRtn === 0) { //下单成功
|
|
|
return [true, $resp['szOrderId'], false];
|
|
|
- } elseif (in_array($nRtn, config::ERRCODES, true)) { //下单错误
|
|
|
+ } elseif (in_array($nRtn, config::ERRCODES, true)) {
|
|
|
return [false, config::ERRMSG[$nRtn], false];
|
|
|
- } elseif (in_array($nRtn, [2050, 999] )) { //下单异常
|
|
|
+ } elseif (in_array($nRtn, [2050, 999])) { //下单异常
|
|
|
$net_errno = "HTTP-$nRtn";
|
|
|
return [false, config::ERRMSG[$nRtn], true];
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
$net_errno = "HTTP-998";
|
|
|
return [false, "其他异常", true];
|
|
|
}
|
|
@@ -116,26 +118,22 @@ class RefillPhone extends refill\IRefillPhone
|
|
|
$official_sn = '';
|
|
|
|
|
|
$nRtn = intval($resp['nRtn']);
|
|
|
- if($nRtn === 5012)//充值成功
|
|
|
- {
|
|
|
+ if ($nRtn === 5012) {
|
|
|
$updata['official_sn'] = $resp['szRtnMsg'];
|
|
|
Model('refill_order')->edit($refill_info['szOrderId'], $updata);
|
|
|
$order_state = ORDER_STATE_SUCCESS;
|
|
|
}
|
|
|
- elseif($nRtn === 5011 or $nRtn === 5019)//充值中
|
|
|
- {
|
|
|
- $order_state = ORDER_STATE_SEND;
|
|
|
+ elseif($nRtn === 5013) {
|
|
|
+ $order_state = ORDER_STATE_CANCEL;
|
|
|
}
|
|
|
- elseif($nRtn === 5001 or $nRtn === 5002 or $nRtn === 5003 or $nRtn === 5004 or $nRtn === 999)//不处理订单
|
|
|
- {
|
|
|
+ elseif (in_array($nRtn, [999, 5001, 5002, 5003, 5004, 5011, 5019])) {
|
|
|
$order_state = ORDER_STATE_SEND;
|
|
|
}
|
|
|
- elseif($nRtn === 5005 and (time() - $refill_info['commit_time'] >= 300))//订单可能不存在
|
|
|
- {
|
|
|
+ elseif($nRtn === 5005 and (time() - $refill_info['commit_time'] >= 300)) {
|
|
|
$order_state = ORDER_STATE_NOEXIST;
|
|
|
}
|
|
|
else {
|
|
|
- return [false, '其他,或网络错误'];
|
|
|
+ return [false, '其他,或网络错误', ''];
|
|
|
}
|
|
|
|
|
|
return [true, $order_state, $official_sn];
|
|
@@ -145,18 +143,10 @@ class RefillPhone extends refill\IRefillPhone
|
|
|
private function balance_params()
|
|
|
{
|
|
|
$params = [
|
|
|
- 'szAgentId' => config::szAgentId,
|
|
|
- 'szFormat' => 'JSON',
|
|
|
+ 'szAgentId' => config::szAgentId
|
|
|
];
|
|
|
|
|
|
- $signer = function ($params)
|
|
|
- {
|
|
|
- $body = "szAgentId={$params['szAgentId']}&"."szKey=".config::szKey;
|
|
|
-
|
|
|
- return strtolower(md5($body));
|
|
|
- };
|
|
|
-
|
|
|
- $params['szVerifyString'] = $signer($params);
|
|
|
+ $params['szVerifyString'] = config::sign($params, config::balance_keys);
|
|
|
return $params;
|
|
|
}
|
|
|
public function balance(): array
|
|
@@ -174,13 +164,8 @@ class RefillPhone extends refill\IRefillPhone
|
|
|
if (empty($resp)) {
|
|
|
return [false, '系统错误'];
|
|
|
} elseif ($resp['nRtn'] === 0) {
|
|
|
- return [true, ncPriceFormat($resp['fBalance']+$resp['fCredit'])];
|
|
|
+ return [true, ncPriceFormat($resp['fBalance'] + $resp['fCredit'])];
|
|
|
} else {
|
|
|
- switch($resp['nRtn']){
|
|
|
- case 1 : return [false, '请求失败'];
|
|
|
- case 5002 : return [false, '查询频繁'];
|
|
|
- case 999 : return [false, '系统异常'];
|
|
|
- }
|
|
|
return [false, '其它,失败'];
|
|
|
}
|
|
|
}
|