|
@@ -0,0 +1,186 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace refill\by_online_kami;
|
|
|
+
|
|
|
+require_once(BASE_HELPER_RAPI_PATH . '/by_online_kami/config.php');
|
|
|
+
|
|
|
+use refill;
|
|
|
+use Log;
|
|
|
+use Cache;
|
|
|
+
|
|
|
+class RefillPhone extends refill\IRefillPhone
|
|
|
+{
|
|
|
+ public function __construct($cfgs)
|
|
|
+ {
|
|
|
+ parent::__construct($cfgs);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function req_params(int $phone, int $amount, int $card_type, string $order_sn, $regin_no)
|
|
|
+ {
|
|
|
+ $params['appId'] = config::APP_ID;
|
|
|
+ $params['version'] = '1.0';
|
|
|
+ $params['merchantOrderNo'] = $order_sn;
|
|
|
+ $params['productId'] = 1;
|
|
|
+ $params['account'] = "{$phone}";
|
|
|
+ $params['amt'] = $amount * 100;
|
|
|
+ $params['callbackUrl'] = config::NOTIFY_URL;
|
|
|
+ $params['provinceId'] = config::ProvinceMap[$regin_no];
|
|
|
+ $params['parameter'] = '';
|
|
|
+ $params['extra'] = '';
|
|
|
+
|
|
|
+ return $params;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function add($card_no, $card_type, $amount, $params, &$net_errno = 0)
|
|
|
+ {
|
|
|
+ $regin_no = $params['regin_no'] ?? -1;
|
|
|
+ if ($regin_no <= 0) {
|
|
|
+ return [false, '省份获取错误', false];
|
|
|
+ }
|
|
|
+
|
|
|
+ if($this->exist($card_no)) {
|
|
|
+ return [false, '今日已经提交过', false];
|
|
|
+ }
|
|
|
+
|
|
|
+ $params = $this->req_params($card_no, $amount, $card_type, $params['order_sn'], $regin_no);
|
|
|
+ $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);
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '系统错误', true];
|
|
|
+ } elseif ($resp['code'] === 1000) {
|
|
|
+ return [true, $resp['data']['order_sn'], false];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['msg'], false];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function query($refill_info)
|
|
|
+ {
|
|
|
+ $params['appId'] = config::APP_ID;
|
|
|
+ $params['version'] = '1.0';
|
|
|
+ $params['merchantOrderNo'] = $refill_info['order_sn'];
|
|
|
+ $sign = config::sign($params);
|
|
|
+ $params['sign'] = $sign;
|
|
|
+
|
|
|
+ $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, '网络错误'];
|
|
|
+ }
|
|
|
+ elseif ($resp['code'] === 1000)
|
|
|
+ {
|
|
|
+ $status = $resp['data']['order_status'];
|
|
|
+ if ($status === 7) {
|
|
|
+ $updata['official_sn'] = $resp['data']['charge_id'];
|
|
|
+ Model('refill_order')->edit($refill_info['order_id'], $updata);
|
|
|
+ $order_state = ORDER_STATE_SUCCESS;
|
|
|
+ } elseif (in_array($status, [3, 4, 6], true)) {
|
|
|
+ $order_state = ORDER_STATE_CANCEL;
|
|
|
+ } elseif (in_array($status, [0, 1, 2, 5], true)) {
|
|
|
+ $order_state = ORDER_STATE_SEND;
|
|
|
+ } else {
|
|
|
+ return [false, $status];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, $order_state];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return [false, $resp['msg']];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function balance()
|
|
|
+ {
|
|
|
+ $params['appId'] = config::APP_ID;
|
|
|
+ $params['version'] = '1.0';
|
|
|
+ $sign = config::sign($params);
|
|
|
+ $params['sign'] = $sign;
|
|
|
+
|
|
|
+ $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, '系统错误'];
|
|
|
+ } elseif ($resp['code'] === 1000) {
|
|
|
+ return [true, $resp['data']['balance'] / 100];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['msg']];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function exist($card_no)
|
|
|
+ {
|
|
|
+ $ins = Cache::getInstance('cacheredis');
|
|
|
+ $today = strtotime(date('Ymd',time()));
|
|
|
+
|
|
|
+ $name = "unique_tongfu_{$today}";
|
|
|
+ $key = "$card_no";
|
|
|
+
|
|
|
+ $value = $ins->hget($name,'',$key);
|
|
|
+ if($value === false) {
|
|
|
+ $ins->hset($name, '', [$key=> 1]);
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //[是否需要返销,是否网络错误]
|
|
|
+ public function need_refund($refill_info)
|
|
|
+ {
|
|
|
+ $params['appId'] = config::APP_ID;
|
|
|
+ $params['version'] = '1.0';
|
|
|
+ $params['merchantOrderNo'] = $refill_info['order_sn'];
|
|
|
+ $sign = config::sign($params);
|
|
|
+ $params['sign'] = $sign;
|
|
|
+
|
|
|
+ $resp = http_request(config::QUERY_URL, $params);
|
|
|
+
|
|
|
+ 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['code'] === 1000)
|
|
|
+ {
|
|
|
+ $status = $resp['data']['order_status'];
|
|
|
+ if ($status === 8 or $status === 3) {
|
|
|
+ return [true,false];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return [false,false];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|