|
@@ -0,0 +1,155 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace refill\kuaikuaifs;
|
|
|
+
|
|
|
+require_once(BASE_HELPER_RAPI_PATH . '/kuaikuaifs/config.php');
|
|
|
+
|
|
|
+use refill;
|
|
|
+use Log;
|
|
|
+
|
|
|
+class RefillPhone extends refill\IRefillPhone
|
|
|
+{
|
|
|
+ public function __construct($cfgs)
|
|
|
+ {
|
|
|
+ parent::__construct($cfgs);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function goods($quality,int $amount,int $card_type,$regin_no,$other)
|
|
|
+ {
|
|
|
+ [$goods_id, $price] = parent::goods($quality,$amount,$card_type,$regin_no,$other);
|
|
|
+ if($goods_id <= 0) return [0,0];
|
|
|
+ $key = "{$card_type}-{$amount}-{$regin_no}";
|
|
|
+ $price = config::Price[$key];
|
|
|
+ if(empty($price)) {
|
|
|
+ Log::record("channel cannot find price where name={$this->mName}, goods_id = {$goods_id} card_type={$card_type} amount={$amount} regin_no={$regin_no}",Log::ERR);
|
|
|
+ return [0,0];
|
|
|
+ } else {
|
|
|
+ return [$goods_id,ncPriceFormat($price)];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function req_params(int $phone, int $card_type, int $amount, string $order_sn, $regin_no)
|
|
|
+ {
|
|
|
+ $params['orderId'] = $order_sn;
|
|
|
+ $params['uid'] = config::UID;
|
|
|
+ $params['pid'] = config::PRODUCT[$card_type][$regin_no][$amount];
|
|
|
+ $params['phone'] = $phone;
|
|
|
+ $params['notify'] = config::NOTIFY_URL;
|
|
|
+ $params['ts'] = date("YmdHis");
|
|
|
+ return $params;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function add($card_no, $card_type, $amount, $input, &$net_errno = 0)
|
|
|
+ {
|
|
|
+ $regin_no = $params['regin_no'] ?? -1;
|
|
|
+ if($regin_no <= 0) {
|
|
|
+ return [false, '省份获取错误', false];
|
|
|
+ }
|
|
|
+ $params = $this->req_params($card_no, $card_type, $amount, $input['order_sn'], $regin_no);
|
|
|
+ if(empty($params['pid'])) {
|
|
|
+ return [false, '商品编号错误', false];
|
|
|
+ }
|
|
|
+ $sign = config::sign($params);
|
|
|
+ $params['sign'] = $sign;
|
|
|
+
|
|
|
+ $params = json_encode($params);
|
|
|
+ $resp = http_post_data(config::ORDER_URL, $params, config::ExtHeaders, $net_errno);
|
|
|
+
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '系统错误', true];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Log::record($resp, Log::DEBUG);
|
|
|
+ $resp = json_decode($resp, true);
|
|
|
+ $code = $resp['code'];
|
|
|
+
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '系统错误', true];
|
|
|
+ } elseif ($code === '1000') {
|
|
|
+ return [true, $resp['data']['oid'], false];
|
|
|
+ } elseif (in_array($code, ['1020', '1021'])) {
|
|
|
+ $net_errno = "HTTP-{$code}";
|
|
|
+ return [false, '查-' . $resp['message'], true];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['message'], false];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function query($refill_info)
|
|
|
+ {
|
|
|
+ $params['oid'] = $refill_info['order_sn'];
|
|
|
+ $params['ts'] = date("YmdHis");
|
|
|
+ $params['uid'] = config::UID;
|
|
|
+ $sign = config::sign($params);
|
|
|
+ $params['sign'] = $sign;
|
|
|
+
|
|
|
+ $params = json_encode($params);
|
|
|
+ $resp = http_post_data(config::QUERY_URL, $params, config::ExtHeaders);
|
|
|
+
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '系统错误'];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Log::record($resp, Log::DEBUG);
|
|
|
+ $resp = json_decode($resp, true);
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '系统错误'];
|
|
|
+ }
|
|
|
+ elseif($resp['code'] === '1000')
|
|
|
+ {
|
|
|
+ $status = $resp['data']['status'];
|
|
|
+ if ($status === 2) {
|
|
|
+ $updata['official_sn'] = $resp['data']['msg'];
|
|
|
+ Model('refill_order')->edit($refill_info['order_id'], $updata);
|
|
|
+ $order_state = ORDER_STATE_SUCCESS;
|
|
|
+ } elseif ($status === 3) {
|
|
|
+ $order_state = ORDER_STATE_CANCEL;
|
|
|
+ } elseif (in_array($status, [1, 5, 9])) {
|
|
|
+ $order_state = ORDER_STATE_SEND;
|
|
|
+ } else {
|
|
|
+ return [false, $status];
|
|
|
+ }
|
|
|
+ return [true, $order_state];
|
|
|
+ }
|
|
|
+ elseif ($resp['code'] === '1004' && (time() - $refill_info['commit_time'] >= 600))
|
|
|
+ {
|
|
|
+ return [true, ORDER_STATE_NOEXIST];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return [false, $resp['message']];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function balance()
|
|
|
+ {
|
|
|
+ $params['uid'] = config::UID;
|
|
|
+ $params['ts'] = date("YmdHis");
|
|
|
+ $content = "uid={$params['uid']}&ts={$params['ts']}&key=" . config::KEY;
|
|
|
+ $sign = md5($content);
|
|
|
+ $params['sign'] = $sign;
|
|
|
+
|
|
|
+ $params = json_encode($params);
|
|
|
+ $resp = http_post_data(config::BALANCE_URL, $params , config::ExtHeaders);
|
|
|
+
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '系统错误'];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Log::record($resp, Log::DEBUG);
|
|
|
+ $resp = json_decode($resp, true);
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '系统错误'];
|
|
|
+ } elseif ($resp['code'] === '1000') {
|
|
|
+ return [true, $resp['data']['balance']];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['message']];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|