Geen omschrijving

paymentResult.js 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. var qs = parseQueryString(window.location.href),type,reason,order_id,timeNumber = 0,flag = false;
  2. //timeNumber 2秒后不再轮训 flag判断是否已经有回调
  3. $().ready(function(){
  4. if(qs.type){type = qs.type}//1为成功 2为失败 3为充值中
  5. if(qs.reason){reason = decodeURIComponent(qs.reason)}
  6. if(qs.order_id){order_id = qs.order_id}
  7. if(type == 1){
  8. $('.paymentSuccess').show()
  9. paySuccessEvent();
  10. }
  11. if(type == 2){
  12. $('.paymentErrer').show()
  13. // $('.paymentFail .hint').html(reason)
  14. }
  15. if(type == 3){
  16. $('.paymentIng').show()
  17. wxCheckOrder(function () {
  18. setTimeEvent();
  19. });
  20. }
  21. // if(navigator.userAgent.match(/android/i)){
  22. // if(type == 3){
  23. // visibilitychange_event();
  24. // }
  25. // }
  26. })
  27. // function visibilitychange_event () {//判断是否切出浏览器
  28. // document.addEventListener('visibilitychange',function(){
  29. // var isHidden = document.hidden;
  30. // if(isHidden){
  31. // // document.title = '死鬼,你去哪儿了';
  32. // } else {
  33. // if(type == 3 && !flag){
  34. // timeNumber = 0;
  35. // flag = false;
  36. // $('.paymentErrer').hide()
  37. // $('.paymentIng').show()
  38. // $('.paymentSuccess').hide()
  39. // wxCheckOrder(function () {
  40. // setTimeEvent();
  41. // });
  42. // }
  43. // }
  44. // });
  45. // }
  46. function setTimeEvent () {
  47. setTimeout(function () {
  48. if(timeNumber >= 2){
  49. // window.location.href = 'paymentResult.html?type=2'
  50. $('.paymentErrer').show()
  51. $('.paymentIng').hide()
  52. $('.paymentSuccess').hide()
  53. //充值失败
  54. return;
  55. }
  56. timeNumber+=1;
  57. if(!flag){
  58. //还没充值成功
  59. wxCheckOrder(setTimeEvent());
  60. }
  61. },1000)
  62. }
  63. function wxCheckOrder (cb) {
  64. //查询订单是否支付成功
  65. $.ajax({
  66. url:'/user/wx_check_order',
  67. type:'post',
  68. dataType:'json',
  69. data:{
  70. client:1,
  71. order_id:order_id
  72. },
  73. success: function (res){
  74. if(res && res.errno == 0){
  75. // window.location.href = 'paymentResult.html?type=1'
  76. $('.paymentErrer').hide()
  77. $('.paymentIng').hide()
  78. $('.paymentSuccess').show()
  79. paySuccessEvent();
  80. flag = true;//充值成功
  81. }else{
  82. // window.location.href = 'paymentResult.html?type=2'
  83. }
  84. cb?cb():'';
  85. },
  86. error: function (err){
  87. console.log(err)
  88. cb?cb():'';
  89. }
  90. })
  91. }
  92. function skipGrap () {
  93. var param = '{"js" : "no"}';
  94. try{
  95. if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){
  96. window.webkit.messageHandlers.skipGrapVC.postMessage(param);
  97. }
  98. if(navigator.userAgent.match(/android/i)){
  99. obj4H5.skipGrapVC(param);
  100. }
  101. }catch(e){
  102. console.log("兼容")
  103. }
  104. }
  105. function paySuccessEvent () {
  106. //支付成功----告诉app
  107. var param = '{"js" : "no"}';
  108. try{
  109. // if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){
  110. // window.webkit.messageHandlers.PaySuccess.postMessage(param);
  111. // }// ios暂时不需要
  112. if(navigator.userAgent.match(/android/i)){
  113. obj4H5.PaySuccess(param);
  114. }
  115. }catch(e){
  116. console.log("兼容")
  117. }
  118. }
  119. //获取地址栏参数
  120. function parseQueryString(url) {
  121. var urlObj = {};
  122. var reg = /([^?=&]+)=([^?=&]+)/g;
  123. url.replace(reg, function($0, $1, $2) {
  124. urlObj[$1] = decodeURIComponent($2);
  125. })
  126. return urlObj;
  127. }
  128. // 展示错误提示信息
  129. function showMsg(msg) {
  130. var msgBox = document.getElementsByClassName('alert-info')[0];
  131. msgBox.getElementsByTagName("p")[0].innerHTML=msg;
  132. msgBox.style.display="block";
  133. setTimeout(function() {
  134. msgBox.style.display="none";
  135. }, 2000);
  136. }