Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
0dc3100f
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5995
Star
90
Fork
162
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
0dc3100f
编写于
3月 26, 2024
作者:
WOSHIMAHAIFENG
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'dev_wx' into 'dev'
添加微信支付示例 See merge request
!7
上级
7b1dee6d
744d6ac3
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
147 addition
and
46 deletion
+147
-46
manifest.json
manifest.json
+45
-35
pages/API/request-payment/request-payment.uvue
pages/API/request-payment/request-payment.uvue
+102
-11
未找到文件。
manifest.json
浏览文件 @
0dc3100f
{
"name"
:
"hello-uniapp x"
,
"appid"
:
"__UNI__3584C99"
,
"description"
:
""
,
"versionName"
:
"1.0.23"
,
"versionCode"
:
10023
,
"uni-app-x"
:
{},
"name"
:
"hello-uniapp x"
,
"appid"
:
"__UNI__3584C99"
,
"description"
:
""
,
"versionName"
:
"1.0.23"
,
"versionCode"
:
10023
,
"uni-app-x"
:
{},
/*
快应用特有相关
*/
"quickapp"
:
{},
"quickapp"
:
{},
/*
小程序特有相关
*/
"mp-weixin"
:
{
"appid"
:
""
,
"setting"
:
{
"urlCheck"
:
false
"mp-weixin"
:
{
"appid"
:
""
,
"setting"
:
{
"urlCheck"
:
false
},
"usingComponents"
:
true
"usingComponents"
:
true
},
"mp-alipay"
:
{
"usingComponents"
:
true
"mp-alipay"
:
{
"usingComponents"
:
true
},
"mp-baidu"
:
{
"usingComponents"
:
true
"mp-baidu"
:
{
"usingComponents"
:
true
},
"mp-toutiao"
:
{
"usingComponents"
:
true
"mp-toutiao"
:
{
"usingComponents"
:
true
},
"uniStatistics"
:
{
"enable"
:
false
"uniStatistics"
:
{
"enable"
:
false
},
"app"
:
{},
"vueVersion"
:
"3"
,
"h5"
:
{
"router"
:
{
"base"
:
"/web/"
"app"
:
{
"distribute"
:
{
/*
android打包配置
*/
"modules"
:
{
"uni-payment"
:{
"alipay"
:{},
"wxpay"
:{}
}
}
}
},
"vueVersion"
:
"3"
,
"h5"
:
{
"router"
:
{
"base"
:
"/web/"
}
}
}
pages/API/request-payment/request-payment.uvue
浏览文件 @
0dc3100f
<template>
<page-head title="支付宝支付"></page-head>
<button :type="btnType" style="margin: 10px;" @click="pay()">{{btnText}}</button>
<page-head title="发起支付"></page-head>
<template v-if="providerList.length > 0">
<button style="margin-top: 20px;" type="primary" v-for="(item,index) in providerList" :key="index"
@click="requestPayment(item)">{{item.name}}支付</button>
</template>
</template>
<script>
export type PayItem = { id : string, name : string }
export default {
data() {
return {
...
...
@@ -12,11 +17,50 @@
orderInfo: "",
errorCode: 0,
errorMsg: "",
complete: false
complete: false,
providerList: [] as PayItem[]
}
},
onLoad: function () {
uni.getProvider({
service: "payment",
success: (e) => {
console.log("payment success:" + JSON.stringify(e));
let array = e.provider as string[]
array.forEach((value : string) => {
switch (value) {
case 'alipay':
this.providerList.push({
name: '支付宝',
id: "alipay",
} as PayItem);
break;
case 'wxpay':
this.providerList.push({
name: '微信',
id: "wxpay",
} as PayItem);
break;
default:
break;
}
})
},
fail: (e) => {
console.log("获取支付通道失败:", e);
}
});
},
methods: {
pay() {
requestPayment(e : PayItem) {
const provider = e.id
if (provider == "alipay") {
this.payAli()
} else if (provider == "wxpay") {
this.payWX()
}
},
payAli() {
uni.showLoading({
title: "请求中..."
})
...
...
@@ -25,11 +69,13 @@
method: 'GET',
timeout: 6000,
success: (res) => {
this.orderInfo = JSON.stringify(res.data);
console.log("====" + this.orderInfo)
uni.hideLoading()
uni.requestPayment({
provider: "alipay",
orderInfo: res.data as string,
fail: (res
: RequestPaymentFail
) => {
fail: (res) => {
console.log(JSON.stringify(res))
this.errorCode = res.errCode
uni.showToast({
...
...
@@ -37,20 +83,65 @@
title: 'errorCode:' + this.errorCode
});
},
success: (res
: RequestPaymentSuccess
) => {
success: (res) => {
console.log(JSON.stringify(res))
uni.showToast({
icon: 'success',
title: '支付成功'
});
}
} as RequestPaymentOptions)
})
},
fail: (e) => {
console.log(e)
uni.hideLoading()
},
});
},
payWX() {
uni.showLoading({
title: "请求中..."
})
uni.request({
url: 'https://demo.dcloud.net.cn/payment/wxpayv3.HBuilder/?total=0.01',
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,
});
},
fail: () => {
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({
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录