用文档例子来测试
这里测试结果:
- res 返回undefined
- 提示窗口显示乱码
- 接口失败也没有调用@fail="refundFail"
<template>
<view class="test-container">
<!-- 标题区域 -->
<view class="header">
<text class="title">? 空白测试页面</text>
</view>
<button @click="refund">发起退款</button>
<uni-pay ref="pay" @success="refundSuccess" @fail="refundFail"></uni-pay>
</view>
</template>
<script>
export default {
name: 'test',
data() {
return {
};
},
onLoad() {
},
methods: {
async refund() {
let res = await this.$refs.pay.refund({
out_trade_no: "1764297913527-666429_172507", // 插件支付单号
});
if (res) {
uni.showToast({
title: res.errMsg,
icon: "none"
});
}
},
async refundSuccess(result) {
console.log('? 退款成功', result);
this.addLog('? 退款成功');
const refund = result.data.refund;
await this.processRefund(refund, 1); // 1 = 审核通过
},
async refundFail(result) {
console.log('? 退款失败', result);
this.addLog('? 退款失败');
},
}
};
</script>
<style lang="scss" scoped>
.test-container {
min-height: 100vh;
background-color: #f5f5f5;
}
.header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 40rpx;
text-align: center;
color: white;
}
.title {
display: block;
font-size: 40rpx;
font-weight: bold;
margin-bottom: 12rpx;
}
</style>
4 个回复
最佳回复
DCloud_uniCloud_VK
根据你发的错误截图信息,可以确认是node版本太高导致,微信支付v2接口退款接口需要用node16,而hbx本地调试的node固定为18,故要么云端改成node16连接云端测试,要么改成v3接口
Ask小助手
处理uni-pay前端退款失败的情况,关键在于理解退款操作的安全边界。根据知识库信息,退款操作应由服务端发起,而非前端直接调用。前端直接调用
this.$refs.pay.refund()存在安全风险,且异常处理不完整。正确做法:
前端异常处理:使用try-catch捕获异常,避免程序中断
业务逻辑修正:
uni.request({ url: '/api/refund' }))推荐方案:
使用uniCloud支付服务实现完整流程,其演示工程插件市场ID=1835包含标准的退款处理逻辑。前端只需轮询查询退款结果,无需直接处理退款API。
注意:前端组件无法保证资金安全,所有支付/退款核心逻辑必须放在服务端处理。
DCloud_uniCloud_VK
你指的退款失败是接口调用失败还是?有没有错误信息
水煮坦克 (作者)
用文档例子来测试
这里测试结果:
要回复问题请先登录或注册
公告
更多>相关问题