一款PHP原生代碼寫的微信掃碼支付,不基於任何框架,徹底手寫。php
掃碼支付只要受權域名對就OK,本地是沒法測試。跟openid也沒有關係,因此跟支付受權目錄頁不要緊。html
1 const APPID = 'wx422126b0b6bbfcfc'; // 綁定支付的APPID(必須配置,開戶郵件中可查看) 2 const MCHID = '1349825901'; // 商戶號(必須配置,開戶郵件中可查看) 3 const KEY = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'; //商戶支付密鑰,參考開戶郵件設置(必須配置,登陸商戶平臺自行設置) 4 const APPSECRET = '45843e705995a12106155f4c26f716dc'; //APPSECRET:公衆賬號secert(僅JSAPI支付的時候須要配置, 登陸公衆平臺,進入開發者中心可設置)
1 $order_no = date("YmdHis") . rand(1000, 9999); //支付訂單號 2 $order_money = 0.01; //訂單金額 元 3 $url_notify = $url . "notify.php"; //微信回調地址
1 $order_no = $simple['out_trade_no'];//商戶訂單號 2 $third_id = $simple['transaction_id'];//微信流水號 3 $pay_money = $simple['total_fee'];//實際支付金額 4 if ($order_no) {//如果支付成功 ,訂單狀態state=1表示已支付成功 5 $query = mysql_query("UPDATE `order` SET `state` = '1',update_time='" . time() . "',trade_no='".$third_id."' WHERE `order_no` ='" . $order_no . "'"); 6 }
1 <script> 2 changeOrderStatues();//檢測訂單是否支付成功 3 function changeOrderStatues() { 4 var order_no = $("#order_no").val(); 5 6 $.post("check_order.php", {order_no: order_no}, function(data) { 7 if (data > 0) { 8 //訂單返回值大於0表示支付成功 9 alert("感謝您贊助,付款成功"); 10 location.href = "order_detail.php?order_no=" + order_no + ""; //支付成功後跳轉到訂單詳情頁 11 } 12 }) 13 setTimeout("changeOrderStatues()", 3000); 14 } 15 </script>
1 $order_no = isset($_POST['order_no']) ? $_POST['order_no'] : ""; 2 if ($order_no) { 3 $query = mysql_query("SELECT id FROM `order` WHERE order_no = '" . $order_no . "' AND state = 1 LIMIT 1"); 4 $row = mysql_fetch_array($query); 5 if ($row) { 6 echo $row['id'];//如果返回值,大於0則說明訂單支付成功 7 } 8 }
本實例教程轉自https://www.sucaihuo.com/php/1384.html,轉載請註明出處!mysql