接口程序文件源碼:wxpay.asp
' 注意:本頁面必須是 UTF-8編碼
' 本頁面為偽代碼,代碼不全,僅是為了演示用法
set wechat = new WeChatPay()
out_trade_no = request("trade_no")
set rs.open "select * from order_list where o_status='未支付' and o_tradeno='" & out_trade_no & "'", conn, 3, 2
'創建支付
if request("action") = "ajax" then
'創建訂單
if rs.eof then
result = wechat.Pay("訂單號", "產品名", "不需要傳值,此值暫時無用,為了與支付寶保持兼容", "支付金額,單位元")
if left(result, 15) = "weixin://wxpay/" then
'支付成功,返回 支付鏈接,通過前臺 ajax 返回到前臺,通過 jQuery.qrcode 插件二維碼
response.write "{""status"":true, ""payUrl"":""" & result & """}"
else
'支付失敗,返回錯誤信息
response.write "{""status"":false, ""errMsg"":""" & result & """}"
end if
else
response.write "{""status"":false, ""errMsg"":""已經處理完畢""}"
end if
else request("action") = "check" then
'檢查支付狀態,【微信支付后臺通知(異步)】設為 完成后,返回成功
'如果 當前訂單不是 未支付狀態了,說明已經支付
if rs.eof then
response.write "{""status"":true}""
else
response.write "{""status"":false}""
end if
else
'微信支付后臺通知(異步)
set result = wechat.GetNotify()
if result.item("status") = false then
'校驗失敗
response.write result.item("message")
else
'校驗成功,修改o_status為已支付
if not rs.eof then
rs("wx_tradeno") = trade_no
rs("o_paytme") = now()
rs("o_status") = "已支付"
rs.update
end if
response.write "<return_code>SUCCESS</return_code><return_msg>OK</return_msg>"
end if
end if
3.Ajax前臺創建支付請求和刷新訂單狀態的方法
$(function(){
$.ajax({
url : "/wxapi.asp?action=ajax&trade_no=<% =trade_no %>",
dataType : "json",
type : "GET",
success : function(result){
if( result.status != true ){
alert(result.errMsg);
}else{
jQuery('#qrcodeCanvas').html("").qrcode({
text : result.payUrl
});
setTimeout(function(){
jQuery('#qrcodeImage img').attr("src", $("#qrcodeCanvas canvas")[0].toDataURL("image/png"));
}, 100);
setInterval(function(){
$.ajax({
url : "/wxapi.asp?action=check&trade_no=<% =trade_no %>",
dataType : "json",
success : function(result){
if( result.status === false ){
alert("支付成功");
location.href = "?action=info&trade_no=<% =trade_no %>";
}
}
});
}, 5000);
}
}
});
})