PHP PC端微信扫码支付【模式二】详细教程-附带源码(转) (4)

点击支付按钮的代码

// 前段代码 样式用大家自己的就行,不用照抄 <div class=http://www.likecs.com/"goods_btn"> <div class=http://www.likecs.com/"buy" onclick=http://www.likecs.com/"GetPay()">立即购买</div> </div> // JS代码 js代码中嵌入的样式,无需修改!和效果图一样的! //接入微信扫码支付 function GetPay() { // 用ajax获取到支付的二维码 var payQrcode = \'http://www.likecs.com/\'; var payPrice = \'http://www.likecs.com/\'; var payOrderCode = \'http://www.likecs.com/\'; // 执行Ajax请求 $.get(\'/getPayQrcode.php\',{"goodsId":"商品的ID"},function(ret){ var obj = JSON.parse(ret) // 把字符串进行转换 // 判断返回数据是否正常(由于请求一般不会出问题,所以在获取二维码的getPayQrcode.php文件没有写返回fail) if (obj.status == \'success\') { payQrcode = \'http://www.baidu.com\'+obj.msg;//二维码链接 payPrice = obj.price; //商品价格 payOrderCode = obj.code; //交易码 //执行layer弹层 layer.open({ type: 1, skin: \'layui-layer-demo\', //样式类名,随意! closeBtn: 0, //不显示关闭按钮 title:false, //关闭title部分 anim: 2, area: [\'300px\', \'450px\'], //层的宽高 shadeClose: true, //开启遮罩关闭 content: \'<div style=http://www.likecs.com/"color: #666;margin: 5px 0 0 10px;position: absolute;right:.5rem;" onclick=http://www.likecs.com/"layer.closeAll()">X</div>\'+\'<div style=http://www.likecs.com/"text-align: center;"><img style=http://www.likecs.com/"width: 4rem;padding:2rem 0 1rem 0;" src=http://www.likecs.com/"{{ asset(\'./images/wx.png\') }}" alt=http://www.likecs.com/"" /><br><b style=http://www.likecs.com/"font-weight: 100;color: #888;">请打开微信 扫码进行支付 </b><div class=http://www.likecs.com/"blank"></div>支付金额:<span style=http://www.likecs.com/"color: red;">\'+payPrice+\'</span> 元</div><div class=http://www.likecs.com/"blank"></div>\'+\'<div style=http://www.likecs.com/"text-align: center"><img src=http://www.likecs.com/"\'+payQrcode+\'" class=http://www.likecs.com/"resize" style=http://www.likecs.com/"width:70%;"></div><div id=http://www.likecs.com/"myDiv" style=http://www.likecs.com/"width: 100%;height: 1.5rem;bottom: 2rem;position:absolute;text-align:center;font-size: 1.2rem;color: #04BE02;"></div><div id=http://www.likecs.com/"timer" style=http://www.likecs.com/"display:none;">0</div>\' }); // 轮询代码开始 // 设置每隔1000毫秒执行一次load() 方法 var myIntval=setInterval(function(){load()},1000); function load(){ 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=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);//打印查看轮询的状态,也可以关闭。 //判断订单支付状态 并用document.getElementById方法赋值到myDiv中; if(trade_state.code==http://www.likecs.com/\'SUCCESS\'){ document.getElementById("myDiv").innerHTML=http://www.likecs.com/\'支付成功\'; //延迟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}); } }); } // 上面的这段js代码稍微有点复杂,愿大家耐心看!撸主是js菜鸡、文盲、白痴;大佬们勿喷! ok!到此为止,整个流程就已经结束了!~上面的代码仅供参考!~下面撸主会贴出整套代码来造福社会!

原装进口代码,麻烦大家记得点赞、关注、收藏,谢谢!

此套代码是原生的php!大家随意用!

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzpfxp.html