123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- namespace refill\shengchuang;
- require_once(BASE_HELPER_RAPI_PATH . '/shengchuang/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 $amount, array $other)
- {
- $params['userId'] = config::userId;
- $params['commoditySellId'] = config::commoditySellId;
- $params['buyNum'] = $amount;
- $params['shopOrderId'] = $other['order_sn'];
- $params['json'] =json_encode(['sOilId'=>$card_no]);
- $params['notifyUrl'] = config::NOTIFY_URL;
- return $params;
- }
- private function sign($params)
- {
- $content = '';
- $key = config::APP_KEY;
- ksort($params);
- $i = 0;
- foreach ($params as $k => $v)
- {
- if (false === $this->check_empty($v) && "@" != substr($v, 0, 1))
- {
- if ($i == 0) {
- $content .= "{$k}" . "=" . $v;
- } else {
- $content .= "&" . "{$k}" . "=" . $v;
- }
- $i++;
- }
- }
- $content .= md5($key);
- return md5($content);
- }
- public function add($card_no, $card_type, $amount, $input,&$net_errno = 0)
- {
- $params = $this->req_params($card_no, $amount, $input);
- $sign = $this->sign($params);
- $params['sign'] = $sign;
- $resp = http_request(config::ORDER_URL, $params, 'POST', false, config::ExtHeaders, $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'] == 0) {
- return [true, $resp['data']['platformId'], false];
- } else {
- return [false, $resp['message'], false];
- }
- }
- }
- public function query($refill_info)
- {
- $params['orderId'] = $refill_info['order_sn'];
- $params['userId'] = config::userId;
- $params['sign'] = $this->sign($params);
- $resp = http_request(config::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 (in_array($status, [12,16])) {
- $order_state = ORDER_STATE_SUCCESS;
- } elseif ($status == 13) {
- $order_state = ORDER_STATE_CANCEL;
- } elseif ($resp['data']['status'] == 0){
- $order_state = ORDER_STATE_SEND;
- } else {
- return [false, $resp['statusDesc']];
- }
- return [true, $order_state];
- }
- else {
- return [false, $resp['message']];
- }
- }
- }
- public function balance()
- {
- return [false, '暂无余额接口'];
- }
- }
|