|
@@ -0,0 +1,137 @@
|
|
|
+<?php
|
|
|
+namespace refill\shantong_oil;
|
|
|
+
|
|
|
+require_once(BASE_HELPER_RAPI_PATH . '/shantong_oil/config.php');
|
|
|
+
|
|
|
+use refill;
|
|
|
+use Log;
|
|
|
+class RefillOil extends refill\IRefillPhone
|
|
|
+{
|
|
|
+ public function __construct($cfgs)
|
|
|
+ {
|
|
|
+ parent::__construct($cfgs);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function req_params(int $card_no, int $amount, int $card_type, string $order_sn)
|
|
|
+ {
|
|
|
+ $params['chargeNumber'] = $card_no;
|
|
|
+ $params['perValue'] = $amount;
|
|
|
+ $params['orderId'] = $order_sn;
|
|
|
+ $params['orderDate'] = date("Y-m-d H:i:s");
|
|
|
+ $params['agentId'] = config::AGENT_ID;
|
|
|
+ $params['transactionPin'] = config::transactionPin;
|
|
|
+ $params['notifyUrl'] = config::NOTIFY_URL;
|
|
|
+ $params['businessId'] = 3;
|
|
|
+ $params['chargeName'] = '张三';
|
|
|
+
|
|
|
+ $card_info = refill\util::read_card($card_no,$card_type);
|
|
|
+ $params['chargeTel'] = $card_info['bind_phone'];
|
|
|
+ return [$params, $card_info];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function add($card_no, $card_type, $amount, $input, &$net_errno = 0)
|
|
|
+ {
|
|
|
+ $params = config::pub_params();
|
|
|
+ [$data, $card_info] = $this->req_params($card_no, $amount, $card_type, $input['order_sn']);
|
|
|
+ $params['reqData'] = json_encode($data);
|
|
|
+ $params['sign'] = config::sign($params);
|
|
|
+
|
|
|
+ $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 === 1) {
|
|
|
+ refill\util::inc_card($card_no,$card_info);
|
|
|
+ return [true, $resp['data']['businessOrderId'], false];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['msg'], false];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function query($refill_info)
|
|
|
+ {
|
|
|
+ $params = config::pub_params();
|
|
|
+
|
|
|
+ $data['orderId'] = $refill_info['order_sn'];
|
|
|
+ $data['businessId'] = 3;
|
|
|
+ $data['agentId'] = config::AGENT_ID;
|
|
|
+ $data['transactionPin'] = config::transactionPin;
|
|
|
+ $params['reqData'] = json_encode($data);
|
|
|
+ $params['sign'] = config::sign($params);
|
|
|
+
|
|
|
+ $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'] === 1)
|
|
|
+ {
|
|
|
+ $status = $resp['data']['orderStatus'];
|
|
|
+ if ($status === 3) {
|
|
|
+ $updata['official_sn'] = $resp['data']['ispVoucherId'];
|
|
|
+ Model('refill_order')->edit($refill_info['order_id'], $updata);
|
|
|
+ $order_state = ORDER_STATE_SUCCESS;
|
|
|
+ } elseif ($status === 99) {
|
|
|
+ $order_state = ORDER_STATE_CANCEL;
|
|
|
+ } elseif ($status === 1 || $status === 2) {
|
|
|
+ $order_state = ORDER_STATE_SEND;
|
|
|
+ } else {
|
|
|
+ return [false, $status];
|
|
|
+ }
|
|
|
+ return [true, $order_state];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return [false, $resp['msg']];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function balance()
|
|
|
+ {
|
|
|
+ $params = config::pub_params();
|
|
|
+
|
|
|
+ $data['agentId'] = config::AGENT_ID;
|
|
|
+ $data['transactionPin'] = config::transactionPin;
|
|
|
+ $params['reqData'] = json_encode($data);
|
|
|
+ $params['sign'] = config::sign($params);
|
|
|
+
|
|
|
+ $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'] === 1) {
|
|
|
+ return [true, $resp['data']['currentBalance']];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['msg']];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|