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

194 lines
5.0 KiB
PHP

<?php
namespace app\channel\service\system;
/**
* 话费服务
* Class Common
* @package app\channel\service
*/
class Ronghe extends Core
{
# 这几个可以后台设置
protected $host = 'host';
protected $mid = 'mid';
protected $token = 'token';
protected $api = 'api';
# 通用的充值
public function common($param)
{
$check = array
(
'account' => 'mobile',
'cash' => 'amount',
);
$this->api = 'supply/order/orderCheck';
$this->orderType = 1;
$this->businessType = 3;
return $this->submit($param, $check);
}
# 电话充值
public function dhcz($param)
{
$check = array
(
'mobile' => 'mobile',
'cash' => 'amount',
);
$this->api = 'supply/order/orderCheck';
$this->orderType = 1;
$this->businessType = 1;
return $this->submit($param, $check);
}
# 中石化油卡充值
public function zshcz($param)
{
$check = array
(
'card' => 'mobile',
'cash' => 'amount',
);
$this->api = 'supply/order/orderCheck';
$this->orderType = 2;
$this->businessType = 2;
return $this->submit($param, $check);
}
# 抖音充值
public function dycz($param)
{
$check = array
(
'account' => 'mobile',
'cash' => 'amount',
);
$this->api = 'supply/order/orderCheck';
$this->orderType = 1;
$this->businessType = 3;
return $this->submit($param, $check);
}
# 电费充值
public function dfcz($param)
{
$check = array
(
'account' => 'mobile',
'cash' => 'amount',
);
$this->api = 'supply/order/orderCheck';
$this->orderType = 1;
$this->businessType = 4;
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$result = array();
$result['cash'] = 1;
if ($data['code'] == 200) {
$result['status'] = 2;
} else {
$result['status'] = 3;
}
if (isset($data['tradeNo']) && $data['tradeNo']) {
# 流水号
$data['s_nubmer'] = $result['s_nubmer'] = $data['tradeNo'];
}
$result['yes'] = 'success';
$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['amount'] = number_format($request['amount'], 2);
$request['merchantId'] = $this->mid;
$request['businessType'] = $this->businessType;
$request['orderType'] = $this->orderType;
$request['tradeNoThird'] = $param['order'];
$request['createTime'] = date('Y-m-d H:i:s');
$request['notifyUrl'] = $this->getNotify($param['order'], 1);
//merchantId + orderType + mobile + tradeNoThird + amount + notifyUrl + timeout + businessType + operator + key
$request['signstr'] = $this->_sign($request, array('merchantId', 'orderType', 'mobile', 'tradeNoThird', 'amount', 'notifyUrl', 'businessType'));
$url = $this->host . $this->api;
$response = $this->curl('post', $url, $request);
$response = $this->response($response);
$channel_order_id = '';
if (isset($response['array']['body']['tradeNoSelf'])) {
$channel_order_id = $response['array']['body']['tradeNoSelf'];
}
$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)
{
$signature_string = '';
foreach ($param as $k => $v) {
if (isset($request[$v]) && $request[$v]) {
$signature_string .= $request[$v];
}
}
$signature_string .= $this->token;
return md5($signature_string);
}
}