diff --git a/app/Http/Controllers/Api/OrderApiController.php b/app/Http/Controllers/Api/OrderApiController.php index 7afec6c..c7fe830 100644 --- a/app/Http/Controllers/Api/OrderApiController.php +++ b/app/Http/Controllers/Api/OrderApiController.php @@ -14,7 +14,7 @@ class OrderApiController extends BaseController public function checkPay(Request $request) { $order_sn = $request->input('order_sn'); - Log::channel('pay_order')->info('查询订单'.json_encode($request->input()), $request->input()); + Log::channel('pay_order')->info('查询订单', $request->input()); if (!$order_sn) { $data = [ 'error' => 1, diff --git a/app/Http/Controllers/Pay/PayController.php b/app/Http/Controllers/Pay/PayController.php index f953da5..778c6b3 100644 --- a/app/Http/Controllers/Pay/PayController.php +++ b/app/Http/Controllers/Pay/PayController.php @@ -2,12 +2,17 @@ namespace App\Http\Controllers\Pay; +use App\ServicePay\PayApiInterface; use App\ServicePay\PayApiProvidesTrait; use Illuminate\Http\Request; class PayController extends BaseController { use PayApiProvidesTrait; + + /** + * @var PayApiInterface + */ public $pay_service; /** diff --git a/app/Models/Message.php b/app/Models/Message.php new file mode 100644 index 0000000..cf8767c --- /dev/null +++ b/app/Models/Message.php @@ -0,0 +1,24 @@ + $v) { + $tmp['mobile'] = $v['mobile']; + $tmp['app_code'] = $v['token']; + $tmp['address'] = $v['from']; + $tmp['content'] = $v['content']; + } + $this->save($tmp); + } catch (\Exception $e) { + Log::channel('smslog')->info('内容',$data); + } + } +} \ No newline at end of file diff --git a/app/Models/Order.php b/app/Models/Order.php index e9f0090..c630e06 100644 --- a/app/Models/Order.php +++ b/app/Models/Order.php @@ -74,7 +74,7 @@ class Order extends BaseModel //支付通道 public function getPayTypeNameAttribute() { - return config('adconfig.pay_type')[$this->pay_type]; + return config('adconfig.pay_type')[$this->pay_type]??''; } //订单状态 diff --git a/app/ServicePay/GuMaPayServices.php b/app/ServicePay/GuMaPayServices.php index a0402d0..ff76cc8 100644 --- a/app/ServicePay/GuMaPayServices.php +++ b/app/ServicePay/GuMaPayServices.php @@ -3,13 +3,11 @@ namespace App\ServicePay; use App\Models\Merchant; +use App\Models\Message; use App\Models\Order; +use App\ServicePay\TransCard\ExampleCard; +use App\ServicePay\TransCard\GetTransInfo; use Illuminate\Support\Facades\Log; -use Yansongda\Pay\Pay; -use Yansongda\Pay\Gateways\Wechat\Support; -use Illuminate\Support\Collection; -use Illuminate\Http\Request; -use Ixudra\Curl\Facades\Curl; class GuMaPayServices implements PayApiInterface { @@ -61,8 +59,9 @@ class GuMaPayServices implements PayApiInterface 'username'=>$this->gateway['username'], 'source'=>$this->gateway['source'], 'url'=>$this->gateway['url'], - 'thumb'=>$this->gateway['thumb'], - 'mch_id'=>$this->gateway['mch_id'] + 'app_id'=>$this->pay_gateway['app_id'], + 'mch_id'=>$this->gateway['mch_id'],//收款 银行卡号 + 'token' => $this->pay_gateway['app_key'],//密钥 ]; $this->pay_model=$this->pay_config; return $this; @@ -114,9 +113,18 @@ class GuMaPayServices implements PayApiInterface */ public function verify() { + $params = $this->result_data; - return $this->pay_model->verify(); - + $allData = $this->request->all(); + if (isset($allData['token'])) { + if ($this->pay_config['app_id'] == $allData['token']) { + return true; + } else { + return false; + } + } else { + return false; + } } @@ -136,15 +144,147 @@ class GuMaPayServices implements PayApiInterface $this->log_name = $name; } - public function notify($return = 1, $pay_type, $request) + /** + * 取得订单,需要分开处理 + * @param $ewm_account + * @return false|void + */ + private function getOrder($ewm_account,$order_money) { + $order_money = number_format($order_money, 2, ',', ''); + //查找未支付的订单 + $this->order = Order::where('ewm_account', $ewm_account)->where('order_money', $order_money) + ->whereIn('status', [0,2])->first(); + //订单不存在返回空 + if (empty($this->order)) { + $this->debugLog('订单不存在:' . $ewm_account); + return false; + } + $this->pay_method = $this->order->gateway_method;//支付方法 + $this->gateway_id = $this->order->gateway_id;//通道ID + $this->merchant = Merchant::find($this->order->merchant_id); + } + public function notify($return, $pay_type, $request) + { + $allData = $request->all(); + $this->setLogName($pay_type); + $this->debugLog('回调原始数据', $allData); + (new Message())->addMsg($allData); + $card = new ExampleCard(); + $card->message($allData['content']); + $getTrans = new GetTransInfo($card); + $requestArr = $getTrans->getInfo(); + if (!is_array($requestArr)) { + $this->debugLog('参数异常'); + return '参数异常'; + } + + $this->pay_type = $pay_type; + $this->request = $request; + //取得订单,是否有此订单,如果没有直接返回空 + $ewm_account = $requestArr['from_card']; + //order_money + //取得订单 + $this->getOrder($ewm_account, $requestArr['pay_money']); + if (empty($this->order)) { + return '订单不存在'; + } + + $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]; + + //取得支付配置 + $this->payConfig($this->pay_type); + + $this->result_data = $requestArr; + $this->result_data['order_sn'] = $this->order->order_sn; + //进行验证签名 + if (!$this->verify()) { + $this->debugLog('签名以及支付状态验证失败'); + return '签名以及支付状态验证失败'; + } + + return $this->payNotify(); + + } + + /** + * 获得通道信息,取得支付配置模型,验证签名, + * @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('失败异常内容:' . json_encode($exception->getTrace())); + $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)]); + + } + + } + + /** + * 统一格式化 + */ + private function unionHandle($data) + { + $result = [ + 'order_sn' => $data['order_sn'],//我方订单号 + 'pay_order_sn' => $data['order_number'],//三方的订单号 + 'pay_money' => $data['pay_money'], //支付金额, + 'money' => $data['pay_money'], + '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['account'], + 'pay_order_sn' => $result['pay_order_sn']]); } public function success() { - // TODO: Implement success() method. + echo 'success'; + exit; } diff --git a/app/ServicePay/PayApiProvidesTrait.php b/app/ServicePay/PayApiProvidesTrait.php index a20483e..36c4c07 100644 --- a/app/ServicePay/PayApiProvidesTrait.php +++ b/app/ServicePay/PayApiProvidesTrait.php @@ -59,38 +59,38 @@ trait PayApiProvidesTrait // return $this->pay_service = new ShanDianServices(); // case 'rongyipay': // return $this->pay_service = new RongYiServices(); - case 'zhanxinpay': - return $this->pay_service = new ZhanXinPayServices(); - case '1003': - return $this->pay_service = new DaliPayServices(); - case '1000': - return $this->pay_service = new PingguopayServices(); - case '1004': - return $this->pay_service = new KoulinghbPayServices(); - case '1002': - 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(); - case '1007': - return $this->pay_service = new DeWuDianServices(); - case '1008': - return $this->pay_service = new MiFengServices(); - case '1009': - case '1011': - case '1015': - return $this->pay_service = new WangWangPayServices(); - case '1010': - return $this->pay_service = new GGPayServices(); - case '1012': - return $this->pay_service = new QunHongBaoServices(); - case '1013': - return $this->pay_service = new WeixinManchongServices(); - case '1014': - return $this->pay_service = new FxPayServices(); +// case 'zhanxinpay': +// return $this->pay_service = new ZhanXinPayServices(); +// case '1003': +// return $this->pay_service = new DaliPayServices(); +// case '1000': +// return $this->pay_service = new PingguopayServices(); +// case '1004': +// return $this->pay_service = new KoulinghbPayServices(); +// case '1002': +// 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(); +// case '1007': +// return $this->pay_service = new DeWuDianServices(); +// case '1008': +// return $this->pay_service = new MiFengServices(); +// case '1009': +// case '1011': +// case '1015': +// return $this->pay_service = new WangWangPayServices(); +// case '1010': +// return $this->pay_service = new GGPayServices(); +// case '1012': +// return $this->pay_service = new QunHongBaoServices(); +// case '1013': +// return $this->pay_service = new WeixinManchongServices(); +// case '1014': +// return $this->pay_service = new FxPayServices(); case '1016': return $this->pay_service = new GoPayServices(); break; diff --git a/app/ServicePay/PayTrait.php b/app/ServicePay/PayTrait.php index dc15549..ea98f63 100644 --- a/app/ServicePay/PayTrait.php +++ b/app/ServicePay/PayTrait.php @@ -330,6 +330,7 @@ trait PayTrait $data['local_user_id'] = $this->user['id']; $data['out_user_id'] = $request->input('user_id', ''); $data['out_trade_sn'] = $request->input('out_trade_sn', ''); + $data['ewm_account'] = $request->input('ewm_account', ''); $data['order_at'] = date('Y-m-d H:i:s'); if ($is_local) { diff --git a/app/ServicePay/TransCard/BaseCard.php b/app/ServicePay/TransCard/BaseCard.php new file mode 100644 index 0000000..b59668e --- /dev/null +++ b/app/ServicePay/TransCard/BaseCard.php @@ -0,0 +1,11 @@ +msg = $msg; + $this->analysisMsg(); + } + + private function analysisMsg(){ + $pattern = '/[0-9]{10,}|[0-9]{1,}\.[0-9]{1,2}/'; + preg_match_all($pattern, $this->msg, $matches, PREG_PATTERN_ORDER); + if ($matches[0]) { + $this->orderInfo = [ + 'from_card' => $matches[0][1], + 'pay_money' => $matches[0][0], + 'order_number' => $matches[0][2], + ]; + } + } + + public function showInfo() + { + $init = [ + 'from_card' => null, + 'pay_money' => null, + 'remark' => null, + 'order_number' => null, + ]; + + return array_merge($init, $this->orderInfo); + } +} \ No newline at end of file diff --git a/app/ServicePay/TransCard/GetTransInfo.php b/app/ServicePay/TransCard/GetTransInfo.php new file mode 100644 index 0000000..d4dd933 --- /dev/null +++ b/app/ServicePay/TransCard/GetTransInfo.php @@ -0,0 +1,25 @@ +card = $card; + } + + /** + * 返回解析短信的信息 + * @return mixed + */ + public function getInfo() + { + return $this->card->showInfo(); + } +} \ No newline at end of file diff --git a/config/adconfig.php b/config/adconfig.php index 2222e28..ca33a73 100644 --- a/config/adconfig.php +++ b/config/adconfig.php @@ -57,23 +57,23 @@ return [ // 'dalepay' =>'大乐支付', // 'shandianpay' =>'闪电支付', // 'rongyipay' =>'融易支付', - 'zhanxinpay' =>'展信支付', - '1003' =>'大利支付', - '1000' =>'苹果付', - '1004' =>'口令红包', - '1002' =>'易汇宝', - '1001' =>'山野付', - '1005' =>'手机网站支付', - '1006' =>'东金天然气', - '1007' =>'得物点卡H5', - '1008' =>'蜜蜂-得物点卡', - '1009' =>'旺旺-得物点卡', - '1010' =>'支付宝天然气', - '1011' =>'支付宝扫码', - '1012' =>'微信红包', - '1013' =>'微信慢充扫码', - '1014' =>'fx_支付宝直充', - '1015' =>'微信直充扫码', +// 'zhanxinpay' =>'展信支付', +// '1003' =>'大利支付', +// '1000' =>'苹果付', +// '1004' =>'口令红包', +// '1002' =>'易汇宝', +// '1001' =>'山野付', +// '1005' =>'手机网站支付', +// '1006' =>'东金天然气', +// '1007' =>'得物点卡H5', +// '1008' =>'蜜蜂-得物点卡', +// '1009' =>'旺旺-得物点卡', +// '1010' =>'支付宝天然气', +// '1011' =>'支付宝扫码', +// '1012' =>'微信红包', +// '1013' =>'微信慢充扫码', +// '1014' =>'fx_支付宝直充', +// '1015' =>'微信直充扫码', '1016' =>'gopay', ], 'payfor_status' => [ diff --git a/config/whitelist.php b/config/whitelist.php index 133ad97..99c07a0 100644 --- a/config/whitelist.php +++ b/config/whitelist.php @@ -5,6 +5,7 @@ return [ '96.9.70.209', '47.243.103.30', '8.218.191.161', + '127.0.0.1', ], 'api'=>[ '45.195.84.39' diff --git a/public/nginx.htaccess b/public/nginx.htaccess index dc5e230..a91513b 100644 --- a/public/nginx.htaccess +++ b/public/nginx.htaccess @@ -1,5 +1,3 @@ location / { - if (!-e $request_filename) { - rewrite ^(.*)$ /index.php?s=/$1 last; - } +try_files $uri $uri/ /index.php?$query_string; } \ 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 f705601..c69e23f 100644 --- a/resources/views/admin/gateway/create.blade.php +++ b/resources/views/admin/gateway/create.blade.php @@ -72,11 +72,23 @@
+ +
+ +
+
+
+
+ +
+ +
+
@@ -265,7 +277,9 @@ @section('add_js')