var qs = parseQueryString(window.location.href),type,reason,order_id,timeNumber = 0,flag = false; //timeNumber 2秒后不再轮训 flag判断是否已经有回调 $().ready(function(){ if(qs.type){type = qs.type}//1为成功 2为失败 3为充值中 if(qs.reason){reason = decodeURIComponent(qs.reason)} if(qs.order_id){order_id = qs.order_id} if(type == 1){ $('.paymentSuccess').show() paySuccessEvent(); } if(type == 2){ $('.paymentErrer').show() // $('.paymentFail .hint').html(reason) } if(type == 3){ $('.paymentIng').show() wxCheckOrder(function () { setTimeEvent(); }); } // if(navigator.userAgent.match(/android/i)){ // if(type == 3){ // visibilitychange_event(); // } // } }) // function visibilitychange_event () {//判断是否切出浏览器 // document.addEventListener('visibilitychange',function(){ // var isHidden = document.hidden; // if(isHidden){ // // document.title = '死鬼,你去哪儿了'; // } else { // if(type == 3 && !flag){ // timeNumber = 0; // flag = false; // $('.paymentErrer').hide() // $('.paymentIng').show() // $('.paymentSuccess').hide() // wxCheckOrder(function () { // setTimeEvent(); // }); // } // } // }); // } function setTimeEvent () { setTimeout(function () { if(timeNumber >= 2){ // window.location.href = 'paymentResult.html?type=2' $('.paymentErrer').show() $('.paymentIng').hide() $('.paymentSuccess').hide() //充值失败 return; } timeNumber+=1; if(!flag){ //还没充值成功 wxCheckOrder(setTimeEvent()); } },1000) } function wxCheckOrder (cb) { //查询订单是否支付成功 $.ajax({ url:'/user/wx_check_order', type:'post', dataType:'json', data:{ client:1, order_id:order_id }, success: function (res){ if(res && res.errno == 0){ // window.location.href = 'paymentResult.html?type=1' $('.paymentErrer').hide() $('.paymentIng').hide() $('.paymentSuccess').show() paySuccessEvent(); flag = true;//充值成功 }else{ // window.location.href = 'paymentResult.html?type=2' } cb?cb():''; }, error: function (err){ console.log(err) cb?cb():''; } }) } function skipGrap () { var param = '{"js" : "no"}'; try{ if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){ window.webkit.messageHandlers.skipGrapVC.postMessage(param); } if(navigator.userAgent.match(/android/i)){ obj4H5.skipGrapVC(param); } }catch(e){ console.log("兼容") } } function paySuccessEvent () { //支付成功----告诉app var param = '{"js" : "no"}'; try{ // if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){ // window.webkit.messageHandlers.PaySuccess.postMessage(param); // }// ios暂时不需要 if(navigator.userAgent.match(/android/i)){ obj4H5.PaySuccess(param); } }catch(e){ console.log("兼容") } } //获取地址栏参数 function parseQueryString(url) { var urlObj = {}; var reg = /([^?=&]+)=([^?=&]+)/g; url.replace(reg, function($0, $1, $2) { urlObj[$1] = decodeURIComponent($2); }) return urlObj; } // 展示错误提示信息 function showMsg(msg) { var msgBox = document.getElementsByClassName('alert-info')[0]; msgBox.getElementsByTagName("p")[0].innerHTML=msg; msgBox.style.display="block"; setTimeout(function() { msgBox.style.display="none"; }, 2000); }