REAPI/app/channel/service/system/Tianjitong.php

171 lines
5.0 KiB
PHP
Raw Normal View History

2024-09-29 15:43:18 +08:00
<?php
namespace app\channel\service\system;
/**
* 天诚亿发服务新版本-天际通
* Class Tianjitong
* @package app\channel\service
*/
class Tianjitong extends Core
{
# 这几个可以后台设置
protected $host = 'http://oilcard.dh2hee.cn/';
protected $mid = '7514657800';
protected $token = '4n4zIGxBSpPYNLNaklC8NQ';
# 中石油油卡充值 拼音来吧
public function zsycz($param)
{
$check = array
(
'card' => 'cardno',
'cash' => 'amt',
'cardtype' => 'cardtype',
'storeid' => 'storeid',
//'mobile' => 'mobile',
'idCard' => 'idcard',
'realName' => 'cardusername',
);
$param['cardtype'] = 'PetroChina';
$param['storeid'] = $this->shop();
return $this->submit($param, $check);
}
# 中石化油卡充值
public function zshcz($param)
{
$check = array
(
'card' => 'cardno',
'cash' => 'amt',
'cardtype' => 'cardtype',
'storeid' => 'storeid',
);
$param['cardtype'] = 'Sinoepc';
$param['storeid'] = $this->shop();
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data;
unset($request['sign']);
unset($request['s_order']);
$sign = $this->sign($request, 'md5', '&key=' . $this->token);
if ($sign != $data['sign']) {
return false;
}
$result = array();
$result['cash'] = floatval($data['amt']);
if ($data['status'] == 2) {
$result['status'] = 2;
} else {
$result['status'] = 3;
}
$result['yes'] = 'SUCCESS';
/*
if (isset($data['jdno']) && $data['jdno']) {
# 流水号
$data['s_nubmer'] = $result['s_nubmer'] = $data['jdno'];
} elseif (isset($data['pddno']) && $data['pddno']) {
# 流水号
$data['s_nubmer'] = $result['s_nubmer'] = $data['pddno'];
} elseif (isset($data['tbno']) && $data['tbno']) {
# 流水号
$data['s_nubmer'] = $result['s_nubmer'] = $data['tbno'];
} elseif (isset($data['channelno']) && $data['channelno']) {
# 流水号
$data['s_nubmer'] = $result['s_nubmer'] = $data['channelno'];
}
*/
$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['state']) && $array['state'] == 0 && isset($array['data']) && $array['data']) {
# 正确
$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'];
if (!$request['storeid']) {
unset($request['storeid']);
}
$request['channelsort'] = 'OIL_CARD';
$request['orgid'] = $this->mid;
$request['onlystr'] = $param['order'];
$request['notifyurl'] = $this->getNotify($param['order'], 1);
if (strstr($this->host, 'tm')) {
$request['channel'] = 'TM';
} elseif (strstr($this->host, 'jd')) {
$request['channel'] = 'JD';
} elseif (strstr($this->host, 'pdd')) {
$request['channel'] = 'PDD';
} elseif (strstr($this->host, 'wx')) {
$request['channel'] = 'WX';
} elseif (strstr($this->host, 'sn')) {
$request['channel'] = 'SN';
} else {
}
$array = parse_url($this->host);
$this->host = $array['scheme'] . '://' . $array['host'];
$url = $this->host . '/order/createOrder.html';
$request['sign'] = $this->sign($request, 'md5', '&key=' . $this->token);
$response = $this->curl('post', $url, $request);
$response = $this->response($response);
//$response['data'] = '';
//$response['msg'] = 'ok';
$channel_order_id = '';
if (isset($response['array']['data'])) {
$channel_order_id = $response['array']['data'];
}
$this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']);
return $response['msg'];
}
}