提交 b1bee492 编写于 作者: zhaofengliang920817's avatar zhaofengliang920817

调整request-payment页面示例。

上级 083d7f5f
...@@ -74,130 +74,130 @@ ...@@ -74,130 +74,130 @@
} }
// #endif // #endif
// #ifdef APP-IOS // #ifdef APP-IOS
if (e.provider != null && !e.provider.isAppExist)) { if (e.provider != null && ((e.provider as UniPaymentWxpayProvider).isWeChatInstalled == undefined || ((e.provider as UniPaymentWxpayProvider).isWeChatInstalled != null && (e.provider as UniPaymentWxpayProvider).isWeChatInstalled == false))) {
uni.showToast({ uni.showToast({
title: "微信没有安装", title: "微信没有安装",
icon: 'error' icon: 'error'
}) })
} else { } else {
this.payWX() this.payWX()
} }
// #endif // #endif
} }
}, },
payAli() { payAli() {
uni.showLoading({ uni.showLoading({
title: "请求中..." title: "请求中..."
}) })
uni.request({ uni.request({
url: 'https://demo.dcloud.net.cn/payment/alipay/?total=0.01', url: 'https://demo.dcloud.net.cn/payment/alipay/?total=0.01',
method: 'GET', method: 'GET',
timeout: 6000, timeout: 6000,
success: (res) => { success: (res) => {
this.orderInfo = JSON.stringify(res.data); this.orderInfo = JSON.stringify(res.data);
console.log("====" + this.orderInfo) console.log("====" + this.orderInfo)
uni.hideLoading() uni.hideLoading()
uni.requestPayment({ uni.requestPayment({
provider: "alipay", provider: "alipay",
orderInfo: res.data as string, orderInfo: res.data as string,
fail: (res) => { fail: (res) => {
console.log(JSON.stringify(res)) console.log(JSON.stringify(res))
this.errorCode = res.errCode this.errorCode = res.errCode
uni.showToast({ uni.showToast({
icon: 'error', icon: 'error',
title: 'errorCode:' + this.errorCode title: 'errorCode:' + this.errorCode
}); });
}, },
success: (res) => { success: (res) => {
console.log(JSON.stringify(res)) console.log(JSON.stringify(res))
uni.showToast({ uni.showToast({
icon: 'success', icon: 'success',
title: '支付成功' title: '支付成功'
}); });
} }
}) })
}, },
fail: (e) => { fail: (e) => {
console.log(e) console.log(e)
uni.hideLoading() uni.hideLoading()
}, },
}); });
}, },
payWX() { payWX() {
uni.showLoading({ uni.showLoading({
title: "请求中..." title: "请求中..."
}) })
let url = 'https://demo.dcloud.net.cn/payment/wxpayv3.__UNI__uniappx/?total=0.01' let url = 'https://demo.dcloud.net.cn/payment/wxpayv3.__UNI__uniappx/?total=0.01'
const res = uni.getAppBaseInfo(); const res = uni.getAppBaseInfo();
let packageName : string | null let packageName : string | null
// #ifdef APP-ANDROID
packageName = res.packageName
// #endif
// #ifdef APP-IOS // #ifdef APP-ANDROID
packageName = res.bundleId packageName = res.packageName
// #endif // #endif
if (packageName == 'io.dcloud.hellouniappx') {//hello uniappx // #ifdef APP-IOS
url = 'https://demo.dcloud.net.cn/payment/wxpayv3.__UNI__HelloUniAppX/?total=0.01' packageName = res.bundleId
} // #endif
uni.request({
url: url,
method: 'GET',
timeout: 6000,
header: {
"Content-Type": "application/json"
} as UTSJSONObject,
success: (res) => {
console.log(res.data)
uni.hideLoading()
uni.requestPayment({
provider: "wxpay",
orderInfo: JSON.stringify(res.data),
fail: (res) => {
console.log(JSON.stringify(res))
this.errorCode = res.errCode
uni.showToast({
duration: 5000,
icon: 'error',
title: 'errorCode:' + this.errorCode,
});
},
success: (res) => {
console.log(JSON.stringify(res))
uni.showToast({
duration: 5000,
icon: 'success',
title: '支付成功'
});
}
})
},
fail: (res) => {
uni.hideLoading()
console.log(res)
},
});
},
//自动化测试使用 if (packageName == 'io.dcloud.hellouniappx') {//hello uniappx
jest_pay() { url = 'https://demo.dcloud.net.cn/payment/wxpayv3.__UNI__HelloUniAppX/?total=0.01'
uni.requestPayment({
provider: "alipay",
orderInfo: this.orderInfo,
fail: (res : RequestPaymentFail) => {
this.errorCode = res.errCode
this.complete = true
},
success: (res : RequestPaymentSuccess) => {
console.log(JSON.stringify(res))
this.complete = true
} }
} as RequestPaymentOptions) uni.request({
url: url,
method: 'GET',
timeout: 6000,
header: {
"Content-Type": "application/json"
} as UTSJSONObject,
success: (res) => {
console.log(res.data)
uni.hideLoading()
uni.requestPayment({
provider: "wxpay",
orderInfo: JSON.stringify(res.data),
fail: (res) => {
console.log(JSON.stringify(res))
this.errorCode = res.errCode
uni.showToast({
duration: 5000,
icon: 'error',
title: 'errorCode:' + this.errorCode,
});
},
success: (res) => {
console.log(JSON.stringify(res))
uni.showToast({
duration: 5000,
icon: 'success',
title: '支付成功'
});
}
})
},
fail: (res) => {
uni.hideLoading()
console.log(res)
},
});
},
//自动化测试使用
jest_pay() {
uni.requestPayment({
provider: "alipay",
orderInfo: this.orderInfo,
fail: (res : RequestPaymentFail) => {
this.errorCode = res.errCode
this.complete = true
},
success: (res : RequestPaymentSuccess) => {
console.log(JSON.stringify(res))
this.complete = true
}
} as RequestPaymentOptions)
}
} }
} }
}
</script> </script>
<style> <style>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册