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

192 lines
4.9 KiB
PHP

<?php
namespace app\channel\service\system;
/**
* 服务
* Class Tiancheng
* @package app\channel\service
*/
class Fzd extends Core
{
# 这几个可以后台设置
protected $host = '';
protected $mid = '';
protected $token = '';
protected $api = '';
# 通用的充值
public function common($param)
{
$check = array
(
'account' => 'target',
'cash' => 'amount',
);
$this->api = 'api/merchant/upload_order';
$this->method = 'post';
return $this->submit($param, $check);
}
# 话费充值
public function dhcz($param)
{
$check = array
(
'mobile' => 'target',
'cash' => 'amount',
);
$this->api = 'api/merchant/upload_order';
$this->method = 'post';
return $this->submit($param, $check);
}
# 中石化油卡充值
public function zshcz($param)
{
$check = array
(
'card' => 'target',
'cash' => 'amount',
);
$this->api = 'api/merchant/upload_order';
$this->method = 'post';
return $this->submit($param, $check);
}
# 中石油
public function zsycz($param)
{
$check = array
(
'card' => 'target',
'cash' => 'amount',
);
$this->api = 'api/merchant/upload_order';
$this->method = 'post';
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data;
$result = array();
$result['cash'] = 1;
if ($data['state'] == 3) {
$result['status'] = 2;
} elseif ($data['state'] == 4) {
$result['status'] = 3;
} else {
$result['status'] = 4;
}
if (isset($data['voucher']) && $data['voucher']) {
# 流水号
$data['s_nubmer'] = $result['s_nubmer'] = $data['voucher'];
}
if (isset($data['info']) && $data['info']) {
$data['msg'] = $result['msg'] = $data['info'];
}
$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['ret']) && $array['ret'] == '0') {
# 正确
$msg = 'ok';
} else {
# 错误
$msg = isset($array['msg']) ? $array['msg'] : 'error';
}
return array
(
'msg' => $msg,
'data' => $array,
'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['app_key'] = $this->mid;
$request['third_id'] = $param['order'];
$request['biz_no'] = $this->getGid($param['cash']);
$request['num'] = 1;
$request['timestamp'] = time();
$request['call_back_url'] = $this->getNotify($param['order'], 1);
$request['sign'] = $this->_sign($request);
$url = $this->host . $this->api;
$response = $this->curl($this->method, $url, $request);
$response = $this->response($response);
$channel_order_id = '';
if (isset($response['array']['data']['order_id'])) {
$channel_order_id = $response['array']['data']['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)
{
ksort($request);
$signature_string = '';
foreach ($request as $k => $v) {
if ($v) {
//$v = urlencode($v);
$signature_string .= $k . $v;
}
}
$signature_string .= $this->token;
return md5($signature_string);
}
//敏感信息加密方法
function aes_encrypt($data)
{
$key = substr(md5($this->app_secret), 0, 16);
return base64_encode(openssl_encrypt($data, "AES-128-CBC", $key, TRUE, "0102030405060708"));
}
//敏感信息解密算法
function aes_decrypt($data)
{
$key = substr(md5($this->app_secret), 0, 16);
return openssl_decrypt(base64_decode($data), "AES-128-CBC", $key, TRUE, "0102030405060708");
}
}