|
@@ -0,0 +1,126 @@
|
|
|
+<?php
|
|
|
+namespace refill\feinimoshu;
|
|
|
+
|
|
|
+require_once(BASE_HELPER_RAPI_PATH . '/feinimoshu/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 $card_type, int $amount, string $order_sn)
|
|
|
+ {
|
|
|
+ $params['appid'] = config::APPID;
|
|
|
+ $params['notify'] = config::NOTIFY_URL;
|
|
|
+ $params['card'] = $card_no;
|
|
|
+ $params['order'] = $order_sn;
|
|
|
+
|
|
|
+ $producd = config::getProduct($card_type, $amount);
|
|
|
+ if ($producd == false) {
|
|
|
+ Log::record("找不到合适的产品",Log::ERR);
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ $params['proid'] = $producd;
|
|
|
+ return $params;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function add($card_no, $card_type,$amount,$input)
|
|
|
+ {
|
|
|
+ $order_sn = $input['order_sn'];
|
|
|
+ $params = $this->req_params($card_no,$card_type,$amount,$order_sn);
|
|
|
+ if(empty($params)) {
|
|
|
+ return [false,"上游{$this->name()}产品不支持:{$card_type}-{$amount}",true];
|
|
|
+ }
|
|
|
+
|
|
|
+ $sign = $this->sign($params);
|
|
|
+ $params['signature'] = $sign;
|
|
|
+
|
|
|
+ $resp = http_request(config::ORDER_URL,$params,'GET');
|
|
|
+ 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'] == 1) {
|
|
|
+ return [true, $resp['data']['order'], false];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['info'], false];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function query($refill_info)
|
|
|
+ {
|
|
|
+ $params['appid'] = config::APPID;
|
|
|
+ $params['morder'] = $refill_info['order_sn'];
|
|
|
+ $sign = $this->sign($params);
|
|
|
+ $params['signature'] = $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, '返回值错误'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $code = intval($resp['code']);
|
|
|
+ $status = intval($resp['data']['status']);
|
|
|
+
|
|
|
+ if ($code != 1) {
|
|
|
+ return [false, $resp['info']];
|
|
|
+ } elseif ($status == 2) {
|
|
|
+ $order_state = ORDER_STATE_SUCCESS;
|
|
|
+ $data['official_sn'] = strtolower($params['vnum']) == 'null' ? '' : $params['vnum'];
|
|
|
+ Model('refill_order')->edit($refill_info['order_id'], $data);
|
|
|
+ } elseif ($status == 3) {
|
|
|
+ $order_state = ORDER_STATE_CANCEL;
|
|
|
+ } else {
|
|
|
+ $order_state = ORDER_STATE_SEND;
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, $order_state];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function balance()
|
|
|
+ {
|
|
|
+ $params['appid'] = config::APPID;
|
|
|
+ $sign = $this->sign($params);
|
|
|
+ $params['signature'] = $sign;
|
|
|
+
|
|
|
+ $resp = http_request(config::QUERY_URL,$params);
|
|
|
+ if($resp === false) {
|
|
|
+ return [false,'系统错误'];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function sign($input)
|
|
|
+ {
|
|
|
+ $key = config::APPKEY;
|
|
|
+ $body = config::body($input);
|
|
|
+ $body .= "&token={$key}";
|
|
|
+
|
|
|
+ return strtolower(md5($body));
|
|
|
+ }
|
|
|
+}
|