|
@@ -0,0 +1,173 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace refill\meihan_fs;
|
|
|
+
|
|
|
+require_once(BASE_HELPER_RAPI_PATH . '/meihan_fs/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 $amount, int $card_type, string $order_sn, $regin_no)
|
|
|
+ {
|
|
|
+ $params['appId'] = config::APP_ID;
|
|
|
+ $params['outOrderId'] = $order_sn;
|
|
|
+ $params['uuid'] = $phone;
|
|
|
+ $params['itemId'] = config::PRODUCT[$card_type][$regin_no][$amount];
|
|
|
+ $params['itemFace'] = $amount;
|
|
|
+ $params['callbackUrl'] = config::NOTIFY_URL;
|
|
|
+ $params['timestamp'] = date("YmdHis").$this->get_millisecond();
|
|
|
+ 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];
|
|
|
+ }
|
|
|
+ $order_sn = $params['order_sn'];
|
|
|
+ $params = $this->req_params($card_no, $amount, $card_type, $order_sn, $regin_no);
|
|
|
+ if(empty($params['itemId'])) {
|
|
|
+ return [false, '商品编号错误', false];
|
|
|
+ }
|
|
|
+ $sign = $this->sign($params);
|
|
|
+ $params['sign'] = $sign;
|
|
|
+
|
|
|
+ $resp = http_request(config::ORDER_URL, $params, 'POST', false, 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'] === '00') {
|
|
|
+ return [true, $resp['orderId'], false];
|
|
|
+ } elseif (in_array($resp['code'], config::ERRCODES, true)) {
|
|
|
+ return [false, $resp['msg'], false];
|
|
|
+ } elseif (in_array($resp['code'], ['-22', '-23', '-99'], true)) {
|
|
|
+ $net_errno = "HTTP-{$resp['code']}";
|
|
|
+ return [false, $resp['msg'], true];
|
|
|
+ } else {
|
|
|
+ $net_errno = "HTTP-998";
|
|
|
+ return [false, $resp['msg'], true];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function query($refill_info)
|
|
|
+ {
|
|
|
+ $params['appId'] = config::APP_ID;
|
|
|
+ $params['outOrderId'] = $refill_info['order_sn'];
|
|
|
+ $params['timestamp'] = date("YmdHis").$this->get_millisecond();
|
|
|
+ $params['sign'] = $this->sign($params);
|
|
|
+
|
|
|
+ $resp = http_request(config::QUERY_URL, $params, 'POST', false, 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'] === '00')
|
|
|
+ {
|
|
|
+ $status = $resp['orderStatus'];
|
|
|
+ if ($status === '2') {
|
|
|
+ $updata['official_sn'] = $resp['ext1'];
|
|
|
+ Model('refill_order')->edit($refill_info['order_id'], $updata);
|
|
|
+ $order_state = ORDER_STATE_SUCCESS;
|
|
|
+ } elseif ($status === '3') {
|
|
|
+ $order_state = ORDER_STATE_CANCEL;
|
|
|
+ } elseif ($status === '1') {
|
|
|
+ $order_state = ORDER_STATE_SEND;
|
|
|
+ } elseif ($status === '4' && (time() - $refill_info['commit_time'] >= 600)) {
|
|
|
+ $order_state = ORDER_STATE_NOEXIST;
|
|
|
+ } else {
|
|
|
+ return [false, $resp['msg']];
|
|
|
+ }
|
|
|
+ return [true, $order_state];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return [false, $resp['msg']];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function balance()
|
|
|
+ {
|
|
|
+ $params['appId'] = config::APP_ID;
|
|
|
+ $params['timestamp'] = date("YmdHis").$this->get_millisecond();
|
|
|
+ $params['sign'] = $this->sign($params);
|
|
|
+
|
|
|
+ $resp = http_request(config::BALANCE_URL, $params, 'POST', false, 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'] === '00') {
|
|
|
+ return [true, $resp['balance']];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['msg']];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取毫秒级别的时间戳
|
|
|
+ */
|
|
|
+ private function get_millisecond()
|
|
|
+ {
|
|
|
+ list($usec, $sec) = explode(" ", microtime());
|
|
|
+ return round($usec*1000);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function sign($params)
|
|
|
+ {
|
|
|
+ $params['appSecret'] = config::APP_SECRET;
|
|
|
+ ksort($params);
|
|
|
+ $content = '';
|
|
|
+ foreach ($params as $key => $value) {
|
|
|
+ if($this->check_empty($value) === false) {
|
|
|
+ $content .= "{$key}={$value}&";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $content = rtrim($content, '&');
|
|
|
+ return md5($content);
|
|
|
+ }
|
|
|
+}
|