微信扫码支付模式二支付状态Ajax轮询实例

来源:互联网 发布:windows镜像文件下载 编辑:程序博客网 时间:2024/06/05 08:10

Ajax 轮训支付状态代码:

<span style="font-size:18px;"><script>    //设置每隔1000毫秒执行一次load() 方法    setInterval(function(){load()},1000);    function load(){    var xmlhttp;          if (window.XMLHttpRequest){              // code for IE7+, Firefox, Chrome, Opera, Safari              xmlhttp=new XMLHttpRequest();          }else{              // code for IE6, IE5              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");          }          xmlhttp.onreadystatechange=function(){              if (xmlhttp.readyState==4 && xmlhttp.status==200){              trade_state=xmlhttp.responseText;            if(trade_state=='SUCCESS'){                document.getElementById("myDiv").innerHTML='支付成功';                document.getElementById('green').style.background="green";                //alert(transaction_id);                //延迟3000毫秒执行tz() 方法                setTimeout(function(){tz()},3000);                function tz(){                window.location.href="要跳转的URL路径";                    }                }else if(trade_state=='REFUND'){                document.getElementById("myDiv").innerHTML='转入退款';                }else if(trade_state=='NOTPAY'){                document.getElementById("myDiv").innerHTML='请扫码支付';                                }else if(trade_state=='CLOSED'){                document.getElementById("myDiv").innerHTML='已关闭';                }else if(trade_state=='REVOKED'){                document.getElementById("myDiv").innerHTML='已撤销';                }else if(trade_state=='USERPAYING'){                document.getElementById("myDiv").innerHTML='用户支付中';                }else if(trade_state=='PAYERROR'){                document.getElementById("myDiv").innerHTML='支付失败';                }                        }          }          //orderquery.php 文件返回订单状态,通过订单状态确定支付状态        xmlhttp.open("POST","orderquery.php",true);          //下面这句话必须有          //把标签/值对添加到要发送的头文件。          xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");          xmlhttp.send("out_trade_no=<?php echo $payment_notice['notice_sn'];?>");         }    </script></span>


3 0
原创粉丝点击