uniapp實(shí)現(xiàn)微信公眾號(hào)支付的方法步驟
1、申請(qǐng)企業(yè)服務(wù)號(hào)(必須企業(yè)認(rèn)證)
2、獲取appid 和秘鑰
菜單 開發(fā)-基本配置 獲取秘鑰 、設(shè)置ip白名單

3、安全域名設(shè)置
進(jìn)入公眾號(hào)設(shè)置-功能設(shè)置配置

4、代碼實(shí)現(xiàn)
點(diǎn)擊請(qǐng)求優(yōu)先去請(qǐng)求后臺(tái)訂單支付接口數(shù)據(jù)
將獲取到的數(shù)據(jù)放入以下請(qǐng)求數(shù)據(jù)里面
callPay: function(response) {
if (typeof WeixinJSBridge === "undefined") {
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', this.onBridgeReady(response), false);
} else if (document.attachEvent) {
document.attachEvent('WeixinJSBridgeReady', this.onBridgeReady(response));
document.attachEvent('onWeixinJSBridgeReady', this.onBridgeReady(response));
}
} else {
this.onBridgeReady(response);
}
},
onBridgeReady: function(response) {
let that = this;
if (!response.package) {
return;
}
WeixinJSBridge.invoke(
'getBrandWCPayRequest', {
"appId": response.appid, //公眾號(hào)名稱,由商戶傳入
"timeStamp": response.timestamp, //時(shí)間戳,自1970年以來的秒數(shù)
"nonceStr": response.noncestr, //隨機(jī)串
"package": response.package,
"signType": response.signType, //微信簽名方式:
"paySign": response.sign //微信簽名
},
function(res) {
if (res.err_msg === "get_brand_wcpay_request:ok") {
// 使用以上方式判斷前端返回,微信團(tuán)隊(duì)鄭重提示:
//res.err_msg將在用戶支付成功后返回ok,但并不保證它絕對(duì)可靠。
uni.showLoading({
title: '支付成功'
});
setTimeout(function() {
uni.hideLoading();
uni.redirectTo({
url: '../member/orderdetail?id=' + that.id
});
}, 1000);
} else {
uni.hideLoading();
}
WeixinJSBridge.log(response.err_msg);
}
);
},到此這篇關(guān)于uniapp實(shí)現(xiàn)微信公眾號(hào)支付的方法步驟的文章就介紹到這了,更多相關(guān)uniapp 微信公眾號(hào)支付內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Quasar Input:type="number" 去掉上下小箭頭 實(shí)現(xiàn)加減按鈕樣式功能
這篇文章主要介紹了Quasar Input:type="number" 去掉上下小箭頭 實(shí)現(xiàn)加減按鈕樣式,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-04-04
關(guān)于document.cookie的使用javascript
構(gòu)造通用的cookie處理函數(shù) cookie的處理過程比較復(fù)雜,并具有一定的相似性。因此可以定義幾個(gè)函數(shù)來完成cookie的通用操作,從而實(shí)現(xiàn)代碼的復(fù)用。2010-10-10
一道優(yōu)雅面試題分析js中fn()和return fn()的區(qū)別
這篇文章主要帶領(lǐng)大家深入理解JavaScript中 fn() 和 return fn() 的區(qū)別,感興趣的小伙伴們可以參考一下2016-07-07
js 剪切板應(yīng)用clipboardData詳細(xì)解析
本篇文章主要介紹了js剪切板應(yīng)用clipboardData。需要的朋友可以過來參考下,希望對(duì)大家有所幫助2013-12-12

