From 06cf430f39df3c886962c23cf1f3a846877260fa Mon Sep 17 00:00:00 2001 From: zcy Date: Tue, 20 Jul 2021 10:23:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Admin/StatisController.php | 4 + app/ServicePay/BasePay.php | 29 ++ app/ServicePay/DaliPayServices.php | 2 +- app/ServicePay/DongJinPayServices.php | 362 +++++++++++++++++ app/ServicePay/PayApiProvidesTrait.php | 6 +- app/ServicePay/PayTrait.php | 7 +- app/ServicePay/PingguopayServices.php | 2 +- app/ServicePay/ShanYePayServices.php | 4 +- app/ServicePay/ShouJiPayServices.php | 378 ++++++++++++++++++ app/ServicePay/YiHuiBaoPayServices.php | 2 +- composer.json | 2 + config/adconfig.php | 4 +- config/whitelist.php | 61 +-- .../views/admin/gateway/create.blade.php | 20 +- resources/views/admin/gateway/edit.blade.php | 23 +- resources/views/admin/home/console.blade.php | 17 + 16 files changed, 873 insertions(+), 50 deletions(-) create mode 100644 app/ServicePay/DongJinPayServices.php create mode 100644 app/ServicePay/ShouJiPayServices.php diff --git a/app/Http/Controllers/Admin/StatisController.php b/app/Http/Controllers/Admin/StatisController.php index be99e76..7bba7e3 100644 --- a/app/Http/Controllers/Admin/StatisController.php +++ b/app/Http/Controllers/Admin/StatisController.php @@ -56,6 +56,10 @@ class StatisController extends BaseController //今日结算 $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); //今日盈利 $data['day_payfor_money'] = $today_info['total_money'] ? $today_info['total_money'] : 0; $data['day_profit_money'] = $today_info['final_money'] ? $today_info['final_money'] : 0; diff --git a/app/ServicePay/BasePay.php b/app/ServicePay/BasePay.php index f816d78..8518547 100644 --- a/app/ServicePay/BasePay.php +++ b/app/ServicePay/BasePay.php @@ -7,6 +7,7 @@ class BasePay{ //第二部配置支付信息,payConfig public function payConfig($type, $setConfig = []) { + //number_format($pay_data['total_amount'], 2, '.', ''), $config = [ 'debug' => 1,//调试 'logDir' => to_linux_path(storage_path() . '/logs/'), @@ -18,4 +19,32 @@ class BasePay{ ]; $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; + } + } + } } \ No newline at end of file diff --git a/app/ServicePay/DaliPayServices.php b/app/ServicePay/DaliPayServices.php index f121a7a..a77abf3 100644 --- a/app/ServicePay/DaliPayServices.php +++ b/app/ServicePay/DaliPayServices.php @@ -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 ($re_type == 'json') { return json_encode(['code' => 1, 'qrurl' => $url], 256); diff --git a/app/ServicePay/DongJinPayServices.php b/app/ServicePay/DongJinPayServices.php new file mode 100644 index 0000000..8fe3687 --- /dev/null +++ b/app/ServicePay/DongJinPayServices.php @@ -0,0 +1,362 @@ +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; + } + +} + diff --git a/app/ServicePay/PayApiProvidesTrait.php b/app/ServicePay/PayApiProvidesTrait.php index baf33e6..57881c2 100644 --- a/app/ServicePay/PayApiProvidesTrait.php +++ b/app/ServicePay/PayApiProvidesTrait.php @@ -63,7 +63,7 @@ trait PayApiProvidesTrait return $this->pay_service = new ZhanXinPayServices(); case '1003': return $this->pay_service = new DaliPayServices(); - case 'pingguopay': + case '1000': return $this->pay_service = new PingguopayServices(); case '1004': return $this->pay_service = new KoulinghbPayServices(); @@ -71,6 +71,10 @@ trait PayApiProvidesTrait return $this->pay_service = new YiHuiBaoPayServices(); case '1001': return $this->pay_service = new ShanYePayServices(); + case '1005': + return $this->pay_service = new ShouJiPayServices(); + case '1006': + return $this->pay_service = new DongJinPayServices(); break; } } diff --git a/app/ServicePay/PayTrait.php b/app/ServicePay/PayTrait.php index 168044c..dc15549 100644 --- a/app/ServicePay/PayTrait.php +++ b/app/ServicePay/PayTrait.php @@ -91,7 +91,7 @@ trait PayTrait $pay_config = $this->payMethod($pay_type); $this->pay_type = $pay_config['pay_type']; $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); if(!$this->gateway_list) @@ -276,8 +276,9 @@ trait PayTrait $this->debugLog('-------------订单开始-------------'); $this->debugLog('appid->' . $request->input('app_id')); - $this->debugLog('支付类型->' . $pay_type); - $this->debugLog('channel->' . $pay_channel); + $this->debugLog('请求数据->' , $request->all()); +// $this->debugLog('支付类型->' . $pay_type); +// $this->debugLog('channel->' . $pay_channel); //选择服务类型 $this->setPayService($pay_type); diff --git a/app/ServicePay/PingguopayServices.php b/app/ServicePay/PingguopayServices.php index 83bee17..941585d 100644 --- a/app/ServicePay/PingguopayServices.php +++ b/app/ServicePay/PingguopayServices.php @@ -75,7 +75,7 @@ class PingguopayServices implements PayApiInterface $sign = strtolower(md5($key . $payData['orderNo'] . $payData['appId'] . $payData['amount'] . $payData['notifyCallback'])); $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(); $this->debugLog('下单接口请求内容' . json_encode($payData, true), []); $this->debugLog('返回内容' . json_encode($res, true), []); diff --git a/app/ServicePay/ShanYePayServices.php b/app/ServicePay/ShanYePayServices.php index 8017383..aad84e1 100644 --- a/app/ServicePay/ShanYePayServices.php +++ b/app/ServicePay/ShanYePayServices.php @@ -32,7 +32,7 @@ class ShanYePayServices extends BasePay implements PayApiInterface */ protected function getGateUrl(): string { - return 'http://154.89.8.108:3020'; + return 'http://154.197.5.79:3020'; } //第二部配置支付信息,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 ($re_type == 'json') { return json_encode(['code' => 1, 'qrurl' => $url], 256); diff --git a/app/ServicePay/ShouJiPayServices.php b/app/ServicePay/ShouJiPayServices.php new file mode 100644 index 0000000..7631e9e --- /dev/null +++ b/app/ServicePay/ShouJiPayServices.php @@ -0,0 +1,378 @@ +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; + } +} + diff --git a/app/ServicePay/YiHuiBaoPayServices.php b/app/ServicePay/YiHuiBaoPayServices.php index 2c46007..aceac19 100644 --- a/app/ServicePay/YiHuiBaoPayServices.php +++ b/app/ServicePay/YiHuiBaoPayServices.php @@ -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 ($re_type == 'json') { return json_encode(['code' => 1, 'qrurl' => $url], 256); diff --git a/composer.json b/composer.json index 9a0091f..4d277b5 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,8 @@ "type": "project", "require": { "php": "^7.2.0", + "ext-json": "*", + "ext-curl": "*", "barryvdh/laravel-debugbar": "^3.1", "fideloper/proxy": "^4.0", "intervention/image": "^2.4", diff --git a/config/adconfig.php b/config/adconfig.php index 76c0604..395bc6b 100644 --- a/config/adconfig.php +++ b/config/adconfig.php @@ -59,10 +59,12 @@ return [ 'rongyipay' =>'融易支付', 'zhanxinpay' =>'展信支付', '1003' =>'大利支付', - 'pingguopay' =>'苹果付', + '1000' =>'苹果付', '1004' =>'口令红包', '1002' =>'易汇宝', '1001' =>'山野付', + '1005' =>'手机网站支付', + '1006' =>'东金天然气', ], 'payfor_status' => [ 0 => '等待处理', diff --git a/config/whitelist.php b/config/whitelist.php index 1ad1df7..183facd 100644 --- a/config/whitelist.php +++ b/config/whitelist.php @@ -29,43 +29,52 @@ return [ '103.47.241.106', '110.74.196.112', '49.156.32.13', + '47.241.164.229', + '43.132.190.48', ], 'api'=>[ '45.195.84.39' ], 'callback'=>[ - 'xianyu'=>[ - '47.91.252.231' - ], - 'liangliangpay'=>['47.56.196.226'], - 'wangfupay'=>['129.226.68.95'], - 'dashengfupay'=>[ - '154.210.64.26', - '45.156.171.170', - '45.156.171.171', - '103.75.14.210', - '154.204.42.109' - ], - 'dalepay'=>['148.66.61.130'], - 'shandianpay'=>['47.115.25.146'], - 'rongyipay'=>[ - '103.223.122.125', - '103.223.122.126', - '103.223.122.127', - '103.223.122.128', - '103.223.122.129', - ], - 'dalipay'=>[ +// 'xianyu'=>[ +// '47.91.252.231' +// ], +// 'liangliangpay'=>['47.56.196.226'], +// 'wangfupay'=>['129.226.68.95'], +// 'dashengfupay'=>[ +// '154.210.64.26', +// '45.156.171.170', +// '45.156.171.171', +// '103.75.14.210', +// '154.204.42.109' +// ], +// 'dalepay'=>['148.66.61.130'], +// 'shandianpay'=>['47.115.25.146'], +// 'rongyipay'=>[ +// '103.223.122.125', +// '103.223.122.126', +// '103.223.122.127', +// '103.223.122.128', +// '103.223.122.129', +// ], + '1003'=>[ '117.120.61.66' ], 'pingguopay'=>[ '47.243.44.247' ], - 'koulinghbpay'=>[ + '1004'=>[ '8.129.172.207' ], - 'shanyepay'=>[ - '154.89.8.108' - ] + '1002'=>[ + '154.197.5.79', + '154.197.4.79' + ], + '1005'=>[ + '154.89.11.174' + ], + '1006'=>[ + '47.243.100.241' + ], ] ]; \ No newline at end of file diff --git a/resources/views/admin/gateway/create.blade.php b/resources/views/admin/gateway/create.blade.php index 9bab220..dd72c4c 100644 --- a/resources/views/admin/gateway/create.blade.php +++ b/resources/views/admin/gateway/create.blade.php @@ -30,12 +30,7 @@ -
- -
- -
-
+
- +
+ +
+ +
+
+
+ +
+ +
+
diff --git a/resources/views/admin/gateway/edit.blade.php b/resources/views/admin/gateway/edit.blade.php index 679e3f6..7fe4a6d 100644 --- a/resources/views/admin/gateway/edit.blade.php +++ b/resources/views/admin/gateway/edit.blade.php @@ -32,13 +32,6 @@
-
- -
- -
-
@@ -100,6 +93,22 @@
+
+ +
+ +
+
+ +
+ +
+ +
+
+
diff --git a/resources/views/admin/home/console.blade.php b/resources/views/admin/home/console.blade.php index d3ab12e..2d0093e 100644 --- a/resources/views/admin/home/console.blade.php +++ b/resources/views/admin/home/console.blade.php @@ -217,6 +217,23 @@
+ +
+
+
+ 成功金额 + 今日 +
+
+ +

0

+

+   + +

+
+
+