新增两个支付

This commit is contained in:
zcy 2021-08-14 15:45:32 +08:00
parent 4ead08e2b2
commit 93fe66ac4d
11 changed files with 1149 additions and 26 deletions

View File

@ -47,4 +47,23 @@ class BasePay{
}
}
}
protected function checkWhiteIP($gate_way){
$ip = request()->getClientIp();
if (isset($gate_way['whiteip'])) {
$whiteip = $gate_way['whiteip'];
if(empty($whiteip)){
return true;
}
$ipArr = explode(',', $whiteip);
$this->debugLog('回调IP', [$ip, $whiteip]);
if (is_array($ipArr)) {
if (!in_array($ip, $ipArr)) {
return false;
}
}
}
return true;
}
}

View File

@ -35,7 +35,7 @@ class DeWuDianServices extends BasePay implements PayApiInterface
*/
public function pay($pay_data)
{
$createUrl=$this->getGateUrl().'/pay/create_order';
$createUrl=$this->getGateUrl().'/api/pay/create_order';
$return = request()->all();
$re_type = 'html';
if (isset($return['re_type'])) {
@ -100,7 +100,6 @@ class DeWuDianServices extends BasePay implements PayApiInterface
if (!empty($signKey) && is_string($signKey)) {
$keyVal .= '&key='.$signKey;
}
dd($keyVal);
return strtoupper(md5($keyVal));
}
@ -112,7 +111,7 @@ class DeWuDianServices extends BasePay implements PayApiInterface
private function checkOrder($orderid)
{
try {
$url = $this->getGateUrl() . '/pay/query_order';
$url = $this->getGateUrl() . '/api/pay/query_order';
$payData = [
'mchId' => $this->pay_gateway['app_id'],//商户号

View File

@ -0,0 +1,355 @@
<?php
namespace App\ServicePay;
use Illuminate\Support\Facades\Log;
use Ixudra\Curl\Facades\Curl;
/**
* @package App\ServicePay
*/
class GGPayServices extends BasePay implements PayApiInterface
{
use PayTrait;
use ThirdPaySignTrait;
public $gateway_list;//当前类型的支付通道列表
public $pay_type;//支付类型
public $pay_method;//支付方法
public $pay_gateway;//当前的支付通道实例
public $pay_config;//这个通道的支付配置信息
public $order;
public $request;
public $gateway_id;
public $pay_data;
public $log_name;
public $result_data;
public static $result;
//统一下单支付
/**
* @param $pay_data
* @return array|\Illuminate\Http\RedirectResponse
*/
public function pay($pay_data)
{
$createUrl=$this->getGateUrl().'/Pay_Index_create.gt';
$return = request()->all();
$re_type = 'html';
if (isset($return['re_type'])) {
$re_type = $return['re_type'];
}
//商户号
$accountId = $this->pay_config['mch_id'];
//商户秘钥
$key = $this->pay_config['token'];
$payData = [
'mch_id' => $accountId,//商户
'ordersn' => strval($pay_data['out_trade_no']),//订单号
'date' => date('Y-m-d H:i:s',time()), //时间
'typecode' => $this->pay_gateway['mch_id'],//对应的三方通道
'amount' => $pay_data['total_amount'], //支付金额为yuan
'is_form'=>2,
'notifyurl' => strval($this->pay_config['notify_url']),// //异步回调地址
'callbackurl' => strval($this->pay_config['return_url']),// //页面跳转通知
];
$sign= $this->sign($payData,$key,[]);
$payData['sign'] = $sign;
// $res=$this->ddcurl($createUrl,$pay_data,false);
$res = Curl::to($createUrl)->withData($payData)->post();
$this->debugLog('下单接口请求内容' . json_encode($payData, true), []);
$this->debugLog('返回内容' . json_encode($res, true), []);
$res = is_array($res) ? $res : json_decode($res, 256);
if (is_array($res) && isset($res['status']) && $res['status'] == 'success') {
$msg = $res['msg'] ?? '未知错误';
$url = $res['pay_url'];
return $this->returnPayRes($re_type,'',1,$url);
} else {
$msg = $res['msg'] ?? '未知错误';
$this->debugLog('错误' . $msg, []);
return $this->returnPayRes($re_type,$msg,0);
}
}
private function sign($tempArr, $signKey,$filter=[]): string
{
$keyVal = '';
if (isset($tempArr['sign'])) {
unset($tempArr['sign']);
}
ksort($tempArr);
$data = [];
foreach ($tempArr as $key => $value) {
if(!in_array($key,$filter) && !empty($value)){
array_push($data, "{$key}={$value}");
}
}
$keyVal = implode('&', $data);
if (!empty($signKey) && is_string($signKey)) {
$keyVal .= '&key='.$signKey;
}
return strtoupper(md5($keyVal));
}
/**
* 检查订单
* @param $orderid
* @return bool|string
*/
private function checkOrder($orderid)
{
$url = $this->getGateUrl() . '/Pay_Trade_query.gt';
$payData = [
'mch_id' => $this->pay_gateway['app_id'],//商户号
'out_trade_no' => $orderid
];
$key = $this->pay_config['token'];
$sign = $this->sign($payData, $key);
$payData['sign'] = $sign;
Log::channel('pay_order')->info('查询接口请求', $payData);
$responseRaw = Curl::to($url)->withData($payData)->post();
// $responseRaw = $this->ddcurl($url, $payData, false);
$response = is_array($responseRaw) ? $responseRaw : json_decode($responseRaw, 256);
// $this->debugLog('查询接口返回' . is_array($res) ? json_encode($res, true) : json_encode(json_decode($res, 256), true));
Log::channel('pay_order')->info('查询接口返回', $response);
if (is_array($response)
&& isset($response['code']) && $response['code'] == '00'
&& isset($response['trade_state']) && $response['trade_state'] == 'SUCCESS'
) {
return true;
}
return false;
}
//返回给支付商的成功
public function success()
{
echo 'OK';
exit;
}
//统一回调处理
/**
* 回调第一部,如果是同步,直接回传
* @param $return
* @param $pay_type
* @param $request
* @return bool|\Illuminate\Http\RedirectResponse
*/
public function notify($return, $pay_type, $request)
{
// $request = json_decode(file_get_contents('php://input'), true);
$allData = $request->all();
$this->setLogName($pay_type);
$this->debugLog('回调原始数据', $allData);
// $datastr = $allData['code'];
$this->pay_type = $pay_type;
$this->request = $request;
//取得订单,是否有此订单,如果没有直接返回空
$order_sn = $allData['out_trade_no'];
$status = $allData['code'];
if ($status != '00') {
return '未支付成功';
}
//取得订单
$this->getOrder($order_sn);
$return = ($return) ? 1 : 0;
if ($return) {
//判断是否是商户id
if ($this->order->merchant_id == 0) {
return redirect()->route('web.user.index');
}
//
return $this->merchantReturnSend();
}
//取得通道id
$this->gateway = $this->pay_gateway = config('gateway.config')[$this->gateway_id];
//dd($this->gateway);
$checkresult = $this->checkWhiteIP($this->gateway);//检查回调IP
if (!$checkresult) {
return 'ip 不合法';
}
//取得支付配置
$this->payConfig($this->pay_type);
$this->result_data = $allData;
//检查三方的订单
$checkorder = $this->checkOrder($order_sn);
if (!$checkorder) {
$this->debugLog('查询三方订单未支付成功');
return '查询三方订单未支付成功';
}
// dump($this->result_data);
//进行验证签名
if (!$this->verify()) {
$this->debugLog('签名以及支付状态验证失败');
return '签名以及支付状态验证失败';
}
return $this->payNotify();
}
//统一验证签名
public function verify()
{
$params = $this->result_data;
$key = $this->pay_config['token'];
// $sinParam=[
// 'api_id'=>$params['api_id'],
// 'mark'=>$params['mark'],
// 'msg'=>$params['msg'],
// 'order_id'=>$params['order_id'],
// 'pay_time'=>$params['pay_time'],
// 'price'=>$params['price'],
// ];
$sign=$this->sign($params,$key,['sign']);
if (isset($params['sign']) && $sign == $params['sign']) {
return true;
} else {
return false;
}
}
/**
* 同步回调
* @return \Illuminate\Http\RedirectResponse
*/
public function returnPay()
{
//判断是否是商户id
if ($this->order->merchant_id == 0) {
return redirect()->route('web.user.index');
}
//
return $this->merchantReturnSend();
}
//异步回调
/**
* 获得通道信息,取得支付配置模型,验证签名,
* @return bool|void
*/
private function payNotify()
{
//取得通道信息内容
$data = $this->result_data;
$this->pay_data = $this->result_data;
//如果应答状态不是01/A6表示支付失败
$this->debugLog(json_encode($data, true));
$this->debugLog('-------------' . $this->order->order_sn . '--选择----' . $this->pay_type . '----' . $this->pay_method . '----开始回调处理-------------------------');
if (empty($data)) {
return $this->debugLog('验证签名失败', $data);
}
try {
$pay_cn_name = '';
//统一格式化
$this->unionHandle($data);
//支付返回信息
$this->pay_data = $data;
$this->debugLog('验证签名成功,数据', $data);
//更新订单
$this->updateOrder();
$this->debugLog('updateOrder Ok');
} catch (\Exception $exception) {
$this->debugLog('失败异常内容:' . $exception->getMessage());
$this->order->notify_status = 1;//支付回调成功
$this->order->pay_status = 1;//支付状态
$this->order->pay_ok_at = date('Y-m-d H:i:s');
$this->order->save();//保存
Log::channel('pay_success')->info($pay_cn_name . '支付成功,但处理订单失败', ['data' => json_encode($data)]);
}
}
/**
* 统一格式化
*/
public function unionHandle($data)
{
$result = [
'order_sn' => $data['out_trade_no'],//我方订单号
'pay_order_sn' => $data['transaction_id'],//三方的订单号
'pay_money' => number_format($data['amount'], 2, '.', ''), //支付金额,
// 'pay_money' => $data['real_fee'], //支付金额,
'money' => number_format($data['amount'], 2, '.', ''),
'pay_type' => $this->pay_type,
'account' => ''
];
$this->setResult($result);
Log::channel('pay_success')->info('支付成功', [
'pay_type' => $result['pay_type'], 'pay_money' => $result['pay_money'],
'account' => $result['money'], 'order_sn' => $result['order_sn'],
'pay_order_sn' => $result['pay_order_sn']]);
}
/**
* 这个调试需要配置在config/logging.php
* @param $pay_type
*/
public function setLogName($pay_type)
{
$this->log_name = $pay_type;
}
/**
* 模拟post提交 json数据 请求接口
* @param string $url
* @param bool|true $https
* @param string $method
* @param string $param
* @return mixed
*/
private function ddcurl($url = '', $param = '', $https = true, $method = 'post')
{
$param = json_encode($param, 320);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
#判断是否为https请求
if ($https === true) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
#判断是否为post请求
if ($method == 'post') {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
}
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
$str = curl_exec($ch);
curl_close($ch);
return $str;
}
}

View File

@ -79,6 +79,14 @@ trait PayApiProvidesTrait
return $this->pay_service = new DeWuDianServices();
case '1008':
return $this->pay_service = new MiFengServices();
case '1009':
return $this->pay_service = new WangWangPayServices();
case '1010':
return $this->pay_service = new GGPayServices();
case '1011':
return $this->pay_service = new WangWangPayServices();
case '1012':
return $this->pay_service = new QunHongBaoServices();
break;
}
}

View File

@ -0,0 +1,362 @@
<?php
namespace App\ServicePay;
use Illuminate\Support\Facades\Log;
use Ixudra\Curl\Facades\Curl;
/**
* @package App\ServicePay
*/
class QunHongBaoServices extends BasePay implements PayApiInterface
{
use PayTrait;
use ThirdPaySignTrait;
public $gateway_list;//当前类型的支付通道列表
public $pay_type;//支付类型
public $pay_method;//支付方法
public $pay_gateway;//当前的支付通道实例
public $pay_config;//这个通道的支付配置信息
public $order;
public $request;
public $gateway_id;
public $pay_data;
public $log_name;
public $result_data;
public static $result;
//统一下单支付
/**
* @param $pay_data
* @return array|\Illuminate\Http\RedirectResponse
*/
public function pay($pay_data)
{
$createUrl=$this->getGateUrl().'/gogogo';
$return = request()->all();
$re_type = 'html';
if (isset($return['re_type'])) {
$re_type = $return['re_type'];
}
//商户号
$accountId = $this->pay_config['mch_id'];
//商户秘钥
$key = $this->pay_config['token'];
$payData = [
'payType' => $this->pay_gateway['mch_id'],//对应的三方通道
'amount' => number_format($pay_data['total_amount'], 2, '.', ''), //支付金额为yuan
'merchantNum' => $accountId,//商户
'orderNo' => strval($pay_data['out_trade_no']),//订单号
'mark' => $pay_data['subject'],
'time' => time(), //商品名称
'notifyUrl' => strval($this->pay_config['notify_url']),// //异步回调地址
'returnUrl' => strval($this->pay_config['return_url']),// //
];
$signParam = [
'merchantNum' => $payData['merchantNum'],
'orderNo' => $payData['orderNo'],
'amount' => $payData['amount'],
'notifyUrl' => $payData['notifyUrl'],
];
$sign= $this->sign($signParam,$key,[]);
$payData['sign'] = $sign;
// $res=$this->ddcurl($createUrl,$pay_data,false);
$res = Curl::to($createUrl)->withData($payData)->post();
$this->debugLog('下单接口请求内容' . json_encode($payData, true), []);
$this->debugLog('返回内容' . json_encode($res, true), []);
$res = is_array($res) ? $res : json_decode($res, 256);
if (is_array($res) && isset($res['code']) && $res['code'] == 200) {
$msg = $res['msg'] ?? '未知错误';
$data=$res['data'];
$url = $data['payUrl'];
return $this->returnPayRes($re_type,'',1,$url);
} else {
$msg = $res['msg'] ?? '未知错误';
$this->debugLog('错误' . $msg, []);
return $this->returnPayRes($re_type,$msg,0);
}
}
private function sign($tempArr, $signKey,$filter=[]): string
{
$keyVal = '';
if (isset($tempArr['sign'])) {
unset($tempArr['sign']);
}
$data = [];
foreach ($tempArr as $key => $value) {
if(!in_array($key,$filter)){
array_push($data, "{$value}");
}
}
$keyVal = implode('', $data);
if (!empty($signKey) && is_string($signKey)) {
$keyVal .= $signKey;
}
return md5($keyVal);
}
/**
* 检查订单
* @param $orderid
* @return bool|string
*/
private function checkOrder($orderid)
{
$url = $this->getGateUrl() . '/fighting';
$payData = [
'merchantNum' => $this->pay_gateway['app_id'],//商户号
'orderNo' => $orderid
];
$key = $this->pay_config['token'];
$sign = $this->sign($payData, $key);
$payData['sign'] = $sign;
Log::channel('pay_order')->info('查询接口请求', $payData);
$responseRaw = Curl::to($url)->withData($payData)->post();
// $responseRaw = $this->ddcurl($url, $payData, false);
$response = is_array($responseRaw) ? $responseRaw : json_decode($responseRaw, 256);
// $this->debugLog('查询接口返回' . is_array($res) ? json_encode($res, true) : json_encode(json_decode($res, 256), true));
Log::channel('pay_order')->info('查询接口返回', $response);
if (is_array($response)
&& isset($response['code']) && $response['code'] == 200
&& isset($response['data']['data']['orderState']) && $response['data']['data']['orderState'] == 4
) {
return true;
}
return false;
}
//返回给支付商的成功
public function success()
{
echo 'success';
exit;
}
//统一回调处理
/**
* 回调第一部,如果是同步,直接回传
* @param $return
* @param $pay_type
* @param $request
* @return bool|\Illuminate\Http\RedirectResponse
*/
public function notify($return, $pay_type, $request)
{
// $request = json_decode(file_get_contents('php://input'), true);
$allData = $request->all();
$this->setLogName($pay_type);
$this->debugLog('回调原始数据', $allData);
if (!is_array($allData)) {
$this->debugLog('参数异常');
return '参数异常';
}
$this->pay_type = $pay_type;
$this->request = $request;
//取得订单,是否有此订单,如果没有直接返回空
$order_sn = $allData['orderNo'];
$status = $allData['state'];
if ($status != 1) {
return '未支付成功';
}
//取得订单
$this->getOrder($order_sn);
$return = ($return) ? 1 : 0;
if ($return) {
//判断是否是商户id
if ($this->order->merchant_id == 0) {
return redirect()->route('web.user.index');
}
//
return $this->merchantReturnSend();
}
//取得通道id
$this->gateway = $this->pay_gateway = config('gateway.config')[$this->gateway_id];
//dd($this->gateway);
$checkresult = $this->checkWhiteIP($this->gateway);//检查回调IP
if (!$checkresult) {
$this->debugLog('ip 不合法');
return 'ip 不合法';
}
//取得支付配置
$this->payConfig($this->pay_type);
$this->result_data = $allData;
// $this->debugLog('回调原始数据', $this->result_data);
//检查三方的订单
$checkorder = $this->checkOrder($order_sn);
if (!$checkorder) {
$this->debugLog('查询三方订单未支付成功');
return '查询三方订单未支付成功';
}
// dump($this->result_data);
//进行验证签名
if (!$this->verify()) {
$this->debugLog('签名以及支付状态验证失败');
return '签名以及支付状态验证失败';
}
return $this->payNotify();
}
//统一验证签名
public function verify()
{
$params = $this->result_data;
$key = $this->pay_config['token'];
$sinParam=[
'state'=>$params['state'],
'merchantNum'=>$params['merchantNum'],
'orderNo'=>$params['orderNo'],
'amount'=>$params['amount'],
];
$sign=$this->sign($sinParam,$key,['sign']);
if (isset($params['sign']) && $sign == $params['sign']) {
return true;
} else {
return false;
}
}
/**
* 同步回调
* @return \Illuminate\Http\RedirectResponse
*/
public function returnPay()
{
//判断是否是商户id
if ($this->order->merchant_id == 0) {
return redirect()->route('web.user.index');
}
//
return $this->merchantReturnSend();
}
//异步回调
/**
* 获得通道信息,取得支付配置模型,验证签名,
* @return bool|void
*/
private function payNotify()
{
//取得通道信息内容
$data = $this->result_data;
$this->pay_data = $this->result_data;
//如果应答状态不是01/A6表示支付失败
$this->debugLog(json_encode($data, true));
$this->debugLog('-------------' . $this->order->order_sn . '--选择----' . $this->pay_type . '----' . $this->pay_method . '----开始回调处理-------------------------');
if (empty($data)) {
return $this->debugLog('验证签名失败', $data);
}
try {
$pay_cn_name = '';
//统一格式化
$this->unionHandle($data);
//支付返回信息
$this->pay_data = $data;
$this->debugLog('验证签名成功,数据', $data);
//更新订单
$this->updateOrder();
$this->debugLog('updateOrder Ok');
} catch (\Exception $exception) {
$this->debugLog('失败异常内容:' . $exception->getMessage());
$this->order->notify_status = 1;//支付回调成功
$this->order->pay_status = 1;//支付状态
$this->order->pay_ok_at = date('Y-m-d H:i:s');
$this->order->save();//保存
Log::channel('pay_success')->info($pay_cn_name . '支付成功,但处理订单失败', ['data' => json_encode($data)]);
}
}
/**
* 统一格式化
*/
public function unionHandle($data)
{
$result = [
'order_sn' => $data['orderNo'],//我方订单号
'pay_order_sn' => $data['platformOrderNo'],//三方的订单号
'pay_money' => number_format($data['actualPayAmount'], 2, '.', ''), //支付金额,
// 'pay_money' => $data['real_fee'], //支付金额,
'money' => number_format($data['amount'], 2, '.', ''),
'pay_type' => $this->pay_type,
'account' => ''
];
$this->setResult($result);
Log::channel('pay_success')->info('支付成功', [
'pay_type' => $result['pay_type'], 'pay_money' => $result['pay_money'],
'account' => $result['money'], 'order_sn' => $result['order_sn'],
'pay_order_sn' => $result['pay_order_sn']]);
}
/**
* 这个调试需要配置在config/logging.php
* @param $pay_type
*/
public function setLogName($pay_type)
{
$this->log_name = $pay_type;
}
/**
* 模拟post提交 json数据 请求接口
* @param string $url
* @param bool|true $https
* @param string $method
* @param string $param
* @return mixed
*/
private function ddcurl($url = '', $param = '', $https = true, $method = 'post')
{
$param = json_encode($param, 320);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
#判断是否为https请求
if ($https === true) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
#判断是否为post请求
if ($method == 'post') {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
}
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
$str = curl_exec($ch);
curl_close($ch);
return $str;
}
}

View File

@ -26,15 +26,6 @@ class ShanYePayServices extends BasePay implements PayApiInterface
public $result_data;
public static $result;
/**
* 网关域名
* @return string
*/
protected function getGateUrl(): string
{
return 'http://154.197.5.79:3020';
}
//第二部配置支付信息payConfig
// public function payConfig($type, $setConfig = [])
// {

View File

@ -0,0 +1,358 @@
<?php
namespace App\ServicePay;
use Illuminate\Support\Facades\Log;
use Ixudra\Curl\Facades\Curl;
/**
* @package App\ServicePay
*/
class WangWangPayServices extends BasePay implements PayApiInterface
{
use PayTrait;
use ThirdPaySignTrait;
public $gateway_list;//当前类型的支付通道列表
public $pay_type;//支付类型
public $pay_method;//支付方法
public $pay_gateway;//当前的支付通道实例
public $pay_config;//这个通道的支付配置信息
public $order;
public $request;
public $gateway_id;
public $pay_data;
public $log_name;
public $result_data;
public static $result;
//统一下单支付
/**
* @param $pay_data
* @return array|\Illuminate\Http\RedirectResponse
*/
public function pay($pay_data)
{
$createUrl=$this->getGateUrl().'/Handler/sdk.ashx?type=create_neworder';
$return = request()->all();
$re_type = 'html';
if (isset($return['re_type'])) {
$re_type = $return['re_type'];
}
//商户号
$accountId = $this->pay_config['mch_id'];
//商户秘钥
$key = $this->pay_config['token'];
$payData = [
'paytype' => $this->pay_gateway['mch_id'],//对应的三方通道
'price' => $pay_data['total_amount'], //支付金额为yuan
'app_id' => $accountId,//商户
'order_id' => strval($pay_data['out_trade_no']),//订单号
'mark' => $pay_data['subject'],
'time' => time(), //商品名称
'notify_url' => strval($this->pay_config['notify_url']),// //异步回调地址
];
$sign= $this->sign($payData,$key,[]);
$payData['sign'] = $sign;
// $res=$this->ddcurl($createUrl,$pay_data,false);
$res = Curl::to($createUrl)->withData($payData)->post();
$this->debugLog('下单接口请求内容' . json_encode($payData, true), []);
$this->debugLog('返回内容' . json_encode($res, true), []);
$res = is_array($res) ? $res : json_decode($res, 256);
if (is_array($res) && isset($res['Status']) && $res['Status'] == 1) {
$msg = $res['Message'] ?? '未知错误';
$data=$res['Result'];
$url = $data['payurl'];
return $this->returnPayRes($re_type,'',1,$url);
} else {
$msg = $res['Message'] ?? '未知错误';
$this->debugLog('错误' . $msg, []);
return $this->returnPayRes($re_type,$msg,0);
}
}
private function sign($tempArr, $signKey,$filter=[]): string
{
$keyVal = '';
if (isset($tempArr['sign'])) {
unset($tempArr['sign']);
}
ksort($tempArr);
$data = [];
foreach ($tempArr as $key => $value) {
if(!in_array($key,$filter)){
array_push($data, "{$key}={$value}");
}
}
$keyVal = implode('&', $data);
if (!empty($signKey) && is_string($signKey)) {
$keyVal .= '&key='.$signKey;
}
return strtolower(md5(strtoupper($keyVal)));
}
/**
* 检查订单
* @param $orderid
* @return bool|string
*/
private function checkOrder($orderid)
{
$url = $this->getGateUrl() . '/Handler/sdk.ashx?type=query_pay';
$payData = [
'app_id' => $this->pay_gateway['app_id'],//商户号
'order_id' => $orderid,
'time' => time(),
];
$key = $this->pay_config['token'];
$sign = $this->sign($payData, $key);
$payData['sign'] = $sign;
Log::channel('pay_order')->info('查询接口请求', $payData);
$responseRaw = Curl::to($url)->withData($payData)->post();
// $responseRaw = $this->ddcurl($url, $payData, false);
$response = is_array($responseRaw) ? $responseRaw : json_decode($responseRaw, 256);
// $this->debugLog('查询接口返回' . is_array($res) ? json_encode($res, true) : json_encode(json_decode($res, 256), true));
Log::channel('pay_order')->info('查询接口返回', $response);
if (is_array($response)
&& isset($response['Status']) && $response['Status'] == 1
) {
return true;
}
return false;
}
//返回给支付商的成功
public function success()
{
echo 'success';
exit;
}
//统一回调处理
/**
* 回调第一部,如果是同步,直接回传
* @param $return
* @param $pay_type
* @param $request
* @return bool|\Illuminate\Http\RedirectResponse
*/
public function notify($return, $pay_type, $request)
{
// $request = json_decode(file_get_contents('php://input'), true);
$allData = $request->all();
$this->setLogName($pay_type);
$this->debugLog('回调原始数据', $allData);
$datastr = $allData['return_type'];
$allData = json_decode($datastr, true);
if (!is_array($allData)) {
$this->debugLog('参数异常');
return '参数异常';
}
$this->pay_type = $pay_type;
$this->request = $request;
//取得订单,是否有此订单,如果没有直接返回空
$order_sn = $allData['order_id'];
$status = $allData['msg'];
if ($status != '支付成功') {
return '未支付成功';
}
$checkresult = $this->checkIP();//检查回调IP
if (!$checkresult) {
return 'ip 不合法';
}
//取得订单
$this->getOrder($order_sn);
$return = ($return) ? 1 : 0;
if ($return) {
//判断是否是商户id
if ($this->order->merchant_id == 0) {
return redirect()->route('web.user.index');
}
//
return $this->merchantReturnSend();
}
//取得通道id
$this->gateway = $this->pay_gateway = config('gateway.config')[$this->gateway_id];
//dd($this->gateway);
//取得支付配置
$this->payConfig($this->pay_type);
$this->result_data = $allData;
$this->debugLog('回调原始数据', $this->result_data);
//检查三方的订单
$checkorder = $this->checkOrder($order_sn);
if (!$checkorder) {
$this->debugLog('查询三方订单未支付成功');
return '查询三方订单未支付成功';
}
// dump($this->result_data);
//进行验证签名
if (!$this->verify()) {
$this->debugLog('签名以及支付状态验证失败');
return '签名以及支付状态验证失败';
}
return $this->payNotify();
}
//统一验证签名
public function verify()
{
$params = $this->result_data;
$key = $this->pay_config['token'];
$sinParam=[
'api_id'=>$params['api_id'],
'mark'=>$params['mark'],
'msg'=>$params['msg'],
'order_id'=>$params['order_id'],
'pay_time'=>$params['pay_time'],
'price'=>$params['price'],
];
$sign=$this->sign($sinParam,$key,['sign']);
if (isset($params['sign']) && $sign == $params['sign']) {
return true;
} else {
return false;
}
}
/**
* 同步回调
* @return \Illuminate\Http\RedirectResponse
*/
public function returnPay()
{
//判断是否是商户id
if ($this->order->merchant_id == 0) {
return redirect()->route('web.user.index');
}
//
return $this->merchantReturnSend();
}
//异步回调
/**
* 获得通道信息,取得支付配置模型,验证签名,
* @return bool|void
*/
private function payNotify()
{
//取得通道信息内容
$data = $this->result_data;
$this->pay_data = $this->result_data;
//如果应答状态不是01/A6表示支付失败
$this->debugLog(json_encode($data, true));
$this->debugLog('-------------' . $this->order->order_sn . '--选择----' . $this->pay_type . '----' . $this->pay_method . '----开始回调处理-------------------------');
if (empty($data)) {
return $this->debugLog('验证签名失败', $data);
}
try {
$pay_cn_name = '';
//统一格式化
$this->unionHandle($data);
//支付返回信息
$this->pay_data = $data;
$this->debugLog('验证签名成功,数据', $data);
//更新订单
$this->updateOrder();
$this->debugLog('updateOrder Ok');
} catch (\Exception $exception) {
$this->debugLog('失败异常内容:' . $exception->getMessage());
$this->order->notify_status = 1;//支付回调成功
$this->order->pay_status = 1;//支付状态
$this->order->pay_ok_at = date('Y-m-d H:i:s');
$this->order->save();//保存
Log::channel('pay_success')->info($pay_cn_name . '支付成功,但处理订单失败', ['data' => json_encode($data)]);
}
}
/**
* 统一格式化
*/
public function unionHandle($data)
{
$result = [
'order_sn' => $data['order_id'],//我方订单号
'pay_order_sn' => $data['order_id'],//三方的订单号
'pay_money' => number_format($data['price'], 2, '.', ''), //支付金额,
// 'pay_money' => $data['real_fee'], //支付金额,
'money' => number_format($data['price'], 2, '.', ''),
'pay_type' => $this->pay_type,
'account' => ''
];
$this->setResult($result);
Log::channel('pay_success')->info('支付成功', [
'pay_type' => $result['pay_type'], 'pay_money' => $result['pay_money'],
'account' => $result['money'], 'order_sn' => $result['order_sn'],
'pay_order_sn' => $result['pay_order_sn']]);
}
/**
* 这个调试需要配置在config/logging.php
* @param $pay_type
*/
public function setLogName($pay_type)
{
$this->log_name = $pay_type;
}
/**
* 模拟post提交 json数据 请求接口
* @param string $url
* @param bool|true $https
* @param string $method
* @param string $param
* @return mixed
*/
private function ddcurl($url = '', $param = '', $https = true, $method = 'post')
{
$param = json_encode($param, 320);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
#判断是否为https请求
if ($https === true) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
#判断是否为post请求
if ($method == 'post') {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
}
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
$str = curl_exec($ch);
curl_close($ch);
return $str;
}
}

View File

@ -45,18 +45,18 @@ return [
'unionpay' => '银联支付',
'usdtpay' => '数字货币USDT',
'citpay' => '数字货币CitPay',
'sanyecaopay_alipay' =>'三叶草支付_支付宝',
'baobeiyepay_alipay' =>'汇丰支付_支付宝',
'xianyupay_alipay' =>'闲鱼支付',
'baoyingpay_alipay' =>'保盈支付',
'liangliangpay' =>'亮亮支付',
'xinbaoyingpay' =>'新保盈支付',
'longepay' =>'龙E支付',
'wangfupay' =>'网付',
'dashengfupay' =>'大盛付支付',
'dalepay' =>'大乐支付',
'shandianpay' =>'闪电支付',
'rongyipay' =>'融易支付',
// 'sanyecaopay_alipay' =>'三叶草支付_支付宝',
// 'baobeiyepay_alipay' =>'汇丰支付_支付宝',
// 'xianyupay_alipay' =>'闲鱼支付',
// 'baoyingpay_alipay' =>'保盈支付',
// 'liangliangpay' =>'亮亮支付',
// 'xinbaoyingpay' =>'新保盈支付',
// 'longepay' =>'龙E支付',
// 'wangfupay' =>'网付',
// 'dashengfupay' =>'大盛付支付',
// 'dalepay' =>'大乐支付',
// 'shandianpay' =>'闪电支付',
// 'rongyipay' =>'融易支付',
'zhanxinpay' =>'展信支付',
'1003' =>'大利支付',
'1000' =>'苹果付',
@ -67,6 +67,10 @@ return [
'1006' =>'东金天然气',
'1007' =>'得物点卡H5',
'1008' =>'蜜蜂-得物点卡',
'1009' =>'旺旺-得物点卡',
'1010' =>'支付宝天然气',
'1011' =>'支付宝扫码',
'1012' =>'微信红包',
],
'payfor_status' => [
0 => '等待处理',

View File

@ -31,6 +31,7 @@ return [
'49.156.32.13',
'47.241.164.229',
'43.132.190.48',
'113.130.126.248',
],
'api'=>[
'45.195.84.39'
@ -57,6 +58,10 @@ return [
// '103.223.122.128',
// '103.223.122.129',
// ],
'1001'=>[
'43.129.184.167',
// '110.40.130.107',
],
'1003'=>[
'117.120.61.66'
],
@ -67,8 +72,8 @@ return [
'8.129.172.207'
],
'1002'=>[
'154.197.5.79',
'154.197.4.79'
'18.163.134.231',
'16.162.65.204'
],
'1005'=>[
'154.89.11.174'
@ -84,6 +89,14 @@ return [
'8.210.207.120',
'47.243.103.193',
'47.243.113.117',
],
// '1009'=>[
// '47.242.45.45',
// '47.243.95.52',
// ]
'1011'=>[
'47.242.45.45',
'47.243.95.52'
]
]
];

View File

@ -151,6 +151,13 @@
</div>
</div>
<div class="layui-form-item layui-form-text" id="whiteip">
<label class="layui-form-label">回调白名单(多个用英文逗号隔开)</label>
<div class="layui-input-block">
<textarea name="whiteip" class="layui-textarea" id="" cols="30" rows="5"></textarea>
</div>
</div>
<div id="gatewayCert">
<div class="layui-form-item layui-form-text-border">
<label class="layui-form-label">公钥证书类型</label>

View File

@ -170,6 +170,13 @@
</select>
</div>
</div>
<div class="layui-form-item layui-form-text" id="whiteip">
<label class="layui-form-label">回调白名单(多个用英文逗号隔开)</label>
<div class="layui-input-block">
<textarea name="whiteip" class="layui-textarea" id="" cols="30" rows="5">{{ $show->whiteip }}</textarea>
</div>
</div>
<div id="gatewayCert"
style="display: {{ in_array($show->ename,['tr_weixin','tr_alipay','tr_bank'])?'none':'' }}">