微信扫码支付 -- 模式二
复制目录:cert , lib
支付页面:
//设置每隔1000毫秒执行一次load() 方法
var myIntval=setInterval(function(){load()},1000);
function load(){
document.getElementById("timer").innerHTML=parseInt(document.getElementById("timer").innerHTML)+1; //可选 秒+
$.post("orderquery.php", { 'out_trade_no':"<?php echo $buyid;?>",'mid': "<?php echo $cfg_ml->M_ID;?>";},function(res) {
trade_state = res;
if(trade_state=='SUCCESS'){
//'支付成功';
//延迟3000毫秒执行tz() 方法
setTimeout("location.href='success.php'",3000);
clearInterval(myIntval);
}else if(trade_state=='REFUND'){
//'转入退款';
}else if(trade_state=='NOTPAY'){
//'请扫码支付';
}else if(trade_state=='CLOSED'){
//'已关闭';
}else if(trade_state=='REVOKED'){
//'已撤销';
}else if(trade_state=='USERPAYING'){
//'用户支付中';
}else if(trade_state=='PAYERROR'){
//'支付失败';
}
});
}
<div id="myDiv"></div><div id="timer">0</div>
<?php
ini_set('date.timezone','Asia/Shanghai');
error_reporting(E_ERROR);
require_once "../路径/wepay/lib/WxPay.Api.php";
require_once "../路径/wepay/log.php";
//初始化日志
$logHandler= new CLogFileHandler("./logs/".date('Y-m-d').'.log');
$log = Log::Init($logHandler, 15);
function printf_info($data)
{
foreach($data as $key=>$value){
echo "<font color='#f00;'>$key</font> : $value <br/>";
}
}
if(isset($_REQUEST["transaction_id"]) && $_REQUEST["transaction_id"] != ""){
$transaction_id = $_REQUEST["transaction_id"];
$input = new WxPayOrderQuery();
$input->SetTransaction_id($transaction_id);
//printf_info(WxPayApi::orderQuery($input));
$result=WxPayApi::orderQuery($input);
echo $result['trade_state'];
exit();
}
if(isset($_REQUEST["out_trade_no"]) && $_REQUEST["out_trade_no"] != ""){
$out_trade_no = $_REQUEST["out_trade_no"];
$input = new WxPayOrderQuery();
$input->SetOut_trade_no($out_trade_no);
//printf_info(WxPayApi::orderQuery($input));
$result=WxPayApi::orderQuery($input);
if($result['trade_state'] == 'SUCCESS'){
//支付成功操作
echo $result['trade_state'];
exit();
}
?>