123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- <?php
- namespace refill\gftd;
- require_once(BASE_HELPER_RAPI_PATH . '/gftd/config.php');
- use refill;
- use mtopcard;
- 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['appid'] = config::APP_ID;
- $params['ts'] = time();
- $params['productId'] = $this->product_id($amount,$card_type);
- $params['outOrderNumber'] = $other['order_sn'];
- $params['fuelCardNumber'] = $card_no;
- $params['fuelCardUserName'] = "";
- $params['fuelCardUserID'] = "";
- $card_info = refill\util::read_card($card_no,$card_type);
- $params['telephone'] = $card_info['bind_phone'];
- $params['phoneNumber'] = $card_info['bind_phone'];
- return [$params, $card_info];
- }
- private function product_id(int $amount,int $cart_type)
- {
- if($cart_type === mtopcard\PetroChinaCard)
- {
- switch ($amount) {
- case 100: return 1;
- case 200: return 2;
- case 500: return 3;
- case 1000: return 4;
- }
- }
- else
- {
- switch ($amount) {
- case 100: return 5;
- case 200: return 6;
- case 500: return 7;
- case 1000: return 8;
- }
- }
- return false;
- }
- private function sign($params)
- {
- $body = $this->body($params);
- $body .= config::APP_SECRET;
- return md5($body);
- }
- protected function check_empty($value)
- {
- if (!isset($value))
- return true;
- if ($value === null)
- return true;
- if (trim($value) === "")
- return true;
- return false;
- }
- private function body($params)
- {
- ksort($params);
- $body = "";
- $i = 0;
- foreach ($params as $k => $v)
- {
- if (false === $this->check_empty($v) && "@" != substr($v, 0, 1))
- {
- if ($i == 0) {
- $body .= "{$k}" . "=" . $v;
- } else {
- $body .= "&" . "{$k}" . "=" . $v;
- }
- $i++;
- }
- }
- return $body;
- }
- public function add($card_no,$card_type,$amount,$input,&$net_errno = 0)
- {
- refill\util::send_normal($params['order_sn']);
- return [true , '',false];
- }
- private function query_params($order_sn)
- {
- $params['appid'] = config::APP_ID;
- $params['ts'] = time();
- $params['outOrderNumber'] = $order_sn;
- return $params;
- }
- public function query($refill_info)
- {
- $order_sn = $refill_info['order_sn'];
- $order_id = $refill_info['order_id'];
- $params = $this->query_params($order_sn);
- $sign = $this->sign($params);
- $params['signature'] = $sign;
- $uri = config::ORDER_URL . "/fuelRecharge/order/detail";
- $resp = http_post_data($uri,json_encode($params), config::ExtHeaders);
- Log::record("query resp={$resp}",Log::DEBUG);
- if(empty($resp)) {
- return [false,'网络错误'];
- }
- Log::record($resp,Log::DEBUG);
- $resp = json_decode($resp,true);
- if(empty($resp)) {
- return [false,'网络错误'];
- }
- elseif($resp['code'] == 0)
- {
- $data = $resp['data'];
- $status = intval($data['orderStatus']);
- if ($status === 101) {
- $updata['official_sn'] = $data['voucher'];
- $updata['ch_trade_no'] = $data['orderNumber'];
- $updata['err_msg'] = $resp['message'];
- Model('refill_order')->edit($order_id, $updata);
- return [true, ORDER_STATE_SUCCESS];
- }
- elseif ($status === 102) {
- $updata['official_sn'] = $data['voucher'];
- $updata['ch_trade_no'] = $data['orderNumber'];
- $updata['err_msg'] = $resp['message'];
- Model('refill_order')->edit($order_id, $updata);
- $this->onError($resp['message'],$order_id);
- return [true, ORDER_STATE_CANCEL];
- }
- elseif($status === 100 || $status === 106) {
- return [true, ORDER_STATE_SEND];
- }
- else {
- return [false, $resp['message']];
- }
- }
- else {
- return [false,$resp['message']];
- }
- }
- public function onError($msg,$order_id)
- {
- if(in_array($msg,config::BlackMsgs))
- {
- $refill = Model('refill_order');
- $order = $refill->getOrderInfo(['order_id' => $order_id]);
- if(empty($order)) return false;
- $card_no = $order['card_no'];
- if(!empty($card_no)) {
- refill\util::set_black($card_no);
- return true;
- }
- }
- return false;
- }
- public function balance()
- {
- return [false, '暂无余额接口'];
- }
- }
|