Home > Backend Development > PHP Tutorial > PHP example tutorial: Automatically jump after successful payment via WeChat scan code on PC

PHP example tutorial: Automatically jump after successful payment via WeChat scan code on PC

巴扎黑
Release: 2023-03-14 21:38:01
Original
4401 people have browsed it

This article mainly introduces in detail the code that automatically jumps to the PHP version after the WeChat scan code payment is successful. It has a certain reference value. Interested friends can refer to it.

The examples in this article are for everyone. Shared the specific code for php to automatically jump after successful WeChat scan code payment for your reference. The specific content is as follows

Scenario: PC side WeChat scan code payment

Result: Automatic jump after successful payment

Implementation idea:

On the payment QR code page, write ajax to request the payment status, request the result, and jump to the corresponding result page regardless of success or failure.

Specific implementation method:

html part:

Payment result status setting: 0 Unpaid 1 Payment successful 2 Payment failed


<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:&#39;http://&#39; + window.location.host+ &#39;/home/cart/pay_status_check&#39;,
    dataType:&#39;json&#39;, 
    type:&#39;post&#39;,  
    data:{&#39;order_id&#39;:order_id}, 
    success:function(data){  
      if(data == &#39;1&#39; ){
        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 ==&#39;2&#39;){
        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>
Copy after login

PHP part:


//支付状态检测
  public function pay_status_check(){
    $order_id = I("order_id");
    $result = M(&#39;table&#39;)->where("order_id = $order_id")->find();
    echo $result[&#39;pay_status&#39;];
  }
Copy after login

These are the basic functions. If you want the effect to look better, you can add some styles, such as: If the payment is successful, a check mark animation will be added!

The above is the detailed content of PHP example tutorial: Automatically jump after successful payment via WeChat scan code on PC. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template