123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- namespace refill\xinsj;
- require_once(BASE_HELPER_RAPI_PATH . '/xinsj/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['fuelCardNumber'] = $card_no;
- $params['outOrderNumber'] = $order_sn;
- $params['productId'] = config::getProduct($card_type, $amount);
- $params['actualAmount'] = $amount;
- return $params;
- }
- private function req_headers($sign)
- {
- $appId = config::APPID;
- $time = time();
- return [
- 'Content-Type: application/json',
- "appId: {$appId}",
- "requestTime: {$time}",
- "signature: {$sign}",
- ];
- }
- public function add($card_no, $card_type,$amount,$input,&$net_errno = 0)
- {
- $order_sn = $input['order_sn'];
- $params = $this->req_params($card_no,$card_type,$amount,$order_sn);
- if(empty($params['productId'])) {
- return [false,"上游{$this->name()}产品不支持:{$card_type}-{$amount}",true];
- }
- $sign = $this->sign($params);
- $header = $this->req_headers($sign);
- $data['data'] = $params;
- $post_data = json_encode($data);
- $resp = http_post_data(config::ORDER_URL,$post_data,$header,$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['code'] == 1005) {
- return [true, $resp['orderNumber'], false];
- } else {
- return [false, $resp['message'], 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()
- {
- return [false, '暂无余额接口'];
- }
- private function sign($input)
- {
- $key = config::APPKEY;
- $body = config::body($input);
- $body .= $key;
- return strtolower(md5($body));
- }
- }
|