调取支付页面代码
<div class=http://www.likecs.com/"goods_btn"> <div class=http://www.likecs.com/"buy" onclick=http://www.likecs.com/"GetPay()">立即购买</div> </div> <script type=http://www.likecs.com/"text/javascript"> //接入微信扫码支付 function GetPay() { //用ajax获取到支付的二维码 var payQrcode = \'http://www.likecs.com/\'; var payPrice = \'http://www.likecs.com/\'; var payOrderCode = \'http://www.likecs.com/\'; $.get(\'/getPayQrcode.php\',{"goodsId":"<?php echo $goodsInfo->id;?>"},function(ret){ var obj = JSON.parse(ret) if (obj.status == \'success\') { payQrcode = \'http://www.baidu.com\'+obj.msg; payPrice = obj.price; payOrderCode = obj.code; layer.open({ type: 1, skin: \'layui-layer-demo\', //样式类名 closeBtn: 0, //不显示关闭按钮 title:false, anim: 2, area: [\'300px\', \'450px\'], shadeClose: true, //开启遮罩关闭 content: \'<div>X</div>\'+\'<div><img src="http://www.likecs.com/images/wx.png" alt="" /><br><b>请打开微信 扫码进行支付 </b><div></div>支付金额:<span>\'+payPrice+\'</span> 元</div><div></div>\'+\'<div><img src="\'+payQrcode+\'"></div><div></div><div>0</div>\' }); // 设置每隔1000毫秒执行一次load() 方法 var myIntval=setInterval(function(){load()},1000); function load(){ //document.getElementById("timer").innerHTML=parseInt(document.getElementById("timer").innerHTML)+1; var xmlhttp; if (window.XMLHttpRequest){ // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=http://www.likecs.com/new XMLHttpRequest(); }else{ // code for IE6, IE5 xmlhttp=http://www.likecs.com/new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=http://www.likecs.com/function(){ if (xmlhttp.readyState==http://www.likecs.com/4 && xmlhttp.status==http://www.likecs.com/200){ trade_state=http://www.likecs.com/JSON.parse(xmlhttp.responseText); console.log(trade_state); if(trade_state.code==http://www.likecs.com/\'SUCCESS\'){ document.getElementById("myDiv").innerHTML=http://www.likecs.com/\'支付成功\'; //alert(transaction_id); //延迟3000毫秒执行tz() 方法 clearInterval(myIntval); setTimeout("location.href=http://www.likecs.com/\'./",1500); }else if(trade_state.code==http://www.likecs.com/\'REFUND\'){ document.getElementById("myDiv").innerHTML=http://www.likecs.com/\'转入退款\'; clearInterval(myIntval); }else if(trade_state.code==http://www.likecs.com/\'NOTPAY\'){ document.getElementById("myDiv").innerHTML=http://www.likecs.com/\'请扫码支付\'; }else if(trade_state.code==http://www.likecs.com/\'CLOSED\'){ document.getElementById("myDiv").innerHTML=http://www.likecs.com/\'已关闭\'; clearInterval(myIntval); }else if(trade_state.code==http://www.likecs.com/\'REVOKED\'){ document.getElementById("myDiv").innerHTML=http://www.likecs.com/\'已撤销\'; clearInterval(myIntval); }else if(trade_state.code==http://www.likecs.com/\'USERPAYING\'){ document.getElementById("myDiv").innerHTML=http://www.likecs.com/\'用户支付中\'; }else if(trade_state.code==http://www.likecs.com/\'PAYERROR\'){ document.getElementById("myDiv").innerHTML=http://www.likecs.com/\'支付失败\'; clearInterval(myIntval); } } } //orderquery.php 文件返回订单状态,通过订单状态确定支付状态 xmlhttp.open("POST","http://www.baidu.com/payment/example/orderquery.php",false); //下面这句话必须有 //把标签/值对添加到要发送的头文件。 xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); xmlhttp.send("out_trade_no="+payOrderCode+""); } }else{ layer.msg(\'请求失败!\', {icon: 5}); } }); } </script>