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

157 lines
4.4 KiB
PHP

<?php
namespace app\channel\service\system;
/**
* 浦上亚婕服务
* Class Bodingcheng
* @package app\channel\service
*/
class Xinhd extends Core
{
# 这几个可以后台设置
protected $host = '';
protected $mid = '';
protected $token = '';
protected $api = 'api/receiveOrder';
protected $sign = array();
# 电话充值
public function dhcz($param)
{
$check = array
(
'mobile' => 'mobile',
'cash' => 'amount',
'type' => 'type',
);
$param['type'] = 1;
if (isset($param['isp']) && $param['isp']) {
if ($param['isp'] == 1) {
$param['type'] = 1;
} elseif ($param['isp'] == 2) {
$param['type'] = 2;
} elseif ($param['isp'] == 3) {
$param['type'] = 3;
}
}
$this->sign = array('partner_id', 'partner_order_no', 'mobile ', 'amount');
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data;
/*
$sign = $this->_sign($request, array('status', 'partner_id', 'partner_order_no', 'card_no', 'amount', 'recharge_amount', 'type'));
if ($sign != $data['sign']) {
//return false;
}*/
$result = array();
$result['cash'] = 1;
$result['status'] = 4;
if ($data['status'] == 2) {
$result['status'] = 2;
} elseif ($data['status'] <= 0 || $data['status'] == 3) {
$result['status'] = 3;
} else {
$result['status'] = 4;
}
if (isset($data['official_order_no']) && $data['official_order_no']) {
# 流水号
$order = json_decode($data['official_order_no'], true);
if ($order) {
$data['s_nubmer'] = $result['s_nubmer'] = implode(',', $order);
}
}
$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'] == '10000') {
# 正确
$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['partner_id'] = $this->mid;
$request['partner_order_no'] = $param['order'];
$request['valid_time'] = 82800;
$request['notify_url'] = $this->getNotify($param['order'], 1);
$request['sign'] = $this->_sign($request, $this->sign);
$url = $this->host . $this->api;
$response = $this->curl('post', $url, $request, true);
$response = $this->response($response);
//$response['data'] = '';
//$response['msg'] = 'ok';
$channel_order_id = '';
if (isset($response['array']['order_no'])) {
$channel_order_id = $response['array']['order_no'];
}
$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)
{
//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 strtoupper(md5($signature_string));
}
}