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

211 lines
5.3 KiB
PHP

<?php
namespace app\channel\service\system;
/**
* 服务
* Class Bodingcheng
* @package app\channel\service
*/
class Maihan extends Core
{
# 这几个可以后台设置
protected $host = 'http://121.196.120.203/';
protected $mid = '65554';
protected $token = '880eabcd7ab680858';
protected $type = 4;
# 电话充值
public function hdcz($param)
{
$check = array
(
'card' => 'mobile',
'cash' => 'amount',
'op' => 'op',
);
$this->type = 1;
$param['op'] = 1;
if (isset($param['isp']) && $param['isp']) {
$param['op'] = $param['isp'];
}
return $this->submit($param, $check);
}
# 中石油油卡充值 拼音来吧
public function zsycz($param)
{
$check = array
(
'card' => 'mobile',
'cash' => 'amount',
'op' => 'op',
);
$this->type = 4;
$param['op'] = 4;
return $this->submit($param, $check);
}
# 中石化油卡充值
public function zshcz($param)
{
$check = array
(
'card' => 'mobile',
'cash' => 'amount',
'op' => 'op',
);
$this->type = 4;
$param['op'] = 5;
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data;
unset($request['sign']);
unset($request['s_order']);
$sign = $this->_sign($request);
if ($sign != $data['sign']) {
return false;
}
$result = array();
$result['cash'] = 1;
if ($data['status'] == 'success') {
$result['status'] = 2;
} elseif ($data['status'] == 'failed') {
$result['status'] = 3;
} else {
$result['status'] = 5;
}
if (isset($data['sz_order_no']) && $data['sz_order_no']) {
# 流水号
$data['s_nubmer'] = $result['s_nubmer'] = $data['sz_order_no'];
}
$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['status']) && $array['status'] == '0' && isset($array['msg']) && $array['msg'] == 'success') {
# 正确
$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['type'] = $this->type;
$request['cpid'] = $this->mid;
$request['ret_para'] = $param['order'];
$request['create_time'] = date('YmdHis');
$request['product_id'] = $this->getProduct($request['op'], $request['amount']);
if (!$request['product_id']) {
return 'order';
}
$request['sign'] = $this->_sign($request);
$url = $this->host . 'api/do';
$response = $this->curl('get', $url, $request);
$response = $this->response($response);
//$response['data'] = '';
//$response['msg'] = 'ok';
$channel_order_id = '';
if (isset($response['array']['order_no'])) {
$channel_order_id = $response['array']['order_no'];
}
$this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']);
return $response['msg'];
}
# 获取产品id
private function getProduct($type, $cash)
{
if ($type == 5) {
if ($cash == 100) {
return 20031;
}
if ($cash == 200) {
return 20032;
}
if ($cash == 500) {
return 20033;
}
if ($cash == 1000) {
return 20034;
}
}
if ($type == 4) {
if ($cash == 100) {
return 20035;
}
if ($cash == 200) {
return 20036;
}
if ($cash == 500) {
return 20037;
}
if ($cash == 1000) {
return 20038;
}
}
if ($type == 1) {
if ($cash == 1000) {
return 0000;
}
}
return 0000;
}
private function _sign($request)
{
ksort($request);
$signature_string = '';
foreach ($request as $k => $v) {
$signature_string .= $k . $v;
}
$signature_string .= $this->token;
return md5($signature_string);
}
}