
在用uni-app開發(fā)小程序時(shí),需要使用微信小程序在線支付
處理發(fā)起支付流程如下
01. 向服務(wù)器發(fā)送微信小程序支付請求,發(fā)送的請教中,一定要帶上當(dāng)前小程序用戶的openid
將支付的錢與支付訂單號(hào)向后臺(tái)發(fā)送
02.后臺(tái)接收訂單內(nèi)容后,向微信支付平臺(tái)發(fā)一個(gè)請求,獲得如下內(nèi)容
以下是發(fā)送請教之后,支付程序返回的代碼
{
"data_state": "success",
"prompting": "下單成功",
"data_list": {
"appId": "wxc45312345678902",
"package": "prepay_id=wx31244255725616c79ca227f95eaee60000",
"timeStamp": "1612101428",
"nonceStr": "3Yl2Zn4Nl1Yf",
"signType": "MD5",
"paySign": "A5415FCF474F10C6D69DEF15C1FBC165",
"orderid": "kecen20210131215703698348"
}
}
03.以下是在頁面中解析代碼然后喚醒對應(yīng)的微信支付功能
let paydata = res.data.data_list;
uni.requestPayment({
nonceStr: paydata.nonceStr, // 隨機(jī)字符串 【字符串】
package: paydata.package, // 統(tǒng)一下單接口 必須加前綴:prepay_id=xxxxxxxx 【字符串】
paySign: paydata.paySign, // 簽名 【字符串】
signType: paydata.signType, // 簽名算法 【字符串】
timeStamp: paydata.timeStamp, // 時(shí)間戳 【字符串】
success: function (res) {
console.log('支付成功提示 success:' + JSON.stringify(res));
},
fail: function (err) {
console.log('支付失敗提示 fail:' + JSON.stringify(err));
},
complete:function(res){
//console.log('xxxxxxxxxxxxxxxxxx---complete')
}
});
利用uni-app中的uni.requestPayment發(fā)起調(diào)用微信支付請求
以下是介紹我的詳細(xì)代碼
getpagedata: function() {
this.$appajax.globalRequest('POST', getApp().qwbmurl + '/pay/weixin/miniapp.asp', {
buy_order: _self.pay_order, //支付訂單,里面包括了支付的費(fèi)用,支付的信息
openid: 'oM67Fv5pK1REqisNtMq5zVBkcd5Y' // + uni.getStorageSync('uu_openid'),
}).then(res => {
let show_state = res.data.state; //支付狀態(tài)
//支付失敗提示
if (show_state == "error") {
uni.showToast({title: unescape(res.data.prompting),icon: 'none'});
}
//支付成功處理
if (show_state == "success") {
uni.showToast({title: unescape(res.data.prompting),
icon: 'success'
});
let paydata = res.data.data_list;
uni.requestPayment({
nonceStr: paydata.nonceStr, // 隨機(jī)字符串 【字符串】
package: paydata.package, // 統(tǒng)一下單接口 必須加前綴:prepay_id=xxxxxxxx 【字符串】
paySign: paydata.paySign, // 簽名 【字符串】
signType: paydata.signType, // 簽名算法 【字符串】
timeStamp: paydata.timeStamp, // 時(shí)間戳 【字符串】
success: function (res) {
console.log('發(fā)起支付success:' + JSON.stringify(res));
},
fail: function (err) {
console.log('失敗支付fail:' + JSON.stringify(err));
},
complete:function(res){
//console.log('xxxxxxxxxxxxxxxxxx---complete')
}
});
}
});
},
您發(fā)布的評論即表示同意遵守以下條款:
一、不得利用本站危害國家安全、泄露國家秘密,不得侵犯國家、社會(huì)、集體和公民的合法權(quán)益;
二、不得發(fā)布國家法律、法規(guī)明令禁止的內(nèi)容;互相尊重,對自己在本站的言論和行為負(fù)責(zé);
三、本站對您所發(fā)布內(nèi)容擁有處置權(quán)。