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

163 lines
4.7 KiB
PHP
Raw Normal View History

2024-09-29 15:43:18 +08:00
<?php
namespace app\channel\service\system;
/**
* 汇天下服务
* Class Tiancheng
* @package app\channel\service
*/
class Huitianxia extends Core
{
# 这几个可以后台设置
protected $host = 'http://bank.daoken.club/';
protected $mid = '1367893433324477';
protected $token = 'xjtkhBWTYEcfMpyY7HzPHaJnsYD67hsQEwCKZzQNGh6HGj56WB';
protected $method = '';
# 中石油油卡充值 拼音来吧
public function zsycz($param)
{
$check = array
(
'card' => 'cardNo',
'cash' => 'amount',
);
$this->method = 'youka/trade/order';
return $this->submit($param, $check);
}
# 中石化油卡充值
public function zshcz($param)
{
$check = array
(
'card' => 'cardNo',
'cash' => 'amount',
);
$this->method = 'youka/trade/order';
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data;
unset($request['sign']);
unset($request['s_order']);
$sign = strtoupper($this->sign($request, 'md5', '&key=' . $this->token));
if ($sign != $data['sign']) {
return false;
}
$result = array();
//$result['data'] = json_encode($data, JSON_UNESCAPED_UNICODE);
$result['cash'] = 1;
if ($data['status'] == 1) {
$result['status'] = 2;
} else {
$result['status'] = 3;
}
if (isset($data['voucherNo']) && $data['voucherNo']) {
# 流水号
$data['s_nubmer'] = $result['s_nubmer'] = $data['voucherNo'];
}
$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'] == '0000' && isset($array['respCode']) && $array['respCode'] == '1111') {
# 正确
$msg = 'ok';
} else {
# 错误
$msg = isset($array['msg']) ? $array['msg'] : 'error';
}
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;
}
/*
if ($param['detail']['amount'] == 5000) {
# 拆单
# 定义拆单数
$num = 2;
$order = $param['order'];
$cash = $param['cash'];
$param['detail']['amount'] = $param['cash'] = $param['detail']['amount']/$num;
for($i = 1; $i <= $num; $i++) {
$param['order'] = $order . '_' . $i;
if ($i == 1) {
$this->send($param, $order);
} else {
$this->data['order'] = $param['order'];
$this->data['time'] = time() + 300;
$this->create($param['order'], '', $param['merchant_order'], $param['cash'], '', $this->data, array(), -1, $param['account'], $order);
}
}
# 当前订单定义为处理中
$response['data'] = '{}';
$response['msg'] = 'ok';
$this->create($order, '', $param['merchant_order'], $cash, '', '', $response, 1, $param['account']);
return $response['msg'];
} else {
return $this->send($param);
}
*/
return $this->send($param);
}
private function send($param, $parent_order = '')
{
$request = $param['detail'];
$request['mid'] = $this->mid;
$request['orderNum'] = $param['order'];
$request['backUrl'] = $this->getNotify($param['order'], 1);
$request['sign'] = strtoupper($this->sign($request, 'md5', '&key=' . $this->token));
$url = $this->host . $this->method;
$response = $this->curl('post', $url, $request, true);
$response = $this->response($response);
//$response['data'] = '{}';
//$response['msg'] = 'ok';
$channel_order_id = '';
$this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account'], $parent_order);
return $response['msg'];
}
}