REAPI/app/channel/service/system/Huachuang.php
2024-09-29 15:43:18 +08:00

186 lines
5.3 KiB
PHP

<?php
namespace app\channel\service\system;
/**
* 服务
* Class Bodingcheng
* @package app\channel\service
*/
class Huachuang extends Core
{
# 这几个可以后台设置
protected $host = 'host';
protected $mid = 'mid';
protected $token = 'token';
protected $api = 'api';
protected $card_type = 1;
# 中石化油卡充值
public function dhcz($param)
{
$check = array
(
'mobile' => 'uid',
'cash' => 'facePrice',
'amt' => 'amt',
);
$param['amt'] = 1;
$this->api = 'api/directaync/buy';
$this->card_type = 3;
if (isset($param['isp']) && $param['isp']) {
if ($param['isp'] == 1) {
$this->card_type = 3;
} elseif ($param['isp'] == 2) {
$this->card_type = 4;
} elseif ($param['isp'] == 3) {
$this->card_type = 5;
}
}
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data;
$sign = $this->_sign($request);
if ($sign != $data['sign']) {
//return false;
}
$result = array();
$result['cash'] = 1;
$result['status'] = 4;
if ($data['status'] == 4) {
$result['status'] = 2;
} elseif ($data['status'] == 5) {
$result['status'] = 3;
}
if (isset($data['voucher']) && $data['voucher']) {
# 流水号
$data['s_nubmer'] = $result['s_nubmer'] = $data['voucher'];
}
$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'] == '00') {
# 正确
$msg = 'ok';
} else {
# 错误
$msg = isset($array['desc']) ? $array['desc'] : 'error';
}
return array
(
'msg' => $msg,
'data' => $data,
'array' => $array,
);
}
# 主动查询接口
public function query($order)
{
}
# 提交数据
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['facePrice'] = $request['facePrice'] * 1000;
$request['userId'] = $this->mid;
$request['productCode'] = 1;
$request['serialno'] = $param['order'];
$request['dtCreate'] = date('Ymdhis');
$request['productCode'] = $this->getCode($param['cash']);
if (!$request['productCode']) {
return 'order';
}
//array('dtCreate', 'facePrice', 'productCode','serialno', 'uid', 'userId')
$request['sign'] = $this->_sign($request);
$url = $this->host . $this->api;
$response = $this->curl('post', $url, $request);
$response = $this->response($response);
$channel_order_id = '';
if (isset($response['array']['bizOrderId']) && $response['array']['bizOrderId']) {
$channel_order_id = $response['array']['bizOrderId'];
}
$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) {
$signature_string .= $v;
}
$signature_string .= $this->token;
return md5($signature_string);
}
private function getCode($cash)
{
if ($this->card_type == 3) {
if ($cash == 30) {
return '10-10-10-99-0-12-00-00-5';
} elseif ($cash == 50) {
return '10-10-10-99-0-13-00-00-5';
} elseif ($cash == 100) {
return '10-10-10-99-0-14-00-00-5';
} elseif ($cash == 200) {
return '10-10-10-99-0-15-00-00-5';
}
} elseif ($this->card_type == 4) {
if ($cash == 30) {
return '11-10-10-99-0-11-00-00-4';
} elseif ($cash == 50) {
return '11-10-10-99-0-12-00-00-4';
} elseif ($cash == 100) {
return '11-10-10-99-0-13-00-00-4';
} elseif ($cash == 200) {
return '11-10-10-99-0-14-00-00-4';
}
} elseif ($this->card_type == 5) {
if ($cash == 30) {
return '12-10-10-99-0-12-00-00-22';
} elseif ($cash == 50) {
return '12-10-10-99-0-13-00-00-22';
} elseif ($cash == 100) {
return '12-10-10-99-0-14-00-00-22';
} elseif ($cash == 200) {
return '12-10-10-99-0-15-00-00-22';
}
}
return false;
}
}