新增支付

This commit is contained in:
zcy 2021-07-20 10:23:29 +08:00
parent db65575467
commit 06cf430f39
16 changed files with 873 additions and 50 deletions

View File

@ -55,6 +55,10 @@ class StatisController extends BaseController
$data['month_order_payfor_all_money'] = $order->getSum(['pay_status' => 1], 'total_money'); $data['month_order_payfor_all_money'] = $order->getSum(['pay_status' => 1], 'total_money');
//今日结算 //今日结算
$today_info = $order->getSumArr(['day' => 0, 'pay_status' => 1], ['total_money', 'final_money']); $today_info = $order->getSumArr(['day' => 0, 'pay_status' => 1], ['total_money', 'final_money']);
//dd($today_info);
//今日充值
$today_pay = $order->getSumArr(['day' => 0, 'pay_status' => 1], ['pay_money']);
$data['day_pay_money'] = $today_pay['pay_money'] ? $today_pay['pay_money'] : 0;
// dd($today_info); // dd($today_info);
//今日盈利 //今日盈利
$data['day_payfor_money'] = $today_info['total_money'] ? $today_info['total_money'] : 0; $data['day_payfor_money'] = $today_info['total_money'] ? $today_info['total_money'] : 0;

View File

@ -7,6 +7,7 @@ class BasePay{
//第二部配置支付信息payConfig //第二部配置支付信息payConfig
public function payConfig($type, $setConfig = []) public function payConfig($type, $setConfig = [])
{ {
//number_format($pay_data['total_amount'], 2, '.', ''),
$config = [ $config = [
'debug' => 1,//调试 'debug' => 1,//调试
'logDir' => to_linux_path(storage_path() . '/logs/'), 'logDir' => to_linux_path(storage_path() . '/logs/'),
@ -18,4 +19,32 @@ class BasePay{
]; ];
$this->pay_config = $config; $this->pay_config = $config;
} }
/**
* 网关域名
* @return string
*/
protected function getGateUrl(): string
{
if (isset($this->pay_gateway['gateway_url']) && !empty(trim($this->pay_gateway['gateway_url']))) {
return rtrim(trim($this->pay_gateway['gateway_url']), '/');
}
return '';
}
protected function returnPayRes($re_type,$msg,$code,$url=''){
if ($code == 1) {
if ($re_type == 'json') {
return json_encode(['code' => 1, 'qrurl' => $url], 256);
} else {
return redirect()->away($url);
}
} else {
if ($re_type == 'json') {
return json_encode(['code' => 0, 'msg' => $msg], 256);
} else {
return $msg;
}
}
}
} }

View File

