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

153 lines
4.2 KiB
PHP

<?php
namespace app\channel\service\system;
/**
* 服务
* Class Bodingcheng
* @package app\channel\service
*/
class Lechong extends Core
{
# 这几个可以后台设置
protected $host = 'host';
protected $mid = 'mid';
protected $token = 'token';
protected $api = 'api';
public function dhcz($param)
{
$check = array
(
'mobile' => 'account',
'cash' => 'value',
'num' => 'num',
);
$param['num'] = 1;
$this->api = 'api/md5/submitorder';
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data;
$sign = $this->_sign($request, array('sellerid', 'agentcode', 'account', 'value', 'payvalue', 'voucher', 'createtime', 'endtime', 'state', 'remark', 'time'));
if ($sign != $data['sign']) {
return false;
}
$result = array();
$result['cash'] = 1;
if ($data['state'] == '2') {
$result['status'] = 2;
} elseif ($data['state'] == '4' || $data['state'] == '-11') {
$result['status'] = 3;
} else {
$result['status'] = 4;
}
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['recode']) && $array['recode'] == 's100') {
# 正确
$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['agentcode'] = $this->mid;
$request['sellerid'] = $param['order'];
$request['account'] = base64_encode($request['account']);
$request['code'] = $this->getCode($param['cash']);
if (!$request['code']) {
return 'order';
}
$request['notifyurl'] = $this->getNotify($param['order'], 1);
$request['time'] = date('YmdHis');
$request['remark'] = base64_encode('v1');
$request['sign'] = $this->_sign($request, array('agentcode', 'sellerid', 'account', 'code', 'num', 'value', 'notifyurl', 'remark', 'time'));
$url = $this->host . $this->api;
$response = $this->curl('post', $url, $request);
$response = $this->response($response);
//$response['data'] = '';
//$response['msg'] = 'ok';
$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 _sign($request, $param)
{
$signature_string = '';
foreach ($param as $k => $v) {
$signature_string .= $request[$v];
}
$signature_string .= $this->token;
return md5($signature_string);
}
private function getCode($cash)
{
return 'auto_rec';
if ($cash == 50) {
return 'def_zsh_50';
} elseif ($cash == 100) {
return 'def_zsh_100';
} elseif ($cash == 200) {
return 'def_zsh_200';
} elseif ($cash == 500) {
return 'def_zsh_500';
} elseif ($cash == 1000) {
return 'def_zsh_1000';
}
return false;
}
}