From f95bf7a1029653a82d5ec2ee75d6fc24d257b91d Mon Sep 17 00:00:00 2001 From: VK <370725567@qq.com> Date: Thu, 22 Aug 2024 19:48:01 +0800 Subject: [PATCH] =?UTF-8?q?uni-pay=E6=96=B0=E5=A2=9E=E8=8B=B9=E6=9E=9C?= =?UTF-8?q?=E8=99=9A=E6=8B=9F=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages.json | 11 +- .../request-payment-uni-pay.uvue | 21 +- .../virtual-payment-uni-pay.uvue | 191 ++++++++++ .../uni-pay/appleiap/apiclient_cert.p8 | 3 + .../uni-config-center/uni-pay/config.js | 11 +- .../uni-pay-popup/uni-pay-popup.uvue | 9 +- .../uni-pay-x/components/uni-pay/uni-pay.uvue | 271 ++++++++++++-- .../cloudfunctions/common/uni-pay/index.js | 4 +- .../cloudfunctions/uni-pay-co/common/error.js | 4 + .../cloudfunctions/uni-pay-co/index.obj.js | 31 +- .../cloudfunctions/uni-pay-co/lang/en.js | 1 + .../cloudfunctions/uni-pay-co/lang/zh-hans.js | 5 +- .../cloudfunctions/uni-pay-co/libs/crypto.js | 13 + .../cloudfunctions/uni-pay-co/libs/index.js | 4 +- .../uni-pay-co/libs/jsonwebtoken.js | 1 + .../cloudfunctions/uni-pay-co/package.json | 4 +- .../cloudfunctions/uni-pay-co/service/pay.js | 341 ++++++++++++++---- 17 files changed, 802 insertions(+), 123 deletions(-) create mode 100644 pages/API/virtual-payment/virtual-payment-uni-pay.uvue create mode 100644 uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-pay/appleiap/apiclient_cert.p8 create mode 100644 uni_modules/uni-pay-x/uniCloud/cloudfunctions/uni-pay-co/libs/jsonwebtoken.js diff --git a/pages.json b/pages.json index e4d0b22d..d9297741 100644 --- a/pages.json +++ b/pages.json @@ -1018,6 +1018,13 @@ "enablePullDownRefresh": false } }, + { + "path": "pages/API/virtual-payment/virtual-payment-uni-pay", + "style": { + "navigationBarTitleText": "苹果虚拟支付(uni-pay)", + "enablePullDownRefresh": false + } + }, // #endif { "path": "pages/API/request-payment/request-payment/order-detail", @@ -1744,14 +1751,14 @@ { "path": "uni_modules/uni-pay-x/pages/ad-interactive-webview/ad-interactive-webview", "style": { - "navigationBarTitleText": "收银台", + "navigationBarTitleText": "ad", "backgroundColor": "#F8F8F8" } }, { "path": "uni_modules/uni-pay-x/pages/pay-desk/pay-desk", "style": { - "navigationBarTitleText": "ad", + "navigationBarTitleText": "收银台", "backgroundColor": "#F8F8F8" } }, diff --git a/pages/API/request-payment/request-payment/request-payment-uni-pay.uvue b/pages/API/request-payment/request-payment/request-payment-uni-pay.uvue index ec469a0f..467f57c7 100644 --- a/pages/API/request-payment/request-payment/request-payment-uni-pay.uvue +++ b/pages/API/request-payment/request-payment/request-payment-uni-pay.uvue @@ -27,9 +27,12 @@ - + + + + - + 插件支付单号: @@ -90,7 +93,7 @@ - @@ -251,7 +254,7 @@ getOrderData['out_trade_no'] = this.out_trade_no; } let res = await payInstance.getOrder(getOrderData); - if (res != null && res['errCode'] == 0) { + if (res['errCode'] == 0) { this.getOrderRes = res.getJSON('pay_order') as UTSJSONObject; let obj = { "-1": "已关闭", @@ -275,7 +278,7 @@ let res = await payInstance.refund({ out_trade_no: this.out_trade_no, // 插件支付单号 }); - if (res != null && res['errCode'] == 0) { + if (res['errCode'] == 0) { uni.showToast({ title: res['errMsg'] as string, icon: "none" @@ -288,7 +291,7 @@ let res = await payInstance.getRefund({ out_trade_no: this.out_trade_no, // 插件支付单号 }); - if (res != null && res['errCode'] == 0) { + if (res['errCode'] == 0) { uni.showModal({ content: res['errMsg'] as string, showCancel: false @@ -301,7 +304,7 @@ let res = await payInstance.closeOrder({ out_trade_no: this.out_trade_no, // 插件支付单号 }); - if (res != null && res['errCode'] == 0) { + if (res['errCode'] == 0) { uni.showModal({ content: res['errMsg'] as string, showCancel: false @@ -316,7 +319,7 @@ provider: "wxpay", provider_pay_type: "jsapi" }); - if (res != null && res['appid'] != null && res['appid'] != "") { + if (res['appid'] != null && res['appid'] != "") { let appid = res['appid'] as string; let redirect_uri = window.location.href.split("?")[0]; let url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scope=${scope}&state=STATE#wechat_redirect`; @@ -327,7 +330,7 @@ async getOpenid(data:UTSJSONObject) : Promise { const payInstance = this.$refs["payRef"] as UniPayComponentPublicInstance; let res = await payInstance.getOpenid(data); - if (res != null && res['openid'] != null && res['openid'] != "") { + if (res['openid'] != null && res['openid'] != "") { let openid = res['openid'] as string; let code = data['code'] as string; this.openid = openid; diff --git a/pages/API/virtual-payment/virtual-payment-uni-pay.uvue b/pages/API/virtual-payment/virtual-payment-uni-pay.uvue new file mode 100644 index 00000000..6361ce1c --- /dev/null +++ b/pages/API/virtual-payment/virtual-payment-uni-pay.uvue @@ -0,0 +1,191 @@ + + + + + diff --git a/uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-pay/appleiap/apiclient_cert.p8 b/uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-pay/appleiap/apiclient_cert.p8 new file mode 100644 index 00000000..1ded0091 --- /dev/null +++ b/uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-pay/appleiap/apiclient_cert.p8 @@ -0,0 +1,3 @@ +-----BEGIN PRIVATE KEY----- + +-----END PRIVATE KEY----- diff --git a/uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-pay/config.js b/uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-pay/config.js index e573971f..78635714 100644 --- a/uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-pay/config.js +++ b/uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-pay/config.js @@ -109,12 +109,15 @@ module.exports = { "alipayRootCertPath": path.join(__dirname, 'alipay/alipayRootCert.crt'), // 支付宝根证书路径 } }, - // ios内购相关(uniapp-x暂不支持) + // 苹果虚拟支付相关 "appleiap": { - // ios内购支付 + // 苹果虚拟支付支付,参数获取地址:https://appstoreconnect.apple.com/access/integrations/api/subs "app": { - "password": "", // App 专用共享密钥,App 专用共享密钥是用于接收此 App 自动续期订阅收据的唯一代码。如果您要将此 App 转让给其他开发者或不想公开主共享密钥,建议使用 App 专用共享密钥。非自动续订场景不需要此参数 - "timeout": 10000, // 请求超时时间,单位:毫秒 + "appId": "", // 密钥ID + "issuerId": "", // Issuer ID + "bundleId": "", // 正式包名(如果dev包名和正式包名一致,则只填bundleId即可) + "devBundleId": "", // dev包名(如果dev包名和正式包名一致,则devBundleId可不填) + "appCertPath": path.join(__dirname, 'appleiap/apiclient_cert.p8'), // 证书路径 "sandbox": true, // 是否是沙箱环境 }, } diff --git a/uni_modules/uni-pay-x/components/uni-pay-popup/uni-pay-popup.uvue b/uni_modules/uni-pay-x/components/uni-pay-popup/uni-pay-popup.uvue index ebb74bc0..15459c2c 100644 --- a/uni_modules/uni-pay-x/components/uni-pay-popup/uni-pay-popup.uvue +++ b/uni_modules/uni-pay-x/components/uni-pay-popup/uni-pay-popup.uvue @@ -1,5 +1,5 @@