REAPI/app/channel/service/system/Xianbeiyi.php
2024-09-29 15:43:18 +08:00

206 lines
5.3 KiB
PHP

<?php
namespace app\channel\service\system;
/**
* xinqudao
* Class Tianjitong
* @package app\channel\service
*/
class Xianbeiyi extends Core
{
# 这几个可以后台设置
protected $host = 'host';
protected $mid = 'mid';
protected $token = 'token';
protected $api = 'api/order/submit';
protected $card_type = 1;
# 中石化油卡充值
public function dhcz($param)
{
$check = array
(
'mobile' => 'uuid',
'cash' => 'itemFace',
);
$this->card_type = 3;
if (isset($param['isp']) && $param['isp']) {
if ($param['isp'] == 1) {
$this->card_type = 3;
} elseif ($param['isp'] == 2) {
$this->card_type = 4;
} elseif ($param['isp'] == 3) {
$this->card_type = 5;
}
}
return $this->submit($param, $check);
}
# 中石油油卡充值 拼音来吧
public function zsycz($param)
{
$check = array
(
'card' => 'uuid',
'cash' => 'itemFace',
'mobile' => 'ext1',
'idCard' => 'ext2',
'realName' => 'ext3',
);
$this->card_type = 2;
return $this->submit($param, $check);
}
# 中石化油卡充值
public function zshcz($param)
{
$check = array
(
'card' => 'uuid',
'cash' => 'itemFace',
);
$this->card_type = 1;
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data;
unset($request['sign']);
unset($request['s_order']);
$request['appSecret'] = $this->token;
$sign = $this->sign($request, 'md5');
if ($sign != $data['sign']) {
return false;
}
$result = array();
$result['cash'] = 1;
if ($data['orderStatus'] == 2) {
$result['status'] = 2;
} elseif ($data['orderStatus'] == 3) {
$result['status'] = 3;
} else {
$result['status'] = 4;
}
$result['yes'] = 'ok';
$result['data'] = $data;
return $result;
}
# 数据响应格式处理
public function response($data)
{
$log['type'] = 'response';
$log['data'] = $data;
$log['config'] = $this->data;
$this->log($log);
$array = $this->json_decode($data);
if (!$array) {
$msg = 'error';
} elseif (isset($array['code']) && $array['code'] == '00') {
# 正确
$msg = 'ok';
} else {
# 错误
$msg = $array['msg'];
}
return array
(
'msg' => $msg,
'data' => $data,
'array' => $array,
);
}
# 查询接口
public function query($param)
{
}
# 提交数据
private function submit($param, $check)
{
$param = $this->param($param, $check);
if (is_string($param) || (is_array($param) && $param['status'] == 1)) {
return $param;
}
$request = $param['detail'];
$request['appId'] = $this->mid;
$request['outOrderId'] = $param['order'];
$request['itemId'] = $this->getCode($param['cash']);
if (!$request['itemId']) {
return 'order';
}
$request['timestamp'] = date('YmdHisu');
$request['callbackUrl'] = $this->getNotify($param['order'], 1);
$request['appSecret'] = $this->token;
$url = $this->host . $this->api;
$request['sign'] = $this->sign($request, 'md5');
$response = $this->curl('post', $url, $request);
$response = $this->response($response);
$channel_order_id = '';
if (isset($response['array']['orderId'])) {
$channel_order_id = $response['array']['orderId'];
}
$this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']);
return $response['msg'];
}
private function getCode($cash)
{
if ($this->card_type == 1) {
if ($cash == 100) {
return 100005;
} elseif ($cash == 200) {
return 100006;
} elseif ($cash == 500) {
return 100007;
} elseif ($cash == 1000) {
return 100008;
}
} elseif ($this->card_type == 2) {
if ($cash == 500) {
return 100001;
} elseif ($cash == 1000) {
return 100002;
} elseif ($cash == 2000) {
return 100003;
}
} elseif ($this->card_type == 3) {
if ($cash == 50) {
return 100145;
} elseif ($cash == 100) {
return 100146;
}
} elseif ($this->card_type == 4) {
if ($cash == 50) {
return 100147;
} elseif ($cash == 100) {
return 100148;
}
} elseif ($this->card_type == 5) {
if ($cash == 50) {
return 100149;
} elseif ($cash == 100) {
return 100150;
}
}
return false;
}
}