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

180 lines
4.8 KiB
PHP

<?php
namespace app\channel\service\system;
/**
* 服务
* Class Bodingcheng
* @package app\channel\service
*/
class Mcreate extends Core
{
# 这几个可以后台设置
protected $host = '';
protected $mid = '';
protected $token = '';
protected $api = '';
protected $mtype = 1;
# 中石化油卡充值
public function zsycz($param)
{
$check = array
(
'card' => 'mobile',
'cash' => 'chargeCash',
'chargeType' => 'chargeType',
);
$param['chargeType'] = 4;
$this->api = 'Api/charge_ver2.php';
$this->mtype = 2;
return $this->submit($param, $check);
}
# 中石化油卡充值
public function zshcz($param)
{
$check = array
(
'card' => 'mobile',
'cash' => 'chargeCash',
'chargeType' => 'chargeType',
);
$param['chargeType'] = 4;
$this->api = 'Api/charge_ver2.php';
$this->mtype = 1;
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data;
$sign = $this->_sign($request, array('orderId', 'status'));
if ($sign != $data['sign']) {
return false;
}
$result = array();
$result['cash'] = 1;
if ($data['status'] == 16) {
$result['status'] = 2;
} elseif ($data['status'] == 26) {
$result['status'] = 3;
} else {
$result['status'] = 4;
}
if (isset($data['officialOrderId']) && $data['officialOrderId'] && $data['officialOrderId'] != 'null') {
# 流水号
$data['s_nubmer'] = $result['s_nubmer'] = $data['officialOrderId'];
}
$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'] == '10000') {
# 正确
$msg = 'ok';
} else {
# 错误
$msg = isset($array['errorMsg']) ? $array['errorMsg'] : '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['act'] = 'Charge';
$request['uid'] = $this->mid;
$request['orderId'] = $param['order'];
$request['cpid'] = $this->getCode($param['cash']);
if (!$request['cpid']) {
return 'order';
}
$request['returnUrl'] = $this->getNotify($param['order'], 1);
$request['sign'] = $this->_sign($request, array('act', 'uid', 'orderId', 'mobile', 'chargeCash', 'chargeType'));
$url = $this->host . $this->api;
$response = $this->curl('get', $url, $request);
$response = $this->response($response);
$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 getCode($cash)
{
if ($this->mtype == 1) {
if ($cash == 500) {
return 132;
} elseif ($cash == 1000) {
return 133;
} elseif ($cash == 3000) {
return 345;
} elseif ($cash == 5000) {
return 346;
}
} else {
if ($cash == 500) {
return 137;
} elseif ($cash == 1000) {
return 138;
} elseif ($cash == 3000) {
return 347;
} elseif ($cash == 5000) {
return 348;
}
}
return false;
}
private function _sign($request, $param)
{
//ksort($request);
$signature_string = '';
foreach ($param as $k => $v) {
if (isset($request[$v]) && $request[$v]) {
//$signature_string .= $v . '=' . $request[$v] . '&';
$signature_string .= $request[$v];
}
}
//$signature_string = substr($signature_string, 0, -1);
$signature_string .= $this->token;
return md5($signature_string);
}
}