Scenario: PC-side sweep code payment
Result: The payment succeeds automatically jump
This article mainly and everyone in detail introduced the scan code after the success of the automatic jump PHP version of code, with a certain reference value, interested in the small partners can refer to, hope to help everyone.
Implementation ideas:
Pay the QR code page, write the AJAX request payment status, request to the result, regardless of success or failure, jump to the corresponding results page
Specific implementation methods:
HTML section:
Payment result status setting: 0 Unpaid 1 Payment Success 2 payment failure
<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);//Destroy Timer setTimeout (function () {//jumps to the results page and passes the status 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);//Destroy Timer setTimeout (function () { Jump to the results page and pass the Status 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"); }, });} Start timer var int=self.setinterval (function () {pay_status ()},1000);</script>
PHP section:
Payment status Detection public function Pay_status_check () { $order _id = I ("order_id"); $result = M (' table ')->where ("order_id = $order _id")->find (); echo $result [' pay_status ']; }
Basic functions on these, if you want to look good, you can add some style, such as: Pay success, plus a check the animation!