From 04f01e27a777fe667bb37de6ea7bf9fd24789bb7 Mon Sep 17 00:00:00 2001 From: mahaifeng Date: Mon, 2 Sep 2024 15:55:16 +0800 Subject: [PATCH] =?UTF-8?q?[provider]=E4=BF=AE=E6=94=B9=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/API/get-location/get-location.uvue | 12 ++++++-- pages/API/provider/provider.uvue | 24 +++++++-------- .../API/request-payment/request-payment.uvue | 30 +++++++++++-------- 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/pages/API/get-location/get-location.uvue b/pages/API/get-location/get-location.uvue index a039a862..13bd5d6f 100644 --- a/pages/API/get-location/get-location.uvue +++ b/pages/API/get-location/get-location.uvue @@ -108,10 +108,16 @@ } as GetProviderSyncOptions) console.log(provider) provider.providerObjects.forEach((value : UniProvider) => { + var currentProvider = value + if (value.id == 'system') { + currentProvider = value as UniLocationSystemProvider + } else if (value.id == 'tencent') { + currentProvider = value as UniLocationTencentProvider + } this.providerList.push({ - name: value.description, - id: value.id, - provider: value + name: currentProvider.description, + id: currentProvider.id, + provider: currentProvider } as LocationItem); }) diff --git a/pages/API/provider/provider.uvue b/pages/API/provider/provider.uvue index 331eda40..68b183e1 100644 --- a/pages/API/provider/provider.uvue +++ b/pages/API/provider/provider.uvue @@ -34,10 +34,12 @@ title: 'provider', flag: false, serviceList: [ - { service: "payment", name: "支付", provider: [], providerObj: []}, - { service: "location", name: "定位", provider: [], providerObj: []} + { service: "payment", name: "支付", provider: [], providerObj: [] }, + { service: "location", name: "定位", provider: [], providerObj: [] } ] as ProviderItem[], + //自动化测试使用 providerIds: [] as string[], + providerObjects: [] as UniProvider[], } }, @@ -46,33 +48,27 @@ this.serviceList.forEach((item : ProviderItem) => { var provider = uni.getProviderSync({ service: item.service, - } as GetProviderSyncOptions) - console.log('getProvider',provider,provider.providerIds.length) - provider.providerIds.forEach((value) => { - console.log('getProvider','value',value) + } as GetProviderSyncOptions) + provider.providerIds.forEach((value) => { this.providerIds.push(value) }) this.updateProvider(item.service, provider.providerIds, provider.providerObjects); }) }, - updateProvider(service : string, provider : string[] | null, uniProvider : UniProvider[]) { + updateProvider(service : string, provider : string[] | null, uniProvider : UniProvider[]) { + //这里需要从新从serviceList 获取item,不能直接用forEach 里面的item,目前存在bug,后续会解决这个问题 const item : ProviderItem | null = this.serviceList.find((item : ProviderItem) : boolean => { return item.service == service }); + if (item != null && provider != null) { item.provider = provider - item.providerObj = uniProvider item.providerObj.forEach((obj) => { this.providerObjects.push(obj) - // #ifdef APP-ANDROID - if (obj instanceof UniPaymentWxpayProvider) {//判断微信是否安装 - var isWeChatInstalled = (obj as UniPaymentWxpayProvider).isWeChatInstalled - console.log(isWeChatInstalled) - } - // #endif }) } + } } } diff --git a/pages/API/request-payment/request-payment.uvue b/pages/API/request-payment/request-payment.uvue index 3b3097f8..d5fd5db4 100644 --- a/pages/API/request-payment/request-payment.uvue +++ b/pages/API/request-payment/request-payment.uvue @@ -29,17 +29,21 @@ provider.providerObjects.forEach((value : UniProvider) => { switch (value.id) { case 'alipay': + var aliPayProvider = value as UniPaymentAlipayProvider + console.log('alipay', aliPayProvider) this.providerList.push({ - name: '支付宝', - id: "alipay", - provider: value + name: aliPayProvider.description, + id: aliPayProvider.id, + provider: aliPayProvider } as PayItem); break; case 'wxpay': + var wxPayProvider = value as UniPaymentWxpayProvider + console.log('wxpay', wxPayProvider) this.providerList.push({ - name: '微信', - id: "wxpay", - provider: value + name: wxPayProvider.description, + id: wxPayProvider.id, + provider: wxPayProvider } as PayItem); break; default: @@ -51,7 +55,7 @@ requestPayment(e : PayItem) { const provider = e.id if (provider == "alipay") { - this.payAli() + this.payAli(provider) } else if (provider == "wxpay") { // #ifdef APP-ANDROID if (e.provider != null && e.provider instanceof UniPaymentWxpayProvider && !((e.provider as UniPaymentWxpayProvider).isWeChatInstalled)) { @@ -60,7 +64,7 @@ icon: 'error' }) } else { - this.payWX() + this.payWX(provider) } // #endif // #ifdef APP-IOS @@ -70,12 +74,12 @@ icon: 'error' }) } else { - this.payWX() + this.payWX(provider) } // #endif } }, - payAli() { + payAli(id:string) { uni.showLoading({ title: "请求中..." }) @@ -88,7 +92,7 @@ console.log("====" + this.orderInfo) uni.hideLoading() uni.requestPayment({ - provider: "alipay", + provider: id, orderInfo: res.data as string, fail: (res) => { console.log(JSON.stringify(res)) @@ -113,7 +117,7 @@ }, }); }, - payWX() { + payWX(id:string) { uni.showLoading({ title: "请求中..." }) @@ -143,7 +147,7 @@ console.log(res.data) uni.hideLoading() uni.requestPayment({ - provider: "wxpay", + provider: id, orderInfo: JSON.stringify(res.data), fail: (res) => { console.log(JSON.stringify(res)) -- GitLab