我在自建的云对象内需要用到uni-pay的退款操作refund方法,我看文档是不是有这两种写法:
第一种是在我的云对象内:
const uniPayCo = uniCloud.importObject("uni-pay-co")
然后在业务逻辑的位置调用:
await uniPayCo.refund({
out_trade_no: "2022102701100010100101001", // 插件支付单号
});
第二种是:
先在我自己的云对象设置公共模块依赖uni-pay,
然后在我自己的云对象index.obj.js文件里:
const unipay = require('uni-pay')
const path = require('path'); // 引入内置的path模块
//初始化
const unipayIns = unipay.initWeixinV3({
appId: 'your appId',
mchId: 'your mchId',
v3Key: 'you parterner key',
appCertPath: path.resolve(dirname, 'your appCertPath'),
// appCertContent: "",
appPrivateKeyPath: path.resolve(dirname, 'your appPrivateKeyPath'),
// appPrivateKeyContent: "",
})
然后在需要退款的业务逻辑处使用:
unipayIns.refund
用哪种方法合适呢?如果是第二种,那每次需要用到退款的地方都需要初始化需要写一遍支付配置参数,以后修改起来也麻烦啊。
IT星空 (作者)
我使用的第一种方法:
try {
const clientInfo = this.getClientInfo()
const token = this.getUniIdToken()
const res4 = await uniPayCo.refund({
out_trade_no: res3.data[0].payOrderNo[0], // 插件支付单号
clientInfo: clientInfo,
uniIdToken: token
});
console.log(res4)
ret.code = 0
ret.msg = "拦截成功"
} catch (error) {
console.log(error)
//TODO handle the exception
ret.msg = JSON.stringify(error)
}
然而又报错误:
errMsg: '50403:权限错误',
errCode: 'FunctionBizError',
code: 'FunctionBizError',
errSubject: undefined,
forceReturn: false,
cause: undefined
}
是哪里还要设置权限?我的目的是想让普通登录用户自动发起退款。
2025-06-12 12:24
DCloud_uniCloud_VK
回复 IT星空: 修改这里的权限配置
/uni-pay-co/config/permission.js
2025-06-12 15:03
IT星空 (作者)
回复 DCloud_uniCloud_VK: 是的,修改下果然好了
2025-06-12 16:30