本文實(shí)例為大家分享了php微信掃碼支付成功之后自動(dòng)跳轉(zhuǎn)的具體代碼,供大家參考,具體內(nèi)容如下
場(chǎng)景: PC端 微信掃碼支付
結(jié)果: 支付成功 自動(dòng)跳轉(zhuǎn)
實(shí)現(xiàn)思路:
支付二維碼頁(yè)面,寫(xiě)ajax請(qǐng)求支付狀態(tài),請(qǐng)求到結(jié)果,無(wú)論成功還是失敗,都跳轉(zhuǎn)到相應(yīng)的結(jié)果頁(yè)面
具體實(shí)現(xiàn)方法:
html部分:
支付結(jié)果狀態(tài)設(shè)定: 0 未支付 1 支付成功 2 支付失敗
<input type="hidden" id="order_id" value="<?php echo $order_id;?>"> <script type="text/javascript"> function pay_status(){ var order_id = $("#order_id").val(); $.ajax({ url:'http://' + window.location.host+ '/home/cart/pay_status_check', dataType:'json', type:'post', data:{'order_id':order_id}, success:function(data){ if(data == '1' ){ window.clearInterval(int); //銷(xiāo)毀定時(shí)器 setTimeout(function(){ //跳轉(zhuǎn)到結(jié)果頁(yè)面,并傳遞狀態(tài) window.location.href="http://" rel="external nofollow" rel="external nofollow" +window.location.host+"/home/cart/pay_result?pay_status=success"; },1000) }else if(data =='2'){ window.clearInterval(int); //銷(xiāo)毀定時(shí)器 setTimeout(function(){ //跳轉(zhuǎn)到結(jié)果頁(yè)面,并傳遞狀態(tài) window.location.href="http://" rel="external nofollow" rel="external nofollow" +window.location.host+"/home/cart/pay_result?pay_status=fail"; },1000) } }, error:function(){ alert("error"); }, }); } //啟動(dòng)定時(shí)器 var int=self.setInterval(function(){pay_status()},1000); </script>
PHP 部分:
//支付狀態(tài)檢測(cè) public function pay_status_check(){ $order_id = I("order_id"); $result = M('table')->where("order_id = $order_id")->find(); echo $result['pay_status']; }
基礎(chǔ)功能就這些,如果想效果好看一點(diǎn),可以再加一些樣式,比如:支付成功,加一個(gè)對(duì)號(hào)的動(dòng)畫(huà)!
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持。
【網(wǎng)站聲明】本站除付費(fèi)源碼經(jīng)過(guò)測(cè)試外,其他素材未做測(cè)試,不保證完整性,網(wǎng)站上部分源碼僅限學(xué)習(xí)交流,請(qǐng)勿用于商業(yè)用途。如損害你的權(quán)益請(qǐng)聯(lián)系客服QQ:2655101040 給予處理,謝謝支持。