@ -95,7 +95,7 @@ class DaliPayServices implements PayApiInterface
} }
} }
private function returnPayRes($re_type,$msg,$code,$url=''){ protected function returnPayRes($re_type,$msg,$code,$url=''){
if ($code == 1) { if ($code == 1) {
if ($re_type == 'json') { if ($re_type == 'json') {
return json_encode(['code' => 1, 'qrurl' => $url], 256); return json_encode(['code' => 1, 'qrurl' => $url], 256);

View File

@ -0,0 +1,362 @@
<?php
namespace App\ServicePay;
use Illuminate\Support\Facades\Log;
use Ixudra\Curl\Facades\Curl;
/**
* 东金天然气
* @package App\ServicePay
*/
class DongJinPayServices 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().'/makeTDJsonOrder';
$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 = [
'openid' => $accountId,//商户
'mch_secret' => $this->pay_gateway['cert_pub'],//公钥
'nonce_str' => uniqid(),//随机码
'body' => $pay_data['subject'], //
'out_trade_no' => strval($pay_data['out_trade_no']),//订单号
'total_fee' => number_format($pay_data['total_amount'], 2, '.', ''), //金额,单位为元,精确到小数点后两位
'notify_url' => strval($this->pay_config['notify_url']),// //异步回调地址
'trade_type' => $this->pay_gateway['mch_id'],//对应的三方通道
'device_info' => 'app', //
'time_Stamp' => strval(time()), //
'ip' => request()->getClientIp(), //
];
// $payData['sign'] = $this->md5Verify('create',$payData,$key,['ip']);
$payData['sign'] = $this->sign($payData,$key,['ip']);
$res=$this->ddcurl($createUrl,$payData,true);
// $res = Curl::to($createUrl)->withHeaders(['Content-type:application/json'])->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'] == 1) {
$url = $res['payUrl'];
$msg = $res['msg'] ?? '未知错误';
return $this->returnPayRes($re_type,$msg,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=>$v){
if(!in_array($key,$filter)){
array_push($data, "{$key}={$v}");
}
}
$keyVal = implode('&', $data);
if (!empty($signKey) && is_string($signKey)) {
$keyVal .= '&key='.$signKey;
}
// dd($keyVal);
return strtoupper(md5($keyVal));
}
/**
* 检查订单
* @param $orderid
* @return bool|string
*/
private function checkOrder($orderid,$total_fee)
{
try {
$url = $this->getGateUrl() . '/queryOrder';
$payData = [
'openid' => $this->pay_gateway['app_id'],//商户号
'total_fee' => $total_fee,
'nonce_str' => uniqid(),
'out_trade_no' => $orderid,
];
$key = $this->pay_config['token'];
$payData['sign'] = $this->sign($payData,$key,['txCode','txMsg','code','message']);
Log::channel('pay_order')->info('查询接口请求', $payData);
$res=$this->ddcurl($url,$payData,true);
// $res = Curl::to($url)->withHeaders(['Content-type:application/json'])->withData($payData)->post();
$response = is_array($res) ? $res : json_decode($res, 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'] == 0
&& isset($response['out_trade_no']) && $response['out_trade_no'] == $orderid
) {
return true;
}
return false;
}catch (\Exception $e){
Log::channel('pay_order')->info('err', $e->getMessage());
}
return false;
}
//统一验证签名
public function verify()
{
$params = $this->result_data;
$key = $this->pay_config['token'];
$sindata=[];
foreach ($params as $k=>$v){
if($v!='' && $k!='sign'){
$sindata[$k]=$v;
}
}
$sign = $this->sign($params, $key, ['sign', 'txCode', 'txMsg', 'code', 'message']);
if (isset($params['sign']) && $sign == $params['sign']) {
return true;
} else {
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);
$this->pay_type = $pay_type;
$this->request = $request;
//取得订单,是否有此订单,如果没有直接返回空
$order_sn = $allData['out_trade_no'];
$status = $allData['code'];
if ($status != '0000') {
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;
//检查三方的订单
$checkorder = $this->checkOrder($order_sn,$allData['total_fee']);
if (!$checkorder) {
$this->debugLog('查询三方订单未支付成功');
return '查询三方订单未支付成功';
}
//dump($this->result_data);
//进行验证签名
if (!$this->verify()) {
$this->debugLog('签名以及支付状态验证失败');
return '签名以及支付状态验证失败';
}
return $this->payNotify();
}
/**
* 同步回调
* @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['prepay_id'],//三方的订单号
'pay_money' => number_format($data['total_fee'], 2, '.', ''), //支付金额,
// 'pay_money' => $data['ordermoney'], //支付金额,
'money' => number_format($data['total_fee'], 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, 256);
$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);
}
// dd($param);
#判断是否为post请求
if ($method == 'post') {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, '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

@ -63,7 +63,7 @@ trait PayApiProvidesTrait
return $this->pay_service = new ZhanXinPayServices(); return $this->pay_service = new ZhanXinPayServices();
case '1003': case '1003':
return $this->pay_service = new DaliPayServices(); return $this->pay_service = new DaliPayServices();
case 'pingguopay': case '1000':
return $this->pay_service = new PingguopayServices(); return $this->pay_service = new PingguopayServices();
case '1004': case '1004':
return $this->pay_service = new KoulinghbPayServices(); return $this->pay_service = new KoulinghbPayServices();
@ -71,6 +71,10 @@ trait PayApiProvidesTrait
return $this->pay_service = new YiHuiBaoPayServices(); return $this->pay_service = new YiHuiBaoPayServices();
case '1001': case '1001':
return $this->pay_service = new ShanYePayServices(); return $this->pay_service = new ShanYePayServices();
case '1005':
return $this->pay_service = new ShouJiPayServices();
case '1006':
return $this->pay_service = new DongJinPayServices();
break; break;
} }
} }

View File

@ -91,7 +91,7 @@ trait PayTrait
$pay_config = $this->payMethod($pay_type); $pay_config = $this->payMethod($pay_type);
$this->pay_type = $pay_config['pay_type']; $this->pay_type = $pay_config['pay_type'];
$this->pay_method = $pay_config['method']; $this->pay_method = $pay_config['method'];
$this->debugLog('pay_config:' . json_encode($pay_config,true)); $this->debugLog('pay_config:' . json_encode(array_merge($pay_config, ['pay_channel' => $pay_channel]), true));
//取得配置通道文件 //取得配置通道文件
$this->gateway_list = config('gateway.' . $this->pay_type); $this->gateway_list = config('gateway.' . $this->pay_type);
if(!$this->gateway_list) if(!$this->gateway_list)
@ -276,8 +276,9 @@ trait PayTrait
$this->debugLog('-------------订单开始-------------'); $this->debugLog('-------------订单开始-------------');
$this->debugLog('appid->' . $request->input('app_id')); $this->debugLog('appid->' . $request->input('app_id'));
$this->debugLog('支付类型->' . $pay_type); $this->debugLog('请求数据->' , $request->all());
$this->debugLog('channel->' . $pay_channel); // $this->debugLog('支付类型->' . $pay_type);
// $this->debugLog('channel->' . $pay_channel);
//选择服务类型 //选择服务类型
$this->setPayService($pay_type); $this->setPayService($pay_type);

View File

@ -75,7 +75,7 @@ class PingguopayServices implements PayApiInterface
$sign = strtolower(md5($key . $payData['orderNo'] . $payData['appId'] . $payData['amount'] . $payData['notifyCallback'])); $sign = strtolower(md5($key . $payData['orderNo'] . $payData['appId'] . $payData['amount'] . $payData['notifyCallback']));
$payData['sign'] = $sign; $payData['sign'] = $sign;
// $res=$this->ddcurl($this->pay_config['url'],$pay_data,false); // $res=$this->ddcurl($this->pay_config['url'],$pay_data);
$res = Curl::to($this->pay_config['url'])->withHeaders(['Content-type'=>'application/json'])->withData($payData)->post(); $res = Curl::to($this->pay_config['url'])->withHeaders(['Content-type'=>'application/json'])->withData($payData)->post();
$this->debugLog('下单接口请求内容' . json_encode($payData, true), []); $this->debugLog('下单接口请求内容' . json_encode($payData, true), []);
$this->debugLog('返回内容' . json_encode($res, true), []); $this->debugLog('返回内容' . json_encode($res, true), []);

View File

@ -32,7 +32,7 @@ class ShanYePayServices extends BasePay implements PayApiInterface
*/ */
protected function getGateUrl(): string protected function getGateUrl(): string
{ {
return 'http://154.89.8.108:3020'; return 'http://154.197.5.79:3020';
} }
//第二部配置支付信息payConfig //第二部配置支付信息payConfig
@ -102,7 +102,7 @@ class ShanYePayServices extends BasePay implements PayApiInterface
} }
} }
private function returnPayRes($re_type,$msg,$code,$url=''){ protected function returnPayRes($re_type,$msg,$code,$url=''){
if ($code == 1) { if ($code == 1) {
if ($re_type == 'json') { if ($re_type == 'json') {
return json_encode(['code' => 1, 'qrurl' => $url], 256); return json_encode(['code' => 1, 'qrurl' => $url], 256);

View File

@ -0,0 +1,378 @@
<?php
namespace App\ServicePay;
use Illuminate\Support\Facades\Log;
use Ixudra\Curl\Facades\Curl;
/**
* @package App\ServicePay
*/
class ShouJiPayServices 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().'/api/unifiedorder';
$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,//商户
'pass_code' => $this->pay_gateway['mch_id'],//对应的三方通道
'out_trade_no' => strval($pay_data['out_trade_no']),//订单号
'amount' => number_format($pay_data['total_amount'], 2, '.', ''), //金额,单位为元,精确到小数点后两位
'subject' => $pay_data['subject'], //
'client_ip' => request()->getClientIp(), //
'timestamp' => date('Y-m-d H:i:s'), //
'notify_url' => strval($this->pay_config['notify_url']),// //异步回调地址
'return_url' => strval($this->pay_config['return_url']),// //页面跳转通知
];
$sign = trim(self::keySortMd5Filter($payData), '&');//签名
$sign = md5($sign . $key);
$payData['sign'] = $sign;
$res=$this->ddcurl($createUrl,$payData,false);
// $res = Curl::to($createUrl)->withHeaders(['Content-type:application/json'])->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'] == 0) {
$data=$res['data'];
$url = $data['pay_url'];
$msg = $res['msg'] ?? '未知错误';
return $this->returnPayRes($re_type,$msg,1,$url);
} else {
$msg = $res['msg'] ?? '未知错误';
$this->debugLog('错误' . $msg, []);
return $this->returnPayRes($re_type,$msg,0);
}
}
protected function returnPayRes($re_type,$msg,$code,$url=''){
if ($code == 1) {
if ($re_type == 'json') {
return json_encode(['code' => 1, 'qrurl' => $url], 256);
} else {
return redirect()->away($url);
}
} else {
if ($re_type == 'json') {
return json_encode(['code' => 0, 'msg' => $msg], 256);
} else {
return $msg;
}
}
}
private function sign($tempArr, $signKey,$signSortArr=[]): string
{
$keyVal = '';
if (isset($tempArr['sign'])) {
unset($tempArr['sign']);
}
$data = [];
foreach ($signSortArr as $key){
if(isset($tempArr[$key])){
array_push($data, "{$key}={$tempArr[$key]}");
}
}
ksort($tempArr);
$keyVal = implode('&', $data);
if (!empty($signKey) && is_string($signKey)) {
$keyVal .= $signKey;
}
return strtoupper(md5($keyVal));
}
/**
* 检查订单
* @param $orderid
* @return bool|string
*/
private function checkOrder($orderid)
{
try {
$url = $this->getGateUrl() . '/api/query';
$payData = [
'mch_id' => $this->pay_gateway['app_id'],//商户号
'timestamp' => date('Y-m-d H:i:s'),
'out_trade_no' => $orderid,
];
$key = $this->pay_config['token'];
$sign = trim(self::keySortMd5Filter($payData), '&');//签名
$sign = md5($sign . $key);
$payData['sign'] = $sign;
Log::channel('pay_order')->info('查询接口请求', $payData);
$res=$this->ddcurl($url,$payData,false);
// $res = Curl::to($url)->withData($payData)->post();
$response = is_array($res) ? $res : json_decode($res, 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'] == 0
&& isset($response['data']['out_trade_no']) && $response['data']['out_trade_no'] == $orderid
&& isset($response['data']['status']) && $response['data']['status'] == 2
) {
return true;
}
return false;
}catch (\Exception $e){
Log::channel('pay_order')->info('err', $e->getMessage());
}
return false;
}
//统一验证签名
public function verify()
{
$params = $this->result_data;
$key = $this->pay_config['token'];
$sindata=[];
foreach ($params as $k=>$v){
if($v!='' && $k!='sign'){
$sindata[$k]=$v;
}
}
$sign = trim(self::keySortMd5Filter($sindata,['sign']), '&');//签名
$sign = strtoupper(md5($sign . $key));
if (isset($params['sign']) && $sign == $params['sign']) {
return true;
} else {
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);
$this->pay_type = $pay_type;
$this->request = $request;
//取得订单,是否有此订单,如果没有直接返回空
$order_sn = $allData['out_trade_no'];
$status = $allData['status'];
if ($status != 2) {
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;
//检查三方的订单
$checkorder = $this->checkOrder($order_sn);
if (!$checkorder) {
$this->debugLog('查询三方订单未支付成功');
return '查询三方订单未支付成功';
}
//dump($this->result_data);
//进行验证签名
if (!$this->verify()) {
$this->debugLog('签名以及支付状态验证失败');
return '签名以及支付状态验证失败';
}
return $this->payNotify();
}
/**
* 同步回调
* @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['trade_no'],//三方的订单号
'pay_money' => number_format($data['money'], 2, '.', ''), //支付金额,
// 'pay_money' => $data['ordermoney'], //支付金额,
'money' => number_format($data['money'], 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, 256);
$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);
}
// dd($param);
#判断是否为post请求
if ($method == 'post') {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, '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

@ -101,7 +101,7 @@ class YiHuiBaoPayServices implements PayApiInterface
} }
} }
private function returnPayRes($re_type,$msg,$code,$url=''){ protected function returnPayRes($re_type,$msg,$code,$url=''){
if ($code == 1) { if ($code == 1) {
if ($re_type == 'json') { if ($re_type == 'json') {
return json_encode(['code' => 1, 'qrurl' => $url], 256); return json_encode(['code' => 1, 'qrurl' => $url], 256);

View File

@ -9,6 +9,8 @@
"type": "project", "type": "project",
"require": { "require": {
"php": "^7.2.0", "php": "^7.2.0",
"ext-json": "*",
"ext-curl": "*",
"barryvdh/laravel-debugbar": "^3.1", "barryvdh/laravel-debugbar": "^3.1",
"fideloper/proxy": "^4.0", "fideloper/proxy": "^4.0",
"intervention/image": "^2.4", "intervention/image": "^2.4",

View File

@ -59,10 +59,12 @@ return [
'rongyipay' =>'融易支付', 'rongyipay' =>'融易支付',
'zhanxinpay' =>'展信支付', 'zhanxinpay' =>'展信支付',
'1003' =>'大利支付', '1003' =>'大利支付',
'pingguopay' =>'苹果付', '1000' =>'苹果付',
'1004' =>'口令红包', '1004' =>'口令红包',
'1002' =>'易汇宝', '1002' =>'易汇宝',
'1001' =>'山野付', '1001' =>'山野付',
'1005' =>'手机网站支付',
'1006' =>'东金天然气',
], ],
'payfor_status' => [ 'payfor_status' => [
0 => '等待处理', 0 => '等待处理',

View File

@ -29,43 +29,52 @@ return [
'103.47.241.106', '103.47.241.106',
'110.74.196.112', '110.74.196.112',
'49.156.32.13', '49.156.32.13',
'47.241.164.229',
'43.132.190.48',
], ],
'api'=>[ 'api'=>[
'45.195.84.39' '45.195.84.39'
], ],
'callback'=>[ 'callback'=>[
'xianyu'=>[ // 'xianyu'=>[
'47.91.252.231' // '47.91.252.231'
], // ],
'liangliangpay'=>['47.56.196.226'], // 'liangliangpay'=>['47.56.196.226'],
'wangfupay'=>['129.226.68.95'], // 'wangfupay'=>['129.226.68.95'],
'dashengfupay'=>[ // 'dashengfupay'=>[
'154.210.64.26', // '154.210.64.26',
'45.156.171.170', // '45.156.171.170',
'45.156.171.171', // '45.156.171.171',
'103.75.14.210', // '103.75.14.210',
'154.204.42.109' // '154.204.42.109'
], // ],
'dalepay'=>['148.66.61.130'], // 'dalepay'=>['148.66.61.130'],
'shandianpay'=>['47.115.25.146'], // 'shandianpay'=>['47.115.25.146'],
'rongyipay'=>[ // 'rongyipay'=>[
'103.223.122.125', // '103.223.122.125',
'103.223.122.126', // '103.223.122.126',
'103.223.122.127', // '103.223.122.127',
'103.223.122.128', // '103.223.122.128',
'103.223.122.129', // '103.223.122.129',
], // ],
'dalipay'=>[ '1003'=>[
'117.120.61.66' '117.120.61.66'
], ],
'pingguopay'=>[ 'pingguopay'=>[
'47.243.44.247' '47.243.44.247'
], ],
'koulinghbpay'=>[ '1004'=>[
'8.129.172.207' '8.129.172.207'
], ],
'shanyepay'=>[ '1002'=>[
'154.89.8.108' '154.197.5.79',
] '154.197.4.79'
],
'1005'=>[
'154.89.11.174'
],
'1006'=>[
'47.243.100.241'
],
] ]
]; ];

View File

@ -30,12 +30,7 @@
</div> </div>
</div> </div>
<div class="layui-form-item">
<label class="layui-form-label">三方通道产品ID</label>
<div class="layui-input-block">
<input type="text" name="mch_id" lay-verify="rq" autocomplete="off" class="layui-input"/>
</div>
</div>
<div id="appGatewayEwm" style="display: none"> <div id="appGatewayEwm" style="display: none">
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">收款姓名</label> <label class="layui-form-label">收款姓名</label>
@ -84,7 +79,18 @@
</div> </div>
</div> </div>
<div id="appGateway"> <div id="appGateway">
<div class="layui-form-item">
<label class="layui-form-label">网关</label>
<div class="layui-input-block">
<input type="text" name="gateway_url" lay-verify="rq" autocomplete="off" class="layui-input"/>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">三方通道产品ID</label>
<div class="layui-input-block">
<input type="text" name="mch_id" lay-verify="rq" autocomplete="off" class="layui-input"/>
</div>
</div>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">商户id/合作号</label> <label class="layui-form-label">商户id/合作号</label>
<div class="layui-input-block"> <div class="layui-input-block">

View File

@ -32,13 +32,6 @@
</div> </div>
</div> </div>
<div class="layui-form-item">
<label class="layui-form-label">三方通道产品ID</label>
<div class="layui-input-block">
<input type="text" name="mch_id" value="{{ $show->mch_id }}" lay-verify="rq" autocomplete="off"
class="layui-input"/>
</div>
</div>
<div id="appGatewayEwm" <div id="appGatewayEwm"
style="display: {{ in_array($show->ename,config('adconfig.guma_type'))?'':'none' }}"> style="display: {{ in_array($show->ename,config('adconfig.guma_type'))?'':'none' }}">
<div class="layui-form-item"> <div class="layui-form-item">
@ -100,6 +93,22 @@
<div id="appGateway" <div id="appGateway"
style="display: {{ in_array($show->ename,['tr_weixin','tr_alipay','tr_bank'])?'none':'' }}"> style="display: {{ in_array($show->ename,['tr_weixin','tr_alipay','tr_bank'])?'none':'' }}">
<div class="layui-form-item">
<label class="layui-form-label">网关</label>
<div class="layui-input-block">
<input type="text" name="gateway_url" value="{{ $show->gateway_url }}" lay-verify="rq" autocomplete="off"
class="layui-input"/>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">三方通道产品ID</label>
<div class="layui-input-block">
<input type="text" name="mch_id" value="{{ $show->mch_id }}" lay-verify="rq" autocomplete="off"
class="layui-input"/>
</div>
</div>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">商户id/合作号</label> <label class="layui-form-label">商户id/合作号</label>
<div class="layui-input-block"> <div class="layui-input-block">

View File

@ -217,6 +217,23 @@
</div> </div>
</div> </div>
</div> </div>
<div class="layui-col-sm6 layui-col-md3">
<div class="layui-card">
<div class="layui-card-header">
成功金额
<span class="layui-badge layui-bg-green layuiadmin-badge">今日</span>
</div>
<div class="layui-card-body layuiadmin-card-list">
<p class="layuiadmin-big-font" id="day_pay_money" style="color: #49afdd">0</p>
<p>
&nbsp;
<span class="layuiadmin-span-color" id=""></span>
</p>
</div>
</div>
</div>
</div> </div>