初始化獲取支付通道
我用的是vue,首先先引入mui,hbuilder中設置支付寶支付,這裏不再敘述。
// 初始化
mui.plusReady(function() {
// 獲取支付通道
plus.payment.getChannels(function(channels){
that.aliChannel=channels[0];
that.wxChannel=channels[1];
},function(e){
mui.toast("獲取支付通道失敗:"+e.message);
});
})
//支付寶 微信支付
paymoney: function (name){
if(name=='wx'){
mui.toast('暫未開通,盡請期待');
return;
}
var that=this;
plus.nativeUI.showWaiting(); //加載圈
mui.post(this.GLOBAL.host+"/vip/improveVipLevel", { //後臺獲取請求字符串
userNumber:sessionStorage.getItem("kbj_userNumber"), //用戶標誌
payWay:"支付寶"
}, function(res) {
plus.nativeUI.closeWaiting();
if (res.code==0) {
plus.payment.request(that.aliChannel,res.data, function(result) {
mui.toast("付費成功");
}, function(e) {
mui.toast("付費失敗");
});
} else {
mui.toast("支付失敗");
}
});
}
如果後臺過來的字符串正常,這時候就可以正常實現支付了,如果不能支付,用安卓手機下載支付寶調試工具,輸入後臺給你的字符串,判斷是前端還是後端的問題。