|
@@ -0,0 +1,169 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace refill\xuyouoil;
|
|
|
+
|
|
|
+require_once(BASE_HELPER_RAPI_PATH . '/xuyouoil/config.php');
|
|
|
+
|
|
|
+use refill;
|
|
|
+use Log;
|
|
|
+use mtopcard;
|
|
|
+
|
|
|
+class RefillOil extends refill\IRefillOil
|
|
|
+{
|
|
|
+ public function __construct($cfgs)
|
|
|
+ {
|
|
|
+ parent::__construct($cfgs);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function req_params(int $phone, string $order_sn, $product_code, $province)
|
|
|
+ {
|
|
|
+ $params['mchid'] = config::MCHID;
|
|
|
+ $params['orderid'] = $order_sn;
|
|
|
+ $params['number'] = $phone;
|
|
|
+ $params['productid'] = $product_code;
|
|
|
+ $params['timestamp'] = $this->getMillisecond();
|
|
|
+ $params['backurl'] = config::NOTIFY_URL;
|
|
|
+ $params['youka'] = mtopcard\ProvinceList[$province];
|
|
|
+ return $params;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private function getProductCode($goods_id, $sys_pcode)
|
|
|
+ {
|
|
|
+ $thrid_refill = Model('thrid_refill');
|
|
|
+ $product = $thrid_refill->getProviderProduct($this->mStoreID,$goods_id,$sys_pcode);
|
|
|
+ if (empty($product)) {
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ return $product['channel_code'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function add($card_no, $card_type, $amount, $params, &$net_errno = 0)
|
|
|
+ {
|
|
|
+ # $goods_id = intval($params['goods_id']);
|
|
|
+ # $province = $params['province'] ?? -1;
|
|
|
+ # if($province < 0) {
|
|
|
+ # return [false, '省份获取错误', false];
|
|
|
+ # }
|
|
|
+
|
|
|
+ # $product_code = $this->getProductCode($goods_id, $params['product_code']);
|
|
|
+ # if(empty($product_code)) {
|
|
|
+ # return [false, '产品未开启', false];
|
|
|
+ # }
|
|
|
+ # Model('thrid_refill')->edit_third($params['order_id'], ['chcode' => $product_code]);
|
|
|
+
|
|
|
+ $params = $this->req_params($card_no, $params['order_sn'], $params['product_code'], $params['province']);
|
|
|
+ $sign = $this->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['status'] === 0) {
|
|
|
+ return [true, $resp['oid'], false];
|
|
|
+ } elseif ($resp['status'] === -1) {
|
|
|
+ return [false, $resp['msg'], false];
|
|
|
+ } else {
|
|
|
+ $net_errno = "HTTP-998";
|
|
|
+ return [false, $resp['msg'], true];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function query($refill_info)
|
|
|
+ {
|
|
|
+ $params['mchid'] = config::MCHID;
|
|
|
+ $params['orderid'] = $refill_info['order_sn'];
|
|
|
+ $key = config::KEY;
|
|
|
+ $content = "mchid={$params['mchid']}&orderid={$params['orderid']}&key={$key}";
|
|
|
+ $params['sign'] = md5($content);
|
|
|
+
|
|
|
+ $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, '系统错误', ''];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $offical_sn = '';
|
|
|
+ $status = $resp['status'];
|
|
|
+ if ($status === 2) {
|
|
|
+ $offical_sn = $resp['voucher'];
|
|
|
+ $updata['official_sn'] = $offical_sn;
|
|
|
+ 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'] > 300)) {
|
|
|
+ $order_state = ORDER_STATE_NOEXIST;
|
|
|
+ } else {
|
|
|
+ return [false, $status, $offical_sn];
|
|
|
+ }
|
|
|
+ return [true, $order_state, $offical_sn];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function balance()
|
|
|
+ {
|
|
|
+ $params['mchid'] = config::MCHID;
|
|
|
+ $key = config::KEY;
|
|
|
+ $content = "mchid={$params['mchid']}&key={$key}";
|
|
|
+ $params['sign'] = md5($content);
|
|
|
+ $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['status'] === 1) {
|
|
|
+ return [true, $resp['balance']];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['msg']];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function sign($params)
|
|
|
+ {
|
|
|
+ $key = config::KEY;
|
|
|
+ $content = "mchid={$params['mchid']}&orderid={$params['orderid']}&number={$params['number']}&productid={$params['productid']}";
|
|
|
+ $content .= "×tamp={$params['timestamp']}&youka={$params['youka']}&key={$key}";
|
|
|
+ return md5($content);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取毫秒级别的时间戳
|
|
|
+ */
|
|
|
+ private function getMillisecond()
|
|
|
+ {
|
|
|
+ $cur = microtime (true);
|
|
|
+ return intval($cur * 1000);
|
|
|
+ }
|
|
|
+}
|