2024-09-29 15:43:18 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\channel\service\system;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 数据服务
|
|
|
|
|
* Class Bodingcheng
|
|
|
|
|
* @package app\channel\service
|
|
|
|
|
*/
|
|
|
|
|
class Cardshang extends Core
|
|
|
|
|
{
|
|
|
|
|
# 这几个可以后台设置
|
|
|
|
|
protected $host = '';
|
|
|
|
|
protected $mid = '';
|
|
|
|
|
protected $token = '';
|
|
|
|
|
protected $card = array();
|
|
|
|
|
protected $order_id = '';
|
|
|
|
|
protected $api = '';
|
|
|
|
|
protected $sign = array();
|
|
|
|
|
protected $Operator = '';
|
|
|
|
|
protected $lprefix = '';
|
2024-12-04 12:33:47 +08:00
|
|
|
|
|
2024-09-29 15:43:18 +08:00
|
|
|
|
# 电话充值
|
|
|
|
|
public function dhcz($param)
|
|
|
|
|
{
|
|
|
|
|
$check = array
|
|
|
|
|
(
|
|
|
|
|
'mobile' => 'phone',
|
|
|
|
|
'cash' => 'money',
|
2024-12-04 12:33:47 +08:00
|
|
|
|
'type' => 'type',
|
2024-09-29 15:43:18 +08:00
|
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$param['type'] = '1';
|
|
|
|
|
$this->api = 'card';
|
|
|
|
|
return $this->submit($param, $check);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function ltcz($param)
|
|
|
|
|
{
|
|
|
|
|
$check = array
|
|
|
|
|
(
|
|
|
|
|
'mobile' => 'phone',
|
|
|
|
|
'cash' => 'money',
|
2024-12-04 12:33:47 +08:00
|
|
|
|
'type' => 'type',
|
2024-09-29 15:43:18 +08:00
|
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$param['type'] = '1';
|
|
|
|
|
$this->api = 'card';
|
|
|
|
|
return $this->submit($param, $check);
|
|
|
|
|
}
|
2024-12-04 12:33:47 +08:00
|
|
|
|
|
2024-09-29 15:43:18 +08:00
|
|
|
|
public function dxcz($param)
|
|
|
|
|
{
|
|
|
|
|
$check = array
|
|
|
|
|
(
|
|
|
|
|
'mobile' => 'phone',
|
|
|
|
|
'cash' => 'money',
|
2024-12-04 12:33:47 +08:00
|
|
|
|
'type' => 'type',
|
2024-09-29 15:43:18 +08:00
|
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$param['type'] = '1';
|
|
|
|
|
$this->api = 'card';
|
|
|
|
|
return $this->submit($param, $check);
|
|
|
|
|
}
|
2024-12-04 12:33:47 +08:00
|
|
|
|
|
2024-09-29 15:43:18 +08:00
|
|
|
|
public function ydcz($param)
|
|
|
|
|
{
|
|
|
|
|
$check = array
|
|
|
|
|
(
|
|
|
|
|
'mobile' => 'phone',
|
|
|
|
|
'cash' => 'money',
|
2024-12-04 12:33:47 +08:00
|
|
|
|
'type' => 'type',
|
2024-09-29 15:43:18 +08:00
|
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$param['type'] = '1';
|
|
|
|
|
$this->api = 'card';
|
|
|
|
|
return $this->submit($param, $check);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 通知处理 主要返回状态 2是成功 3是失败
|
|
|
|
|
public function notify($data)
|
|
|
|
|
{
|
|
|
|
|
$request = $data;
|
|
|
|
|
$result = array();
|
|
|
|
|
$result['cash'] = 1;
|
|
|
|
|
$result['status'] = 4;
|
2024-12-04 12:33:47 +08:00
|
|
|
|
if (is_string($data)) {
|
2024-09-29 15:43:18 +08:00
|
|
|
|
$data = json_decode($data, true);
|
|
|
|
|
}
|
|
|
|
|
if ($data['return_code'] == "SUCCESS") {
|
2024-12-04 12:33:47 +08:00
|
|
|
|
if ($data['return_msg']['attach'] == "支付成功") {
|
2024-09-29 15:43:18 +08:00
|
|
|
|
$result['status'] = 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-12-04 12:33:47 +08:00
|
|
|
|
} else if ($data['return_code'] == "FAIL") {
|
2024-09-29 15:43:18 +08:00
|
|
|
|
$result['status'] = 3;
|
2024-12-04 12:33:47 +08:00
|
|
|
|
} else {
|
2024-09-29 15:43:18 +08:00
|
|
|
|
$result['status'] = 4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$result['yes'] = '{"return_code":"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['return_code']) && $array['return_code'] == 'SUCCESS') {
|
|
|
|
|
# 正确
|
|
|
|
|
$msg = 'ok';
|
2024-12-04 12:33:47 +08:00
|
|
|
|
} // }
|
2024-09-29 15:43:18 +08:00
|
|
|
|
else {
|
|
|
|
|
# 错误
|
|
|
|
|
$msg = $array['desc'] ?? 'error';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return array
|
|
|
|
|
(
|
|
|
|
|
'msg' => $msg,
|
|
|
|
|
'data' => $data,
|
|
|
|
|
'array' => $array,
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-12-04 12:33:47 +08:00
|
|
|
|
|
2024-09-29 15:43:18 +08:00
|
|
|
|
# 订单查询
|
|
|
|
|
public function ddcx($param)
|
|
|
|
|
{
|
|
|
|
|
$check = array
|
|
|
|
|
(
|
|
|
|
|
'order_id' => 'szOrderId',
|
|
|
|
|
|
|
|
|
|
);
|
|
|
|
|
$this->sign = array('szAgentId', 'szOrderId');
|
|
|
|
|
$this->api = 'api/old/queryorder';
|
|
|
|
|
return $this->submit($param, $check);
|
|
|
|
|
}
|
2024-12-04 12:33:47 +08:00
|
|
|
|
|
2024-09-29 15:43:18 +08:00
|
|
|
|
# 账户余额
|
|
|
|
|
public function balance($param)
|
|
|
|
|
{
|
|
|
|
|
$check = array
|
2024-12-04 12:33:47 +08:00
|
|
|
|
();
|
2024-09-29 15:43:18 +08:00
|
|
|
|
$this->sign = array('szAgentId');
|
|
|
|
|
$this->api = 'api/old/queryBalance';
|
|
|
|
|
return $this->submit($param, $check);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 查询余额接口
|
|
|
|
|
public function account($day)
|
|
|
|
|
{
|
|
|
|
|
$request['day'] = $day;
|
|
|
|
|
$request['appid'] = $this->mid;
|
|
|
|
|
$request['api_product'] = 'query';
|
|
|
|
|
$this->token = $this->mid . '|' . $this->token;
|
|
|
|
|
$request = $this->getParam($request, $this->token);
|
|
|
|
|
$url = $this->host . 'api/old/queryBalance';
|
|
|
|
|
$response = $this->curl('post', $url, $request);
|
|
|
|
|
$response = $this->response($response);
|
|
|
|
|
|
|
|
|
|
return $response['array']['data'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 查询接口
|
|
|
|
|
public function query($order)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
$request['szAgentId'] = $this->mid;
|
|
|
|
|
$request['szOrderId'] = $order['order_id'];
|
|
|
|
|
|
|
|
|
|
$request['szVerifyString'] = $this->_sign1($request, array('szAgentId', 'szOrderId'));
|
|
|
|
|
$request['szFormat'] = 'json';
|
|
|
|
|
$url = $this->host . 'api/old/queryorder';
|
|
|
|
|
$response = $this->curl('post', $url, $request);
|
|
|
|
|
|
|
|
|
|
$log['type'] = 'query_response';
|
|
|
|
|
$log['data'] = $response;
|
|
|
|
|
$log['config'] = $this->data;
|
|
|
|
|
$this->log($log);
|
|
|
|
|
|
|
|
|
|
$array = $this->json_decode($response);
|
|
|
|
|
|
|
|
|
|
$result = array();
|
|
|
|
|
$result['status'] = 4;
|
2024-12-04 12:33:47 +08:00
|
|
|
|
if (isset($array['nRtn'])) {
|
|
|
|
|
if ($array['nRtn'] == '5012') {
|
2024-09-29 15:43:18 +08:00
|
|
|
|
$result['nFlag'] = 2;
|
|
|
|
|
$result['status'] = 2;
|
2024-12-04 12:33:47 +08:00
|
|
|
|
} elseif ($array['nRtn'] == '5013') {
|
2024-09-29 15:43:18 +08:00
|
|
|
|
$result['nFlag'] = 3;
|
|
|
|
|
$result['status'] = 3;
|
|
|
|
|
}
|
|
|
|
|
if (isset($array['szRtnMsg']) && $array['szRtnMsg']) {
|
|
|
|
|
$result['szRtnMsg'] = $array['szRtnMsg'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2024-12-04 12:33:47 +08:00
|
|
|
|
|
2024-09-29 15:43:18 +08:00
|
|
|
|
private function _sign1($request, $param)
|
|
|
|
|
{
|
2024-12-04 12:33:47 +08:00
|
|
|
|
|
2024-09-29 15:43:18 +08:00
|
|
|
|
$signature_string = '';
|
|
|
|
|
foreach ($param as $k => $v) {
|
|
|
|
|
|
|
|
|
|
$signature_string .= $v . '=' . $request[$v] . '&';
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$signature_string = substr($signature_string, 0, -1);
|
|
|
|
|
|
2024-12-04 12:33:47 +08:00
|
|
|
|
$signature_string .= '&szKey=' . $this->token;
|
|
|
|
|
|
2024-09-29 15:43:18 +08:00
|
|
|
|
|
|
|
|
|
return md5($signature_string);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 提交数据
|
|
|
|
|
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['uid'] = $this->mid;
|
|
|
|
|
$request['orderid'] = $param['order'];
|
|
|
|
|
$request['notify_url'] = $this->getNotify($param['order'], 1);
|
|
|
|
|
|
|
|
|
|
ksort($request);
|
|
|
|
|
|
|
|
|
|
$request['sign'] = $this->_sign($request);
|
|
|
|
|
$url = $this->host . $this->api;
|
|
|
|
|
$response = $this->curl('post', $url, $request);
|
|
|
|
|
$response = $this->response($response);
|
2024-12-04 12:33:47 +08:00
|
|
|
|
|
2024-09-29 15:43:18 +08:00
|
|
|
|
$channel_order_id = '';
|
|
|
|
|
if (isset($response['array']['szRtnCode']) && $response['array']['szRtnCode'] != 'success') {
|
|
|
|
|
#警告类型
|
|
|
|
|
$channel_order_id = $response['array']['szRtnCode'];
|
|
|
|
|
}
|
|
|
|
|
$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 = '';
|
2024-12-04 12:33:47 +08:00
|
|
|
|
foreach ($request as $k => $v) {
|
|
|
|
|
$signature_string .= ($k . '=' . $v);
|
2024-09-29 15:43:18 +08:00
|
|
|
|
}
|
2024-12-04 12:33:47 +08:00
|
|
|
|
$signature_string .= $this->token;
|
2024-09-29 15:43:18 +08:00
|
|
|
|
|
|
|
|
|
// $signature_string .='szKey='. $this->token;
|
|
|
|
|
// var_dump($signature_string);exit;
|
|
|
|
|
return md5($signature_string);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-04 12:33:47 +08:00
|
|
|
|
public function send_post($notify_url, $post_data, $type)
|
2024-09-29 15:43:18 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
$postdata = http_build_query($post_data);
|
|
|
|
|
|
|
|
|
|
$options = array(
|
|
|
|
|
'http' => array(
|
|
|
|
|
'method' => $type,
|
|
|
|
|
'header' => 'Content-type:application/x-www-form-urlencoded',
|
|
|
|
|
'content' => $postdata,
|
|
|
|
|
'timeout' => 15 * 60 // 超时时间(单位:s)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
$context = stream_context_create($options);
|
|
|
|
|
$result = file_get_contents($notify_url, false, $context);
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
}
|