From 8b744beae06a542e4ae88abd8bce34faf1ead7e2 Mon Sep 17 00:00:00 2001 From: gongfuxiang Date: Fri, 3 Dec 2021 01:02:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E4=BB=98=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/Order.php | 14 +++++++++ app/service/OrderService.php | 2 +- extend/payment/Alipay.php | 27 +++++++++++----- extend/payment/AlipayFace.php | 34 +++++++++++++------- extend/payment/QQ.php | 34 +++++++++++++------- extend/payment/Weixin.php | 59 +++++++++++++++++++++++------------ 6 files changed, 119 insertions(+), 51 deletions(-) diff --git a/app/api/controller/Order.php b/app/api/controller/Order.php index 568e5b201..9eaf31ac4 100755 --- a/app/api/controller/Order.php +++ b/app/api/controller/Order.php @@ -272,5 +272,19 @@ class Order extends Common return ApiService::ApiDataReturn(OrderService::OrderDelete($params)); } + /** + * 支付状态校验 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2019-01-08 + * @desc description + */ + public function PayCheck() + { + $params = $this->data_post; + $params['user'] = $this->user; + return ApiService::ApiDataReturn(OrderService::OrderPayCheck($params)); + } } ?> \ No newline at end of file diff --git a/app/service/OrderService.php b/app/service/OrderService.php index c16d1f15a..e755e1703 100755 --- a/app/service/OrderService.php +++ b/app/service/OrderService.php @@ -271,7 +271,7 @@ class OrderService 'call_back_url' => $call_back_url, 'redirect_url' => $redirect_url, 'site_name' => MyC('home_site_name', 'ShopXO', true), - 'ajax_url' => MyUrl('index/order/paycheck'), + 'check_url' => MyUrl('index/order/paycheck'), ]; // 发起支付处理钩子 diff --git a/extend/payment/Alipay.php b/extend/payment/Alipay.php index d82d2d055..f9d637eb9 100755 --- a/extend/payment/Alipay.php +++ b/extend/payment/Alipay.php @@ -145,7 +145,6 @@ class Alipay // app,头条小程序 case 'ios' : case 'android' : - case 'toutiao' : $ret = $this->PayApp($params); break; @@ -246,17 +245,19 @@ class Alipay $parameter['sign'] = $this->MyRsaSign($this->GetSignContent($parameter)); // 接口则直接返回 + $html = $this->BuildRequestForm($parameter); if(APPLICATION == 'app') { $result = [ 'data' => $parameter, + 'html' => $html, 'url' => 'https://openapi.alipay.com/gateway.do?charset=utf-8', ]; return DataReturn('success', 0, $result); } - + // web端输出执行form表单post提交 - exit($this->BuildRequestForm($parameter)); + exit($html); } @@ -293,9 +294,21 @@ class Alipay // 生成签名参数+签名 $parameter['sign'] = $this->MyRsaSign($this->GetSignContent($parameter)); - - // 输出执行form表单post提交 - exit($this->BuildRequestForm($parameter)); + + // 接口则直接返回 + $html = $this->BuildRequestForm($parameter); + if(APPLICATION == 'app') + { + $result = [ + 'data' => $parameter, + 'html' => $html, + 'url' => 'https://openapi.alipay.com/gateway.do?charset=utf-8', + ]; + return DataReturn('success', 0, $result); + } + + // web端输出执行form表单post提交 + exit($html); } /** @@ -504,9 +517,7 @@ class Alipay //submit按钮控件请不要含有name属性 $html .= ""; - $html .= ""; - return $html; } diff --git a/extend/payment/AlipayFace.php b/extend/payment/AlipayFace.php index 20c2894bf..1eabc40a8 100644 --- a/extend/payment/AlipayFace.php +++ b/extend/payment/AlipayFace.php @@ -52,7 +52,7 @@ class AlipayFace 'name' => '支付宝', // 插件名称 'version' => '1.0.0', // 插件版本 'apply_version' => '不限', // 适用系统版本描述 - 'apply_terminal'=> ['pc', 'h5'], // 适用终端 默认全部 ['pc', 'h5', 'app', 'alipay', 'weixin', 'baidu'] + 'apply_terminal'=> ['pc', 'h5', 'weixin'], // 适用终端 默认全部 ['pc', 'h5', 'app', 'alipay', 'weixin', 'baidu'] 'desc' => '支付宝当面付、适用web端,用户主动扫码支付方式,买家的交易资金直接打入卖家支付宝账户,快速回笼交易资金。 立即申请', // 插件描述(支持html) 'author' => 'Devil', // 开发者 'author_url' => 'http://shopxo.net/', // 开发者主页 @@ -171,19 +171,31 @@ class AlipayFace // 状态 if(isset($result[$key]['code']) && $result[$key]['code'] == 10000 && !empty($result[$key]['qr_code'])) { - if(empty($params['ajax_url'])) + if(empty($params['check_url'])) { return DataReturn('支付状态校验地址不能为空', -50); } - $pay_params = [ - 'url' => urlencode(base64_encode($result[$key]['qr_code'])), - 'order_no' => $params['order_no'], - 'name' => urlencode('支付宝支付'), - 'msg' => urlencode('打开支付宝APP扫一扫进行支付'), - 'ajax_url' => urlencode(base64_encode($params['ajax_url'])), - ]; - $url = MyUrl('index/pay/qrcode', $pay_params); - return DataReturn('success', 0, $url); + if(APPLICATION == 'app') + { + $data = [ + 'pay_url' => $result[$key]['qr_code'], + 'qrcode_url' => MyUrl('index/qrcode/index', ['content'=>urlencode(base64_encode($result[$key]['qr_code']))]), + 'order_no' => $params['order_no'], + 'name' => '支付宝支付', + 'msg' => '打开支付宝APP扫一扫进行支付', + 'check_url' => $params['check_url'], + ]; + } else { + $pay_params = [ + 'url' => urlencode(base64_encode($result[$key]['qr_code'])), + 'order_no' => $params['order_no'], + 'name' => urlencode('支付宝支付'), + 'msg' => urlencode('打开支付宝APP扫一扫进行支付'), + 'check_url' => urlencode(base64_encode($params['check_url'])), + ]; + $data = MyUrl('index/pay/qrcode', $pay_params); + } + return DataReturn('success', 0, $data); } // 直接返回支付信息 diff --git a/extend/payment/QQ.php b/extend/payment/QQ.php index ad9333eb4..20cfa5ef6 100644 --- a/extend/payment/QQ.php +++ b/extend/payment/QQ.php @@ -227,23 +227,35 @@ class QQ // 手机模式下直接返回微信的支付url地址,打开支付(缺点是支付后会直接关闭站点) // QQ支付本身没有提供H5支付方案,这种方式也可以直接支付(缺点是支付后不能回调到原来浏览器) // 公众号后续再采用公众号的方式支付,体验会更好一些,只是可以不关闭站点 - if(ApplicationClientType() == 'h5') + if(APPLICATION == 'web' && IsMobile()) { $result = DataReturn('success', 0, $data['code_url']); } else { - if(empty($params['ajax_url'])) + if(empty($params['check_url'])) { return DataReturn('支付状态校验地址不能为空', -50); } - $pay_params = [ - 'url' => urlencode(base64_encode($data['code_url'])), - 'order_no' => $params['order_no'], - 'name' => urlencode('QQ支付'), - 'msg' => urlencode('打开QQAPP扫一扫进行支付'), - 'ajax_url' => urlencode(base64_encode($params['ajax_url'])), - ]; - $url = MyUrl('index/pay/qrcode', $pay_params); - $result = DataReturn('success', 0, $url); + if(APPLICATION == 'app') + { + $data = [ + 'pay_url' => $data['code_url'], + 'qrcode_url' => MyUrl('index/qrcode/index', ['content'=>urlencode(base64_encode($data['code_url']))]), + 'order_no' => $params['order_no'], + 'name' => 'QQ支付', + 'msg' => '打开QQAPP扫一扫进行支付', + 'check_url' => $params['check_url'], + ]; + } else { + $pay_params = [ + 'url' => urlencode(base64_encode($data['code_url'])), + 'order_no' => $params['order_no'], + 'name' => urlencode('QQ支付'), + 'msg' => urlencode('打开QQAPP扫一扫进行支付'), + 'check_url' => urlencode(base64_encode($params['check_url'])), + ]; + $data = MyUrl('index/pay/qrcode', $pay_params); + } + $result = DataReturn('success', 0, $data); } break; diff --git a/extend/payment/Weixin.php b/extend/payment/Weixin.php index 0dd785436..f89b4377f 100755 --- a/extend/payment/Weixin.php +++ b/extend/payment/Weixin.php @@ -249,19 +249,30 @@ class Weixin { // web支付 case 'NATIVE' : - if(empty($params['ajax_url'])) + if(empty($params['check_url'])) { return DataReturn('支付状态校验地址不能为空', -50); } - $pay_params = [ - 'url' => urlencode(base64_encode($data['code_url'])), - 'order_no' => $params['order_no'], - 'name' => urlencode('微信支付'), - 'msg' => urlencode('打开微信APP扫一扫进行支付'), - 'ajax_url' => urlencode(base64_encode($params['ajax_url'])), - ]; - $url = MyUrl('index/pay/qrcode', $pay_params); - $result = DataReturn('success', 0, $url); + if(APPLICATION == 'app') + { + $data = [ + 'qrcode_url' => MyUrl('index/qrcode/index', ['content'=>urlencode(base64_encode($data['code_url']))]), + 'order_no' => $params['order_no'], + 'name' => '微信支付', + 'msg' => '打开微信APP扫一扫进行支付', + 'check_url' => $params['check_url'], + ]; + } else { + $pay_params = [ + 'url' => urlencode(base64_encode($data['code_url'])), + 'order_no' => $params['order_no'], + 'name' => urlencode('微信支付'), + 'msg' => urlencode('打开微信APP扫一扫进行支付'), + 'check_url' => urlencode(base64_encode($params['check_url'])), + ]; + $data = MyUrl('index/pay/qrcode', $pay_params); + } + $result = DataReturn('success', 0, $data); break; // h5支付 @@ -277,19 +288,20 @@ class Weixin // 微信中/小程序支付 case 'JSAPI' : - $pay_data = array( + $pay_data = [ 'appId' => $pay_params['appid'], 'package' => 'prepay_id='.$data['prepay_id'], 'nonceStr' => md5(time().rand()), 'signType' => $pay_params['sign_type'], 'timeStamp' => (string) time(), - ); + ]; $pay_data['paySign'] = $this->GetSign($pay_data); // 微信中 if(APPLICATION == 'web' && IsWeixinEnv()) { - $this->PayHtml($pay_data, $redirect_url); + $html = $this->PayHtml($pay_data, $redirect_url); + die($pay_data['html']); } else { $result = DataReturn('success', 0, $pay_data); } @@ -324,10 +336,16 @@ class Weixin private function PayHtml($pay_data, $redirect_url) { // 支付代码 - exit(' + return ' 微信安全支付 + + + +

正在支付中...

+

请不要关闭页面!

+ - - - '); + + '; } /** @@ -490,10 +507,12 @@ class Weixin 'android' => 'APP', ]; - // 微信中打开 - if($client_type == 'h5' && IsWeixinEnv()) + // h5 + if($client_type == 'h5') { - $type_all['h5'] = $type_all['weixin']; + // 微信中打开 + // h5则使用NATIVE二维码的方式 + $type_all['h5'] = IsWeixinEnv() ? $type_all['weixin'] : $type_all['pc']; } return isset($type_all[$client_type]) ? $type_all[$client_type] : '';