|
@@ -0,0 +1,104 @@
|
|
|
+<?php
|
|
|
+namespace refill\juzhuo;
|
|
|
+
|
|
|
+require_once(BASE_HELPER_RAPI_PATH . '/juzhuo/config.php');
|
|
|
+
|
|
|
+use refill;
|
|
|
+
|
|
|
+use Log;
|
|
|
+
|
|
|
+class RefillOil extends refill\IRefillOil
|
|
|
+{
|
|
|
+ public function __construct($cfgs)
|
|
|
+ {
|
|
|
+ parent::__construct($cfgs);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function req_params(string $card_no,int $card_type,int $amount,array $other)
|
|
|
+ {
|
|
|
+ $params['channelsort'] = 'OIL_CARD';
|
|
|
+ $params['cardtype'] = config::operator[$card_type];
|
|
|
+ $params['orgid'] = config::ORGID;
|
|
|
+ $params['amt'] = $amount;
|
|
|
+ $params['notifyurl'] = config::NOTIFY_URL;
|
|
|
+ $params['onlystr'] = $other['order_sn'];
|
|
|
+ $params['cardno'] = $card_no;
|
|
|
+ return $params;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function sign($params)
|
|
|
+ {
|
|
|
+ $content = '';
|
|
|
+ ksort($params);
|
|
|
+ foreach ($params as $key => $val){
|
|
|
+ if(false === $this->check_empty($val)) {
|
|
|
+ $content .= "{$key}={$val}&";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $content .= "key=".config::KEY;
|
|
|
+
|
|
|
+ return md5($content);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function add($card_no,$card_type,$amount,$input)
|
|
|
+ {
|
|
|
+ $params = $this->req_params($card_no,$card_type,$amount,$input);
|
|
|
+ $sign = $this->sign($params);
|
|
|
+ $params['sign'] = $sign;
|
|
|
+
|
|
|
+ $resp = http_request(config::ORDER_URL,$params,'POST',false, config::ExtHeaders);
|
|
|
+ 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['state'] == 0) {
|
|
|
+ return [true, $resp['data'], false];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['msg'], false];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function query($refill_info)
|
|
|
+ {
|
|
|
+ $params['orgid'] = config::ORGID;
|
|
|
+ $params['onlystr'] = $refill_info['order_sn'];
|
|
|
+ $sign = $this->sign($params);
|
|
|
+ $params['sign'] = $sign;
|
|
|
+
|
|
|
+ $resp = http_request(config::ORDER_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['state'] == 0)
|
|
|
+ {
|
|
|
+ $status = $resp['data']['status'];
|
|
|
+ if ($status == 2) {
|
|
|
+ $order_state = ORDER_STATE_SUCCESS;
|
|
|
+ } elseif ($status == 3) {
|
|
|
+ $order_state = ORDER_STATE_CANCEL;
|
|
|
+ } elseif ($status == 0){
|
|
|
+ $order_state = ORDER_STATE_SEND;
|
|
|
+ } else {
|
|
|
+ return [false, $status];
|
|
|
+ }
|
|
|
+ return [true, $order_state];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return [false,$resp['msg']];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|