|
@@ -0,0 +1,191 @@
|
|
|
|
+<?php
|
|
|
|
+
|
|
|
|
+namespace refill\suhu_normal;
|
|
|
|
+
|
|
|
|
+require_once(BASE_HELPER_RAPI_PATH . '/suhu_normal/config.php');
|
|
|
|
+
|
|
|
|
+use refill;
|
|
|
|
+use Log;
|
|
|
|
+
|
|
|
|
+class RefillPhone extends refill\IRefillPhone
|
|
|
|
+{
|
|
|
|
+ public function __construct($cfgs)
|
|
|
|
+ {
|
|
|
|
+ parent::__construct($cfgs);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function add_params(int $phone, int $amount, string $order_sn, int $card_type): array
|
|
|
|
+ {
|
|
|
|
+ $signer = function ($params)
|
|
|
|
+ {
|
|
|
|
+ $body = "memberId={$params['memberId']}productId={$params['productId']}memberOrderId={$params['memberOrderId']}rechargeAccount={$params['rechargeAccount']}faceValue={$params['faceValue']}signkey=";
|
|
|
|
+ $body .= config::KEY;
|
|
|
|
+
|
|
|
|
+ return md5($body);
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ $sku_code = config::sku_code($card_type,$amount);
|
|
|
|
+ if(empty($sku_code)) {
|
|
|
|
+ return [];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $params = [
|
|
|
|
+ "memberId" => config::MEMBER_ID,
|
|
|
|
+ 'productId' => $sku_code,
|
|
|
|
+ 'memberOrderId' => $order_sn,
|
|
|
|
+ 'rechargeAccount' => "$phone",
|
|
|
|
+ 'faceValue' => "$amount"
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ $params['sign'] = $signer($params);
|
|
|
|
+ return $params;
|
|
|
|
+ }
|
|
|
|
+ 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);
|
|
|
|
+ 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);
|
|
|
|
+
|
|
|
|
+ if (empty($resp)) {
|
|
|
|
+ return [false, '网络错误', true];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $code = $resp['code'];
|
|
|
|
+ if ($code === 100) {
|
|
|
|
+ return [true, $resp['rechargeOrderId'], false];
|
|
|
|
+ } elseif (in_array($code, config::ERRCODES, true)) {
|
|
|
|
+ return [false, $resp['msg'], false];
|
|
|
|
+ } elseif ($code === 999) {
|
|
|
|
+ $net_errno = "HTTP-$code";
|
|
|
|
+ return [false, $resp['msg'], true];
|
|
|
|
+ } else {
|
|
|
|
+ $net_errno = "HTTP-998";
|
|
|
|
+ return [false, $resp['msg'], true];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function query_params($refill_info)
|
|
|
|
+ {
|
|
|
|
+ $params = [
|
|
|
|
+ 'memberId' => config::MEMBER_ID,
|
|
|
|
+ 'memberOrderId' => $refill_info['order_sn'],
|
|
|
|
+ 'requestDate' => date("Y-m-d H:i:s",time())
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ $signer = function ($params)
|
|
|
|
+ {
|
|
|
|
+ $body = "memberId={$params['memberId']}rechargeOrderId=memberOrderId={$params['memberOrderId']}requestDate={$params['requestDate']}signkey=";
|
|
|
|
+ $body .= config::KEY;
|
|
|
|
+
|
|
|
|
+ return md5($body);
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ $params['sign'] = $signer($params);
|
|
|
|
+ return $params;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function query($refill_info): array
|
|
|
|
+ {
|
|
|
|
+ $params = $this->query_params($refill_info);
|
|
|
|
+ $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, '系统错误', ''];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $official_sn = '';
|
|
|
|
+
|
|
|
|
+ $status = intval($resp['status']);
|
|
|
|
+ if($status === 1)
|
|
|
|
+ {
|
|
|
|
+ if(empty($resp['result'])) {
|
|
|
|
+ return [false, '系统错误', ''];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $item = $resp['result'][0];
|
|
|
|
+
|
|
|
|
+ $code = $item['code'];
|
|
|
|
+ if($code == 200) {
|
|
|
|
+ $order_state = ORDER_STATE_SEND;
|
|
|
|
+ }
|
|
|
|
+ elseif($code == 201) {
|
|
|
|
+ $updata['official_sn'] = $item['supplyCert'];
|
|
|
|
+ Model('refill_order')->edit($refill_info['order_id'], $updata);
|
|
|
|
+ $official_sn = $item['supplyCert'];
|
|
|
|
+ $order_state = ORDER_STATE_SUCCESS;
|
|
|
|
+ }
|
|
|
|
+ elseif(in_array($code,[202,203,204])) {
|
|
|
|
+ $order_state = ORDER_STATE_CANCEL;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ elseif($status === 2 and (time() - $refill_info['commit_time'] >= 600))
|
|
|
|
+ {
|
|
|
|
+ $order_state = ORDER_STATE_NOEXIST;
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ return [false, $resp['msg']];
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return [true, $order_state, $official_sn];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function balance_params()
|
|
|
|
+ {
|
|
|
|
+ $params = [
|
|
|
|
+ 'memberId' => config::MEMBER_ID,
|
|
|
|
+ 'requestDate' => date("Y-m-d H:i:s", time())
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ $signer = function ($params)
|
|
|
|
+ {
|
|
|
|
+ $body = "memberId={$params['memberId']}requestDate={$params['requestDate']}signkey=";
|
|
|
|
+ $body .= config::KEY;
|
|
|
|
+
|
|
|
|
+ return md5($body);
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ $params['sign'] = $signer($params);
|
|
|
|
+ return $params;
|
|
|
|
+ }
|
|
|
|
+ public function balance(): array
|
|
|
|
+ {
|
|
|
|
+ $params = $this->balance_params();
|
|
|
|
+ $resp = http_request(config::ORDER_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['status'] === 1) {
|
|
|
|
+ return [true, ncPriceFormat($resp['result']['money'])];
|
|
|
|
+ } else {
|
|
|
|
+ return [false, $resp['msg']];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|