智能客服
你问我答,随时在线为你解决问题
开发者可以参考demo中SDK支付接口调用
| 名称 | 下载 |
|---|---|
| DevEco Studio 示例代码 |
JavaScript代码片段示例
import HMSAGGRPAY from '@hw-hmscore/hms-payment';
async pay() {
// orderStr云测调用预下单接口获取prepayId后生成,具体请查接入文档和服务器demo看,此处仅做格式参考
const orderStr = "{\"merc_no\":\"**\",\"prepay_id\":\"***\",\"timestamp\":\"**\",\"noncestr\":\"**\",\"sign\":\"**\",\"auth_id\":\"**\"}";
HMSPAYMENT.pay(orderStr).then(res => {
console.log("pay res: "+ JSON.stringify(res));
if (res.errCode == "0") {
this.dealPayResult(res);
} else {
console.log("combinedPay err: "+ res.errMsg);
}
}).catch(err => {
console.log("pay err: "+ JSON.stringify(err));
this.toast("支付失败")
})
},
async combinedPay() {
// orderStr云测调用合单支付预下单接口获取prepayId后生成,具体请查接入文档和服务器demo看,此处仅做格式参考
const orderStr = "{\"merc_no\":\"**\",\"prepay_id\":\"***\",\"timestamp\":\"**\",\"noncestr\":\"**\",\"sign\":\"**\",\"auth_id\":\"**\"}";;
HMSPAYMENT.combinedPay(orderStr).then(res => {
console.log("combinedPay res: "+ JSON.stringify(res));
if (res.errCode == "0") {
this.dealPayResult(res);
} else {
console.log("combinedPay err: "+ res.errMsg);
}
}).catch(err => {
console.log("combinedPay err: "+ JSON.stringify(err));
})
},
async signContract() {
// contractStr云测调用预签约接口获取preSignNo,具体请查接入文档和服务器demo看,此处仅做格式参考
const contractStr = "{\"preSignNo\":\"****\"}";
HMSPAYMENT.signContract(contractStr).then(res => {
console.log("signContract res: "+ JSON.stringify(res));
if (res.errCode == "0") {
let signResult = JSON.parse(JSON.stringify(res.data));
const { returnCode } = JSON.parse(signResult.ContractResult);
console.log("sign err: "+ returnCode);
// 如果returnCode="0",表示成功,注意:为了支付安全,请以服务器的通知或查询结果为准。
if (returnCode == "0") {
this.toast("签约成功")
} else {
this.toast("签约失败")
}
} else {
console.log("combinedPay err: "+ res.errMsg);
}
}).catch(err => {
console.log("signContract err: "+ JSON.stringify(err));
})
},
toast(msg) {
prompt.showToast({
message: msg
})
},
dealPayResult(res) {
let payResult = JSON.parse(JSON.stringify(res.data));
const { returnCode } = JSON.parse(payResult.PayResult);
console.log("pay err: "+ returnCode);
// 如果returnCode="0",表示成功,注意:为了支付安全,请以服务器的通知或查询结果为准。
if (returnCode == "0") {
this.toast("支付成功")
} else {
this.toast("支付失败")
}
}