1.首先要在HBuilder X 找到 manifest.json 找到App 模块配置 把Payment(支付) 勾选上
2.如果跟你合作的后端技术可以 那么前端实现起来 就非常简单 话不多说 上代码
if (this.payType == "支付宝支付") {
userpay({//首先 调用后端的支付接口 换取订单信息 把后端需要的字段传过去
uid: this.userInfo.id,
bill_orderSn: this.bill_orderSn,
pay_type: this.userInfo.pay_type,
gate_id: this.userInfo.gate_id,
amount: this.jine,
mer_cust_id: this.userInfo.bank_card
}).then(res => {
if (res.code == 1) {
//订单对象,从服务器获取 // 注意 如果是 支付宝支付provider固定值就是alipay
uni.requestPayment({ //拿到订单信息后 调用 uniapp的支付接口 唤起支付
provider: 'alipay', //微信就是 wxpay
orderInfo: res.data, //支付宝订单数据 从后端拿到的数据
success: function(res) {
this.show1 = false
uni.showToast({
title: "支付成功",
icon: 'success',
success: () => {
setTimeout(() => {
uni.switchTab({
url: '/pages/index/index'
})
}, 500)
}
})
},
fail: function(err) {
uni.showToast({
title: "支付失败请稍后再试",
icon: 'none',
success: () => {
setTimeout(() => {
uni.switchTab({
url: '/pages/my/my'
})
}, 500)
}
})
console.log('fail:' + JSON.stringify(err));
}
});
}
})
}
注意:app项目要在真机调试下 才能正常唤起支付 并且要配置的 一定不要少配置 否则问题会让你找的很头疼