使用uniapp開發(fā)小程序時,調(diào)用微信支付的步驟如下:
第一步、manifest.json里配置相關(guān)參數(shù)
1.在manifest.json - App模塊權(quán)限選擇 中勾選 payment(支付)
2.在 manifest.json - App SDK配置 中,勾選需要的支付平臺,目前有微信支付、支付寶支付、蘋果應(yīng)用內(nèi)支付(IAP),其中微信支付需要填寫從微信開放平臺獲取的
文章來源:http://www.zghlxwxcb.cn/news/detail-523739.html
第二步、代碼
1.微信小程序支付-代碼:
這里的timeStamp, nonceStr, package, signType, paySign是由后端與微信交互生成后,通過接口傳遞過來的,調(diào)用接口直接取出來即可。文章來源地址http://www.zghlxwxcb.cn/news/detail-523739.html
<view class="footbut" @tap="payBtn(goodsdetail.id)">立即購買</view>
// ①立即購買-訂單提交
payBtn(id) {
var that = this;
var data = {
id:id
}
this.$api.appPlateForm('POST', this.$url.url.wx_order_submit, data, function(res) {
console.log("訂單提交", res)
that.payment(res.data.order_id) //調(diào)用支付接口
})
},
//②支付接口
payment(order_id) {
var that = this;
var data = {
order_id: order_id
}
this.$api.appPlateForm('POST',this.$url.url.wx_order_paydata, data, function(res) {
console.log("訂單提交", res)
uni.requestPayment({
provider: 'wxpay', //支付類型-固定值
timeStamp: res.data.timeStamp, // 時間戳(單位:秒)
nonceStr: res.data.nonceStr, // 隨機字符串
package: res.data.package, // 固定值
signType: res.data.signType, //固定值
paySign: res.data.paySign, //簽名
success: function(res) {
// console.log('success:' + JSON.stringify(res));
console.log("支付成功");
uni.showToast({
icon: 'success',
title: '支付成功'
})
//清空輸入框
that.name = ''
that.idcard = ''
//2秒后跳轉(zhuǎn)訂單列表
setTimeout(() => {
uni.navigateTo({url:'/pages/shop/uni_order'})}, 2000)
},
fail: function(err) {
// console.log('fail:' + JSON.stringify(err));
console.log("支付失敗");
uni.showToast({
icon: 'none',
title: '支付失敗'
})
// //2秒后返回
// setTimeout(() => {uni.navigateBack() }, 2000)},
});
})
},
2.APP支付代碼:
//訂單對象,從服務(wù)器獲取
var orderInfo = {
"appid": res.data.orderInfo.appId, // 應(yīng)用ID(AppID)
"partnerid": res.data.orderInfo.partnerId, // 商戶號(PartnerID)
"prepayid": res.data.orderInfo.prepayId, // 預(yù)支付交易會話ID
"package": res.data.orderInfo.packageValue, // 固定值
"noncestr": res.data.orderInfo.nonceStr, // 隨機字符串
"timestamp": res.data.orderInfo.timeStamp, // 時間戳(單位:秒)
"sign": res.data.orderInfo.sign, // 簽名,這里用的 MD5 簽名
};
uni.requestPayment({
provider: "wxpay",
orderInfo: orderInfos,
success(res) {
console.log('success:' + JSON.stringify(res));
console.log("支付成功");
},
fail(err) {
console.log('fail:' + JSON.stringify(err));
console.log("支付失敗");
});
完成~
到了這里,關(guān)于【uniapp調(diào)用微信支付】uniapp開發(fā)小程序-調(diào)用微信支付的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!