|
@@ -1,146 +1,149 @@
|
|
-<?php
|
|
|
|
-
|
|
|
|
-namespace refill\lingzhman48;
|
|
|
|
-
|
|
|
|
-require_once(BASE_HELPER_RAPI_PATH . '/lingzhman48/config.php');
|
|
|
|
-
|
|
|
|
-use refill;
|
|
|
|
-use Log;
|
|
|
|
-
|
|
|
|
-class RefillPhone extends refill\IRefillPhone
|
|
|
|
-{
|
|
|
|
- public function __construct($cfgs)
|
|
|
|
- {
|
|
|
|
- parent::__construct($cfgs);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private function req_params(int $phone, string $order_sn)
|
|
|
|
- {
|
|
|
|
- $params['account'] = config::ACCOUNT;
|
|
|
|
- $params['consumerNo'] = $order_sn;
|
|
|
|
- $params['mobile'] = $phone;
|
|
|
|
- $params['timestamp'] = date("YmdHis");
|
|
|
|
-
|
|
|
|
- return $params;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public function add($card_no, $card_type, $amount, $params,&$net_errno = 0): array
|
|
|
|
- {
|
|
|
|
- $params = $this->req_params($card_no, $params['order_sn']);
|
|
|
|
- $params['flowCode'] = config::ProductIDS[$card_type][$amount];
|
|
|
|
- if (empty($params['flowCode'])) {
|
|
|
|
- return [false, '产品编号错误', false];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- $sign = $this->sign($params);
|
|
|
|
- $params['sign'] = $sign;
|
|
|
|
-
|
|
|
|
- $resp = http_request(config::ORDER_URL, $params, 'GET', false, [], $net_errno);
|
|
|
|
-
|
|
|
|
- if (empty($resp)) {
|
|
|
|
- return [false, '系统错误', true];
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- Log::record($resp, Log::DEBUG);
|
|
|
|
- $resp = json_decode($resp ,true);
|
|
|
|
-
|
|
|
|
- if (empty($resp)) {
|
|
|
|
- return [false, '系统错误', true];
|
|
|
|
- } elseif ($resp['status'] === '001') {
|
|
|
|
- return [true, $resp['orderNo'], false];
|
|
|
|
- } else {
|
|
|
|
- return [false, $resp['status'], false];
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public function query($refill_info): array
|
|
|
|
- {
|
|
|
|
- $params['account'] = config::ACCOUNT;
|
|
|
|
- $params['consumerNo'] = $refill_info['order_sn'];
|
|
|
|
- $params['timestamp'] = date("YmdHis");
|
|
|
|
- $params['sign'] = $this->sign($params);
|
|
|
|
-
|
|
|
|
- $resp = http_request(config::QUERY_URL, $params);
|
|
|
|
- if (empty($resp)) {
|
|
|
|
- return [false, '系统错误'];
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- Log::record($resp, Log::DEBUG);
|
|
|
|
- $resp = json_decode($resp, true);
|
|
|
|
- if (empty($resp)) {
|
|
|
|
- return [false, '系统错误'];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- $status = $resp['status'];
|
|
|
|
- if ($status === '001') {
|
|
|
|
- $order_state = ORDER_STATE_SUCCESS;
|
|
|
|
- $save['official_sn'] = strtolower($resp['voucherNo']) == 'null' ? '' : $resp['voucherNo'];
|
|
|
|
- Model('refill_order')->edit($refill_info['order_id'], $save);
|
|
|
|
- }
|
|
|
|
- elseif (in_array($status,config::QueryErrCodes))
|
|
|
|
- {
|
|
|
|
- if ($status === '026')
|
|
|
|
- {
|
|
|
|
- //订单不存在状态,三小时内查询可失败,超过则返回充值中.不可以在下单后的同时立马发起查询,否则返回该状态处理充值中,至少延迟10秒以上再发起查询
|
|
|
|
- if (time() - $refill_info['commit_time'] <= 10800 && time() - $refill_info['commit_time'] >= 10) {
|
|
|
|
- $order_state = ORDER_STATE_CANCEL;
|
|
|
|
- } else {
|
|
|
|
- $order_state = ORDER_STATE_SEND;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- $order_state = ORDER_STATE_CANCEL;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- elseif ($status === '002') {
|
|
|
|
- $order_state = ORDER_STATE_SEND;
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- return [false, $status];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return [true, $order_state];
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public function balance()
|
|
|
|
- {
|
|
|
|
- $params['account'] = config::ACCOUNT;
|
|
|
|
- $params['timestamp'] = date("YmdHis");
|
|
|
|
- $params['sign'] = $this->sign($params);
|
|
|
|
-
|
|
|
|
- $resp = http_request(config::BALANCE_URL, $params);
|
|
|
|
- if (empty($resp)) {
|
|
|
|
- return [false, '系统错误'];
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- Log::record($resp, Log::DEBUG);
|
|
|
|
- $resp = json_decode($resp, true);
|
|
|
|
- if (empty($resp)) {
|
|
|
|
- return [false, '系统错误'];
|
|
|
|
- } else {
|
|
|
|
- if ($resp['status'] === 'success') {
|
|
|
|
- return [true, $resp['balance']];
|
|
|
|
- } else {
|
|
|
|
- return [false, $resp['descriptor']];
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- private function sign($params)
|
|
|
|
- {
|
|
|
|
- $data['account'] = $params['account'];
|
|
|
|
- $data['timestamp'] = $params['timestamp'];
|
|
|
|
- $data['secret'] = config::KEY;
|
|
|
|
- asort($data);
|
|
|
|
- $content = '';
|
|
|
|
- foreach ($data as $val){
|
|
|
|
- $content .= $val;
|
|
|
|
- }
|
|
|
|
- return sha1($content);
|
|
|
|
- }
|
|
|
|
|
|
+<?php
|
|
|
|
+
|
|
|
|
+namespace refill\lingzhman48;
|
|
|
|
+
|
|
|
|
+require_once(BASE_HELPER_RAPI_PATH . '/lingzhman48/config.php');
|
|
|
|
+
|
|
|
|
+use refill;
|
|
|
|
+use Log;
|
|
|
|
+
|
|
|
|
+class RefillPhone extends refill\IRefillPhone
|
|
|
|
+{
|
|
|
|
+ public function __construct($cfgs)
|
|
|
|
+ {
|
|
|
|
+ parent::__construct($cfgs);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function req_params(int $phone, string $order_sn)
|
|
|
|
+ {
|
|
|
|
+ $params['account'] = config::ACCOUNT;
|
|
|
|
+ $params['consumerNo'] = $order_sn;
|
|
|
|
+ $params['mobile'] = $phone;
|
|
|
|
+ $params['timestamp'] = date("YmdHis");
|
|
|
|
+
|
|
|
|
+ return $params;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function add($card_no, $card_type, $amount, $params,&$net_errno = 0): array
|
|
|
|
+ {
|
|
|
|
+ $params = $this->req_params($card_no, $params['order_sn']);
|
|
|
|
+ $params['flowCode'] = config::ProductIDS[$card_type][$amount];
|
|
|
|
+ if (empty($params['flowCode'])) {
|
|
|
|
+ return [false, '产品编号错误', false];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $sign = $this->sign($params);
|
|
|
|
+ $params['sign'] = $sign;
|
|
|
|
+
|
|
|
|
+ $resp = http_request(config::ORDER_URL, $params, 'GET', false, [], $net_errno);
|
|
|
|
+
|
|
|
|
+ if (empty($resp)) {
|
|
|
|
+ return [false, '系统错误', true];
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ Log::record($resp, Log::DEBUG);
|
|
|
|
+ $resp = json_decode($resp ,true);
|
|
|
|
+
|
|
|
|
+ if (empty($resp)) {
|
|
|
|
+ return [false, '系统错误', true];
|
|
|
|
+ } elseif ($resp['status'] === '001') {
|
|
|
|
+ return [true, $resp['orderNo'], false];
|
|
|
|
+ } else {
|
|
|
|
+ return [false, $resp['status'], false];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function query($refill_info): array
|
|
|
|
+ {
|
|
|
|
+ $params['account'] = config::ACCOUNT;
|
|
|
|
+ $params['consumerNo'] = $refill_info['order_sn'];
|
|
|
|
+ $params['timestamp'] = date("YmdHis");
|
|
|
|
+ $params['sign'] = $this->sign($params);
|
|
|
|
+
|
|
|
|
+ $resp = http_request(config::QUERY_URL, $params);
|
|
|
|
+ if (empty($resp)) {
|
|
|
|
+ return [false, '系统错误'];
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ Log::record($resp, Log::DEBUG);
|
|
|
|
+ $resp = json_decode($resp, true);
|
|
|
|
+ if (empty($resp)) {
|
|
|
|
+ return [false, '系统错误'];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $status = $resp['status'];
|
|
|
|
+ if ($status === '001') {
|
|
|
|
+ $order_state = ORDER_STATE_SUCCESS;
|
|
|
|
+ $save['official_sn'] = strtolower($resp['voucherNo']) == 'null' ? '' : $resp['voucherNo'];
|
|
|
|
+ Model('refill_order')->edit($refill_info['order_id'], $save);
|
|
|
|
+ }
|
|
|
|
+ elseif (in_array($status,config::QueryErrCodes))
|
|
|
|
+ {
|
|
|
|
+ if ($status === '026')
|
|
|
|
+ {
|
|
|
|
+ //订单不存在状态,三小时内查询可失败,超过则返回充值中.不可以在下单后的同时立马发起查询,否则返回该状态处理为充值中,至少隔30秒以上再发起查询
|
|
|
|
+ $commit_secs = time() - $refill_info['commit_time'];
|
|
|
|
+ if ($commit_secs > 0 && $commit_secs < 30) {
|
|
|
|
+ return [false, '时长不足'];
|
|
|
|
+ } elseif ($commit_secs <= 10800 && $commit_secs >= 30) {
|
|
|
|
+ $order_state = ORDER_STATE_NOEXIST;
|
|
|
|
+ } else {
|
|
|
|
+ $order_state = ORDER_STATE_SEND;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ $order_state = ORDER_STATE_CANCEL;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ elseif ($status === '002') {
|
|
|
|
+ $order_state = ORDER_STATE_SEND;
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ return [false, $status];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return [true, $order_state];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function balance()
|
|
|
|
+ {
|
|
|
|
+ $params['account'] = config::ACCOUNT;
|
|
|
|
+ $params['timestamp'] = date("YmdHis");
|
|
|
|
+ $params['sign'] = $this->sign($params);
|
|
|
|
+
|
|
|
|
+ $resp = http_request(config::BALANCE_URL, $params);
|
|
|
|
+ if (empty($resp)) {
|
|
|
|
+ return [false, '系统错误'];
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ Log::record($resp, Log::DEBUG);
|
|
|
|
+ $resp = json_decode($resp, true);
|
|
|
|
+ if (empty($resp)) {
|
|
|
|
+ return [false, '系统错误'];
|
|
|
|
+ } else {
|
|
|
|
+ if ($resp['status'] === 'success') {
|
|
|
|
+ return [true, $resp['balance']];
|
|
|
|
+ } else {
|
|
|
|
+ return [false, $resp['descriptor']];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ private function sign($params)
|
|
|
|
+ {
|
|
|
|
+ $data['account'] = $params['account'];
|
|
|
|
+ $data['timestamp'] = $params['timestamp'];
|
|
|
|
+ $data['secret'] = config::KEY;
|
|
|
|
+ asort($data);
|
|
|
|
+ $content = '';
|
|
|
|
+ foreach ($data as $val){
|
|
|
|
+ $content .= $val;
|
|
|
|
+ }
|
|
|
|
+ return sha1($content);
|
|
|
|
+ }
|
|
}
|
|
}
|