PC端微信掃碼支付成功後自動跳轉php版代碼分享

來源:互聯網
上載者:User
情境: PC端 掃碼支付

結果: 支付成功 自動跳轉

本文主要和大家詳細介紹了掃碼支付成功之後自動跳轉php版代碼,具有一定的參考價值,感興趣的小夥伴們可以參考一下,希望能協助到大家。

實現思路:

支付二維碼頁面,寫ajax請求支付狀態,請求到結果,無論成功還是失敗,都跳轉到相應的結果頁面

具體實現方法:

html部分:

支付結果狀態設定: 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); //銷毀定時器        setTimeout(function(){          //跳轉到結果頁面,並傳遞狀態          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); //銷毀定時器        setTimeout(function(){          //跳轉到結果頁面,並傳遞狀態          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");          },   });}//啟動定時器var int=self.setInterval(function(){pay_status()},1000);</script>

PHP 部分:


//支付狀態檢測  public function pay_status_check(){    $order_id = I("order_id");    $result = M('table')->where("order_id = $order_id")->find();    echo $result['pay_status'];  }

基礎功能就這些,如果想效果好看一點,可以再加一些樣式,比如:支付成功,加一個對號的動畫!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.