2024-09-29 15:43:18 +08:00

189 lines
4.9 KiB
PHP

<?php
namespace app\channel\service\system;
/**
* 服务
* Class Bodingcheng
* @package app\channel\service
*/
class Liu extends Core
{
# 这几个可以后台设置
protected $host = 'host';
protected $mid = 'mid';
protected $token = 'token';
protected $api = 'api/supplier/submit';
# 通用的充值
public function common($param)
{
$check = array
(
'account' => 'account_no',
'cash' => 'amount',
'order_type' => 'order_type',
);
$param['order_type'] = 'dy';
return $this->submit($param, $check);
}
# 抖音充值
public function dy($param)
{
$check = array
(
'account' => 'account_no',
'cash' => 'amount',
'order_type' => 'order_type',
);
$param['order_type'] = 'dy';
return $this->submit($param, $check);
}
# 手机充值
public function dhcz($param)
{
$check = array
(
'account' => 'account_no',
'cash' => 'amount',
'order_type' => 'order_type',
);
$param['order_type'] = 'dy';
return $this->submit($param, $check);
}
# 中石油充值
public function zsycz($param)
{
$check = array
(
'account' => 'account_no',
'cash' => 'amount',
'order_type' => 'order_type',
);
$param['order_type'] = 'dy';
return $this->submit($param, $check);
}
# 中石化油卡充值
public function zshcz($param)
{
$check = array
(
'account' => 'account_no',
'cash' => 'amount',
'order_type' => 'order_type',
);
$param['order_type'] = 'dy';
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data['data'];
$sign = $this->_sign($request, array('account_no', 'amount', 'out_order_no', 'order_type', 'pay_status', 'notify_url'));
if ($sign != $request['sign']) {
return false;
}
$result = array();
$result['cash'] = 1;
if ($request['pay_status'] == '2') {
$result['status'] = 2;
} elseif ($request['pay_status'] == '3') {
$result['status'] = 3;
} else {
$result['status'] = 4;
}
if (isset($request['platform_order_no']) && $request['platform_order_no'] && $request['platform_order_no'] != '无') {
# 流水号
$data['s_nubmer'] = $result['s_nubmer'] = $request['platform_order_no'];
}
$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'] == '200') {
# 正确
$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;
}
$request = $param['detail'];
$request['user_name'] = $this->mid;
$request['out_order_no'] = $param['order'];
$request['szVerifyString'] = $this->_sign($request, array('user_name', 'out_order_no', 'amount', 'account_no', 'order_type', 'notify_url'));
$request['notify_url'] = $this->getNotify($param['order'], 1);
$url = $this->host . $this->api;
$response = $this->curl('post', $url, $request);
$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']);
return $response['msg'];
}
private function _sign($request, $param)
{
//ksort($request);
$signature_string = '';
foreach ($param as $k => $v) {
if (isset($request[$v])) {
$signature_string .= $v;
}
}
$signature_string .= '' . $this->token;
return md5($signature_string);
}
}