接口程序文件源码: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);
}
}
});
})