150 lines
4.3 KiB
PHP
150 lines
4.3 KiB
PHP
![]() |
<?php
|
||
|
|
||
|
namespace app\channel\service\system;
|
||
|
|
||
|
/**
|
||
|
* 服务
|
||
|
* Class Bodingcheng
|
||
|
* @package app\channel\service
|
||
|
*/
|
||
|
class Lupay extends Core
|
||
|
{
|
||
|
# 这几个可以后台设置
|
||
|
protected $host = 'host';
|
||
|
protected $mid = 'mid';
|
||
|
protected $token = 'token';
|
||
|
protected $api = 'api';
|
||
|
protected $api_check = 1;
|
||
|
|
||
|
|
||
|
# 中石化油卡充值
|
||
|
public function dhcz($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'mobile' => 'Account',
|
||
|
'cash' => 'UnitPrice',
|
||
|
'BuyNum' => 'BuyNum',
|
||
|
'Operator' => 'Operator',
|
||
|
);
|
||
|
$param['BuyNum'] = 1;
|
||
|
$param['Operator'] = 3;
|
||
|
if (isset($param['isp']) && $param['isp']) {
|
||
|
if ($param['isp'] == 1) {
|
||
|
$param['Operator'] = 3;
|
||
|
} elseif ($param['isp'] == 2) {
|
||
|
$param['Operator'] = 2;
|
||
|
} elseif ($param['isp'] == 3) {
|
||
|
$param['Operator'] = 1;
|
||
|
}
|
||
|
}
|
||
|
$this->api = 'Api/PayMobile.aspx';
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 通知处理 主要返回状态 2是成功 3是失败
|
||
|
public function notify($data)
|
||
|
{
|
||
|
$request = $data;
|
||
|
$sign = $this->_sign($request, array('APIID', 'Account', 'OrderID','OutID', 'State', 'TradeType','TotalPrice'));
|
||
|
if ($sign != $data['Sign']) {
|
||
|
return false;
|
||
|
}
|
||
|
$result = array();
|
||
|
$result['cash'] = 1;
|
||
|
$result['status'] = 4;
|
||
|
if (isset($data['State'])) {
|
||
|
if ($data['State'] == 10027) {
|
||
|
$result['status'] = 2;
|
||
|
} else {
|
||
|
$result['status'] = 3;
|
||
|
}
|
||
|
|
||
|
if (isset($data['OutOrderNo']) && $data['OutOrderNo']) {
|
||
|
# 流水号
|
||
|
$data['s_nubmer'] = $result['s_nubmer'] = $data['OutOrderNo'];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$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'] == '10018') {
|
||
|
# 正确
|
||
|
$msg = 'ok';
|
||
|
} else {
|
||
|
# 错误
|
||
|
$msg = isset($array['Msg']) ? $array['Msg'] : '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['UnitPrice'] = $request['UnitPrice'] * 1000;
|
||
|
$request['TotalPrice'] = $request['UnitPrice'] * $request['BuyNum'];
|
||
|
$request['APIID'] = $this->mid;
|
||
|
$request['OrderID'] = $param['order'];
|
||
|
$request['CreateTime'] = date('Ymdhis');
|
||
|
$request['isCallBack'] = 1;
|
||
|
$request['TradeType'] = 10;
|
||
|
$request['Sign'] = $this->_sign($request, array('APIID', 'Account', 'BuyNum','CreateTime', 'isCallBack', 'OrderID','TotalPrice', 'TradeType', 'UnitPrice'));
|
||
|
$url = $this->host . $this->api;
|
||
|
|
||
|
$response = $this->curl('post', $url, $request);
|
||
|
$response = $this->response($response);
|
||
|
$channel_order_id = '';
|
||
|
if (isset($response['array']['ReturnOrderID']) && $response['array']['ReturnOrderID']) {
|
||
|
$channel_order_id = $response['array']['ReturnOrderID'];
|
||
|
}
|
||
|
|
||
|
$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) {
|
||
|
if (isset($request[$v]) && $request[$v]) {
|
||
|
$signature_string .= $v . '=' . $request[$v] . '&';
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$signature_string .= 'APIKEY=' . $this->token;
|
||
|
return strtoupper(md5($signature_string));
|
||
|
}
|
||
|
}
|