diff --git a/extend/base/QQ.php b/extend/base/QQ.php index 31445aa084b61162a8daeeffbabcf225d6db7ce2..99a3b5208dda8681e390fb41d691d92dcce382d9 100644 --- a/extend/base/QQ.php +++ b/extend/base/QQ.php @@ -106,7 +106,7 @@ class QQ { // 请求获取session_key $url = 'https://api.q.qq.com/sns/jscode2session?appid='.$this->_appid.'&secret='.$this->_appsecret.'&js_code='.$authcode.'&grant_type=authorization_code'; - $result = json_decode(file_get_contents($url), true); + $result = $this->HttpRequestGet($url); if(!empty($result['openid'])) { // 从缓存获取用户信息 @@ -118,5 +118,62 @@ class QQ } return false; } + + /** + * 公共获取access_token + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2020-08-26 + * @desc description + */ + public function GetAccessToken() + { + // 缓存key + $key = $this->_appid.'_access_token'; + $result = cache($key); + if(!empty($result)) + { + if($result['expires_in'] > time()) + { + return $result['access_token']; + } + } + + // 网络请求 + $url = 'https://api.q.qq.com/api/getToken?grant_type=client_credential&appid='.$this->_appid.'&secret='.$this->_appsecret; + $result = $this->HttpRequestGet($url); + if(!empty($result['access_token'])) + { + // 缓存存储 + $result['expires_in'] += time(); + cache($key, $result); + return $result['access_token']; + } + return false; + } + + /** + * [HttpRequestGet get请求] + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @datetime 2018-01-03T19:21:38+0800 + * @param [string] $url [url地址] + * @return [array] [返回数据] + */ + public function HttpRequestGet($url) + { + $curl = curl_init(); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_TIMEOUT, 500); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($curl, CURLOPT_URL, $url); + + $res = curl_exec($curl); + curl_close($curl); + return json_decode($res, true); + } } ?> \ No newline at end of file diff --git a/extend/payment/Weixin.php b/extend/payment/Weixin.php index beed7cf598c94ed777a1efaaf0a8f7ca51827c48..f41cb3b5bb4ade3cc527de0cc51e379018fd9d16 100755 --- a/extend/payment/Weixin.php +++ b/extend/payment/Weixin.php @@ -161,8 +161,11 @@ class Weixin return DataReturn('支付缺少配置', -1); } + // 平台 + $client_type = ApplicationClientType(); + // 微信中打开 - if(ApplicationClientType() == 'h5' && IsWeixinEnv()) + if($client_type == 'h5' && IsWeixinEnv()) { exit(header('location:'.PluginsHomeUrl('weixinwebauthorization', 'pay', 'index', input()))); } @@ -174,8 +177,26 @@ class Weixin return $ret; } + // QQ小程序使用微信支付 + if($client_type == 'qq') + { + // 获取QQ access_token + $qq_appid = MyC('common_app_mini_qq_appid'); + $qq_appsecret = MyC('common_app_mini_qq_appsecret'); + $access_token = (new \base\QQ($qq_appid, $qq_appsecret))->GetAccessToken(); + if($access_token === false) + { + return DataReturn('QQ凭证AccessToken获取失败', -1); + } + + // QQ小程序代理下单地址 + $request_url = 'https://api.q.qq.com/wxpay/unifiedorder?appid='.$qq_appid.'&access_token='.$access_token.'&real_notify_url='.urlencode($this->GetNotifyUrl($params)); + } else { + $request_url = 'https://api.mch.weixin.qq.com/pay/unifiedorder'; + } + // 请求接口处理 - $result = $this->XmlToArray($this->HttpRequest('https://api.mch.weixin.qq.com/pay/unifiedorder', $this->ArrayToXml($ret['data']))); + $result = $this->XmlToArray($this->HttpRequest($request_url, $this->ArrayToXml($ret['data']))); if(!empty($result['return_code']) && $result['return_code'] == 'SUCCESS' && !empty($result['prepay_id'])) { return $this->PayHandleReturn($ret['data'], $result, $params); @@ -352,7 +373,7 @@ class Weixin $appid = ($client_type == 'weixin') ? $this->config['mini_appid'] : $this->config['appid']; // 异步地址处理 - $notify_url = (__MY_HTTP__ == 'https' && isset($this->config['agreement']) && $this->config['agreement'] == 1) ? 'http'.mb_substr($params['notify_url'], 5, null, 'utf-8') : $params['notify_url']; + $notify_url = ($client_type == 'qq') ? 'https://api.q.qq.com/wxpay/notify' : $this->GetNotifyUrl($params); // 请求参数 $data = [ @@ -373,6 +394,20 @@ class Weixin return DataReturn('success', 0, $data); } + /** + * 获取异步通知地址 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2020-09-19 + * @desc description + * @param [array] $params [输入参数] + */ + private function GetNotifyUrl($params) + { + return (__MY_HTTP__ == 'https' && isset($this->config['agreement']) && $this->config['agreement'] == 1) ? 'http'.mb_substr($params['notify_url'], 5, null, 'utf-8') : $params['notify_url']; + } + /** * 获取支付交易类型 * @author Devil diff --git a/sourcecode/alipay/pages/user-order/user-order.js b/sourcecode/alipay/pages/user-order/user-order.js index f2cb18d3a5a7fff7fa7f018f45117de3b764f807..67b7bf75dd3d1f18664e3786fbb8e492170adf62 100644 --- a/sourcecode/alipay/pages/user-order/user-order.js +++ b/sourcecode/alipay/pages/user-order/user-order.js @@ -235,8 +235,9 @@ Page({ switch (res.data.data.is_payment_type) { // 正常线上支付 case 0 : + var data = res.data.data; my.tradePay({ - tradeNO: res.data.data.data, + tradeNO: data.data, success: res => { if (res.resultCode == 9000) { // 数据设置 diff --git a/sourcecode/baidu/pages/user-order/user-order.js b/sourcecode/baidu/pages/user-order/user-order.js index b7cee92c83501ec27d41659b55e738e7c887c66a..b05289f0a521e4b244d03cafcd1da79983794487 100755 --- a/sourcecode/baidu/pages/user-order/user-order.js +++ b/sourcecode/baidu/pages/user-order/user-order.js @@ -230,8 +230,9 @@ Page({ switch (res.data.data.is_payment_type) { // 正常线上支付 case 0: + var data = res.data.data; swan.requestPolymerPayment({ - orderInfo: res.data.data.data, + orderInfo: data.data, success: function (res) { // 数据设置 self.order_item_pay_success_handle(order_ids); diff --git a/sourcecode/qq/pages/goods-detail/goods-detail.js b/sourcecode/qq/pages/goods-detail/goods-detail.js index 13bcf2218bcb9655c1810809b7420b287390fde5..fd571ac89d7e50e605dab0d5bdb658225c494004 100755 --- a/sourcecode/qq/pages/goods-detail/goods-detail.js +++ b/sourcecode/qq/pages/goods-detail/goods-detail.js @@ -75,9 +75,6 @@ Page({ // 初始化配置 this.init_config(); - - // 显示分享菜单 - app.show_share_menu(); }, // 初始化配置 diff --git a/sourcecode/qq/pages/plugins/wallet/user-recharge/user-recharge.js b/sourcecode/qq/pages/plugins/wallet/user-recharge/user-recharge.js index af6285e2879b62b75e315049888d68101eca9e7e..1c37ae3407f071485b9041f649c2447476f73f6e 100644 --- a/sourcecode/qq/pages/plugins/wallet/user-recharge/user-recharge.js +++ b/sourcecode/qq/pages/plugins/wallet/user-recharge/user-recharge.js @@ -220,23 +220,38 @@ Page({ success: res => { qq.hideLoading(); if (res.data.code == 0) { - var data = res.data.data.data; - qq.requestPayment({ - package: data, - success: function (res) { - // 数据设置 - self.order_item_pay_success_handle(index); - - // 跳转支付页面 - qq.navigateTo({ - url: "/pages/paytips/paytips?code=9000&total_price=" + - self.data.data_list[index]['money'] + var data = res.data.data; + // 是否微信支付 + if(data.payment.payment == 'Weixin') { + qq.requestWxPayment({ + url: data.data, + referer: app.data.request_url, + success: function(res) { + app.alert({msg: '支付成功后、请不要重复支付、如果订单状态未成功请联系客服处理', is_show_cancel: 0}); + self.get_data_list(); + }, + fail: function (res) { + app.showToast('支付失败'); + } }); - }, - fail: function (res) { - app.showToast('支付失败'); - } - }); + } else { + qq.requestPayment({ + package: data.data, + success: function (res) { + // 数据设置 + self.order_item_pay_success_handle(index); + + // 跳转支付页面 + qq.navigateTo({ + url: "/pages/paytips/paytips?code=9000&total_price=" + + self.data.data_list[index]['money'] + }); + }, + fail: function (res) { + app.showToast('支付失败'); + } + }); + } } else { app.showToast(res.data.msg); } diff --git a/sourcecode/qq/pages/user-order/user-order.js b/sourcecode/qq/pages/user-order/user-order.js index b124121da895dea0c832c5caa36d3ce19f0bea5b..90bf66e1d5bdaff0b402531f4c98cf764f98c765 100755 --- a/sourcecode/qq/pages/user-order/user-order.js +++ b/sourcecode/qq/pages/user-order/user-order.js @@ -233,19 +233,15 @@ Page({ switch (res.data.data.is_payment_type) { // 正常线上支付 case 0 : + var data = res.data.data; // 是否微信支付 - if(res.data.data.payment.payment == 'Weixin') { + if(data.payment.payment == 'Weixin') { qq.requestWxPayment({ - url: res.data.data.data, + url: data.data, referer: app.data.request_url, success: function(res) { - // 数据设置 - self.order_item_pay_success_handle(order_ids); - - // 跳转支付页面 - qq.navigateTo({ - url: "/pages/paytips/paytips?code=9000" - }); + app.alert({msg: '支付成功后、请不要重复支付、如果订单状态未成功请联系客服处理', is_show_cancel: 0}); + self.get_data_list(); }, fail: function (res) { app.showToast('支付失败'); @@ -253,7 +249,7 @@ Page({ }); } else { qq.requestPayment({ - package: res.data.data.data, + package: data.data, success: function(res) { // 数据设置 self.order_item_pay_success_handle(order_ids); diff --git a/sourcecode/toutiao/pages/user-order/user-order.js b/sourcecode/toutiao/pages/user-order/user-order.js index aa8d503879affec0657f1329fef5df8eca894e84..8488af62060bbc9ecb71384e0f1656c034087bd8 100755 --- a/sourcecode/toutiao/pages/user-order/user-order.js +++ b/sourcecode/toutiao/pages/user-order/user-order.js @@ -256,9 +256,10 @@ Page({ switch (res.data.data.is_payment_type) { // 正常线上支付 case 0: + var data = res.data.data; tt.pay({ - orderInfo: res.data.data.order_info, - service: res.data.data.service, + orderInfo: data.order_info, + service: data.service, success(res) { // if (res.code == 0) { // // 数据设置 diff --git a/sourcecode/weixin/pages/user-order/user-order.js b/sourcecode/weixin/pages/user-order/user-order.js index b1f29d3ddd5472d5969f1aaf20a42f69132d9ac5..d54d8e0705e34fbcf382951c00fcf84867f8fef0 100755 --- a/sourcecode/weixin/pages/user-order/user-order.js +++ b/sourcecode/weixin/pages/user-order/user-order.js @@ -233,12 +233,13 @@ Page({ switch (res.data.data.is_payment_type) { // 正常线上支付 case 0 : + var data = res.data.data; wx.requestPayment({ - timeStamp: res.data.data.data.timeStamp, - nonceStr: res.data.data.data.nonceStr, - package: res.data.data.data.package, - signType: res.data.data.data.signType, - paySign: res.data.data.data.paySign, + timeStamp: data.data.timeStamp, + nonceStr: data.data.nonceStr, + package: data.data.package, + signType: data.data.signType, + paySign: data.data.paySign, success: function (res) { // 数据设置 self.order_item_pay_success_handle(order_ids);