PHP PC端微信扫码支付【模式二】详细教程-附带源码(转) (2)

设置微信支付demo中的扫码支付文件 payment/example/native.php

//在大概19行找到该代码 $notify = new NativePay(); 并在下方添加获取商品名字和商品价格的代码 // 接收get过来的商品价格和名称 $goodsPrice = $_GET[\'goodsPrice\']; $goodsName = $_GET[\'goodsName\']; //下面修改从第32号开始的一大堆$input开头的 $input = new WxPayUnifiedOrder(); $input->SetBody($goodsName);//商品名称 $input->SetAttach("大姨妈商城");//自己设置 $num = WxPayConfig::MCHID.date("YmdHis");//订单号 $input->SetOut_trade_no($num); $input->SetTotal_fee($goodsPrice*100);//注意!!!!!!!!!由于是以分为单位结算,所以一定要记得商品价格*100;别到时候下岗了来怪撸主 $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetGoods_tag($goodsName);//下面的这些参数大家自己看一下文档吧!意义都不大,撸主肾虚,要早点写完早点睡! $input->SetNotify_url("/payment/example/notify.php"); $input->SetTrade_type("NATIVE"); $input->SetProduct_id("123456789"); $result = $notify->GetPayUrl($input); //print_r($result);//最终的信息,大家可以打印了进行调试 $url2 = $result["code_url"]; // ok!整个文件的PHP代码就完毕了!在这以下的html代码全部把它干掉,把撸主准备的这段贴上去 这段代码不做什么解释了,也是用于查询订单状态的轮询,调试用的~!下面还会用到一次,讲的很详细 <html> <head> <meta http-equiv=http://www.likecs.com/"content-type" content=http://www.likecs.com/"text/html;charset=utf-8"/> <meta name=http://www.likecs.com/"viewport" content=http://www.likecs.com/"width=device-width, initial-scale=1" /> <title>微信支付样例</title> </head> <body> <div style=http://www.likecs.com/"margin-left: 10px;color:#556B2F;font-size:30px;font-weight: bolder;">扫描支付模式二</div><br/> <img alt=http://www.likecs.com/"||<?php echo $num?>||" src=http://www.likecs.com/"qrcode.php?data=<?php echo urlencode($url2);?>" style=http://www.likecs.com/"width:150px;height:150px;"/> <div id=http://www.likecs.com/"myDiv"></div><div id=http://www.likecs.com/"timer">0</div> </body> <script> //设置每隔1000毫秒执行一次load() 方法 var myIntval=setInterval(function(){load()},1000); function load(){ document.getElementById("timer").innerHTML=parseInt(document.getElementById("timer").innerHTML)+1; var xmlhttp; if (window.XMLHttpRequest){ // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=http://www.likecs.com/new XMLHttpRequest(); }else{ // code for IE6, IE5 xmlhttp=http://www.likecs.com/new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=http://www.likecs.com/function(){ if (xmlhttp.readyState==http://www.likecs.com/4 && xmlhttp.status==http://www.likecs.com/200){ trade_state=xmlhttp.responseText; if(trade_state==http://www.likecs.com/\'SUCCESS\'){ document.getElementById("myDiv").innerHTML=http://www.likecs.com/\'支付成功\'; //alert(transaction_id); //延迟3000毫秒执行tz() 方法 clearInterval(myIntval); setTimeout("location.href=http://www.likecs.com/\'success.php\'",3000); }else if(trade_state==http://www.likecs.com/\'REFUND\'){ document.getElementById("myDiv").innerHTML=http://www.likecs.com/\'转入退款\'; clearInterval(myIntval); }else if(trade_state==http://www.likecs.com/\'NOTPAY\'){ document.getElementById("myDiv").innerHTML=http://www.likecs.com/\'请扫码支付\'; }else if(trade_state==http://www.likecs.com/\'CLOSED\'){ document.getElementById("myDiv").innerHTML=http://www.likecs.com/\'已关闭\'; clearInterval(myIntval); }else if(trade_state==http://www.likecs.com/\'REVOKED\'){ document.getElementById("myDiv").innerHTML=http://www.likecs.com/\'已撤销\'; clearInterval(myIntval); }else if(trade_state==http://www.likecs.com/\'USERPAYING\'){ document.getElementById("myDiv").innerHTML=http://www.likecs.com/\'用户支付中\'; }else if(trade_state==http://www.likecs.com/\'PAYERROR\'){ document.getElementById("myDiv").innerHTML=http://www.likecs.com/\'支付失败\'; clearInterval(myIntval); } } } //orderquery.php 文件返回订单状态,通过订单状态确定支付状态 xmlhttp.open("POST","orderquery.php",false); //下面这句话必须有 //把标签/值对添加到要发送的头文件。 xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); xmlhttp.send("out_trade_no=<?php echo $num;?>"); } </script>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzpfxp.html