var wxChannel = null; // 微信支付 var aliChannel = null; // 支付寶支付 //獲取支付通道 plus.payment.getChannels(function(channels) { for (var i in channels) { if (channels[i].id == "wxpay") { wxChannel = channels[i]; } else { aliChannel = channels[i]; } } }, function(e) { alert("獲取支付通道失敗:" + e.message); });
在ajax請求(注意這時要傳遞,金額和支付方式)本身的後臺返回,相似下面的JSON字符串或對象均可以javascript
{"appid":"wx0411fa6a39d61297","noncestr":"skE6E936BYG6lC3a","package":"Sign=WXPay","partnerid":"1230636401","prepayid":"wx15091340429325c50c1239131980426900","timestamp":1560561220,"sign":"253C3449B8EE2B0F15C612E4F068F668"}
plus.payment.request(aliChannel, data.data, function(result) { plus.nativeUI.alert('支付成功!', function() { mui.back(); }, '充值'); }, function(e) { plus.nativeUI.alert('更多錯誤信息請參考支付(Payment)規範文檔:http://www.html5plus.org/#specification#/specification/Payment.html', null, '支付失敗:' + e.code); });
其中:aliChannel是上面的值,data.data就是JSON字符串或對象.若是不出意外的話都沒有問題的。html