onlinepay.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. $(function () {
  2. });
  3. //订单倒计时
  4. var maxtime = 5 * 60; //
  5. var state = true; //
  6. function CountDown() {
  7. if (maxtime >= 0) {
  8. minutes = Math.floor(maxtime / 60);
  9. seconds = Math.floor(maxtime % 60);
  10. msg = "距离结束还有" + minutes + "分" + seconds + "秒";
  11. document.getElementById('minute_show').innerText = minutes + "分";
  12. document.getElementById('second_show').innerText = seconds + "秒";
  13. /*if (maxtime == 1 * 60) alert("订单还有1分钟失效");
  14. */
  15. --maxtime;
  16. } else {
  17. clearInterval(timers);
  18. state = false;
  19. document.getElementById('imgCode2').src = '/static/zzpay/img/qrcode_timeout.png';
  20. document.getElementById('imgCode3').src = '/static/zzpay/img/qrcode_timeout.png';
  21. if (window.confirm('订单已失效,是否重新生成')) {
  22. window.location.reload();
  23. return true;
  24. } else {
  25. return false;
  26. }
  27. }
  28. }
  29. timers = setInterval("CountDown()", 1000);
  30. //循环执行,每隔20秒钟执行一次showalert()
  31. //window.setInterval(showalert, 5000);
  32. function showalert() {
  33. var orderId = document.getElementById("orderId").value;
  34. if (orderId != null && orderId != "undefined") {
  35. checkPayResult(orderId);
  36. }
  37. }
  38. var timer = null;
  39. var count = 5;
  40. timer = setInterval(function () {
  41. if (state == true) {
  42. count--;
  43. $('.resultMsg').text(count + '秒后自动获取支付结果');
  44. if (count <= 0) {
  45. count = 5
  46. $('.resultMsg').text('5秒后自动获取支付结果');
  47. }
  48. } else {
  49. clearInterval(timer)
  50. }
  51. }, 1000);
  52. /*支付状态查询,不建议这种写法。只是为了简单版本演示
  53. 1、请api接入
  54. 2、在您的服务端请求支付状态查询
  55. 3、js页面请求您自己服务端的付款状态查询接口
  56. */
  57. function checkPayResult(orderId) {
  58. $
  59. .ajax({
  60. url: "https://admin.zhanzhangfu.com/order/onlinePayFindResult?orderId=" + orderId,
  61. dataType: "json",
  62. type: "post",
  63. success: function (obj) {
  64. if (obj.code == "10001") {
  65. //支付完成,定时器关闭
  66. clearInterval(timer)
  67. document.getElementById('imgCode2').src = '/static/zzpay/img/qrcode_paysuccess.jpg';
  68. document.getElementById('imgCode3').src = '/static/zzpay/img/qrcode_paysuccess.jpg';
  69. if (window.confirm('支付成功')) {
  70. window.location.reload();
  71. //alert("确定");
  72. return true;
  73. } else {
  74. //alert("取消");
  75. return false;
  76. }
  77. } else if (obj.code == "10003") {
  78. if (window.confirm('订单已经失效,是否重新生成订单')) {
  79. //alert("确定");
  80. window.location.reload();
  81. return true;
  82. } else {
  83. //alert("取消");
  84. return false;
  85. }
  86. } else {
  87. }
  88. },
  89. error: function (obj) {
  90. alert("未知异常,稍后重试!");
  91. }
  92. });
  93. }