PC端微信掃碼支付成功之后自動(dòng)跳轉(zhuǎn)php版代碼
本文實(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í)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
PHP多線程批量采集下載美女圖片的實(shí)現(xiàn)代碼(續(xù))
之前寫(xiě)過(guò)一篇《PHP批量采集下載美女圖片》文中主要采用file_get_content做采集圖片,今天發(fā)現(xiàn)采集了400張圖片 居然需要70分鐘以上,真是難以忍受2013-06-06
發(fā)款php蜘蛛統(tǒng)計(jì)插件只要有mysql就可用
利用php-cli和任務(wù)計(jì)劃實(shí)現(xiàn)訂單同步功能的方法
php根據(jù)身份證號(hào)碼計(jì)算年齡的實(shí)例代碼
php慢查詢(xún)?nèi)罩竞湾e(cuò)誤日志使用詳解

