參考:https://www.cnblogs.com/H5App/articles/7279373.html
plus API使用步驟:
1. 調用plus.payment.getChannels()獲取系統支持的支付通道;
2. 調用plus.payment.request()發起支付請求。
示例代碼:
1 var channel=null; 2 // 1. 獲取支付通道 3 function plusReady(){ 4 // 獲取支付通道 5 plus.payment.getChannels(function(channels){ 6 channel=channels[0]; 7 },function(e){ 8 alert("獲取支付通道失敗:"+e.message); 9 }); 10 } 11 document.addEventListener('plusready',plusReady,false); 12 13 var ALIPAYSERVER='http://demo.dcloud.net.cn/helloh5/payment/alipay.php?total=';//支付寶支付接口 14 var WXPAYSERVER='http://demo.dcloud.net.cn/helloh5/payment/wxpay.php?total='; //微信支付接口 15 // 2. 發起支付請求 在用戶輸完金額和選完支付方式后可以執行此函數 16 function pay(id){ 17 // 從服務器請求支付訂單 18 var PAYSERVER=''; 19 if(id=='alipay'){ 20 PAYSERVER=ALIPAYSERVER; 21 }else if(id=='wxpay'){ 22 PAYSERVER=WXPAYSERVER; 23 }else{ 24 plus.nativeUI.alert("不支持此支付通道!",null,"捐贈"); 25 return; 26 } 27 var xhr=new XMLHttpRequest(); 28 xhr.onreadystatechange=function(){ 29 switch(xhr.readyState){ 30 case 4: 31 if(xhr.status==200){ 32 plus.payment.request(channel,xhr.responseText,function(result){ 33 plus.nativeUI.alert("支付成功!",function(){ 34 back(); 35 }); 36 },function(error){ 37 plus.nativeUI.alert("支付失敗:" + error.code); 38 }); 39 }else{ 40 alert("獲取訂單信息失敗!"); 41 } 42 break; 43 default: 44 break; 45 } 46 } 47 xhr.open('GET',PAYSERVER); 48 xhr.send(); 49 }