152 lines
4.1 KiB
PHP
Raw Permalink Normal View History

2024-09-29 15:43:18 +08:00
<?php
namespace app\channel\service\system;
class Zhizhi2 extends Core
{
# 这几个可以后台设置
protected $host = '';
protected $mid = '';
protected $token = '';
protected $card = array();
protected $order_id = '';
protected $api = '';
protected $sign = array();
# 电话充值
public function dhcz($param)
{
$check = array
(
'mobile' => 'mobile_phone',
'cash' => 'recharge_amount',
'type' => 'type',
);
$param['type'] = '0';
$this->api = 'api/MobileMerchant/RechargeOrder/Import';
$this->sign = array('merchant_name', 'order_no', 'mobile_phone', 'recharge_amount', 'type');
return $this->submit($param, $check);
}
# 查询接口
public function query($param)
{
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data;
unset($request['s_order']);
$result = array();
$result['cash'] = 1;
if ($data['status'] == 'success') {
$result['status'] = 2;
} elseif ($data['status'] == 'error') {
$result['status'] = 3;
} else {
$result['status'] = 4;
}
if (isset($data['trade_no']) && $data['trade_no']) {
# 流水号
$data['s_nubmer'] = $result['s_nubmer'] = $data['trade_no'];
}
$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['status']) && $array['status'] == 'success') {
# 正确
$msg = 'ok';
}
else {
# 错误
$msg = isset($array['message']) ? $array['message'] : 'error';
}
return array
(
'msg' => $msg,
'data' => $data,
'array' => $array,
);
}
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=array();
$request['merchant_name'] = $this->mid;
$this->order_id = $request['order_no'] = $param['order'];
// $request['mobile_phone'] = $param['detail']['phone'];
// $request['amount'] = $param['detail']['amount'];
// $request['type'] = $param['detail']['type'];
$request['sign'] = $this->_sign($request, $this->sign);
$url = $this->host . $this->api;
$response = $this->curl('post', $url, $request);
$response = $this->response($response);
//$response['data'] = '';
//$response['msg'] = 'ok';
$channel_order_id = '';
if (isset($response['array']['data']['order_no']) && $response['array']['data']['order_no']) {
$channel_order_id = $response['array']['data']['order_no'];
}
$this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account'], '', $this->card_id);
return $response['msg'];
}
#签名
private function _sign($request, $param)
{
// ksort($request);
// $signature_string = '';
// foreach ($request as $k => $v) {
// $signature_string .= $k . '=' . $v . '&';
// }
//
// $signature_string .= 'key=' . $this->token;
//
ksort($request);
$signature_string = '';
foreach ($param as $k => $v) {
if (isset($request[$v]) && $request[$v]) {
$signature_string .=$v."=". $request[$v]."&";
}
}
$signature_string .='key='.$this->token;
return md5($signature_string);
}
}