ASP⽀付(V3⽀付)让更多ASP新⽼项⽬更加⽅便做社交电
商
ASP⽀付(V3⽀付)让更多ASP新⽼项⽬更加⽅便做社交电商。很多asp⽼项⽬⼀直运营的⽐较好,也不愿意去更换技术,今天我⽤我整理的常⽤WeixinDLL组件给⼤家讲解⽀付过程。
准备⼯作:
1、注册服务号(⼀定要认证)、开通⽀付
2、安装⽀付安全证书
此处介绍V3⽀付,⼀共是⽤三个执⾏⽂件代码进⾏讲解!
1、toPay.asp 发起⽀付
2、pay_ok.asp ⽀付成功页
3、notify.asp ⽀付成功过程服务器与我们的服务器通信,将⽀付结果数据推送到我们服务器上
页⾯:toPay.asp
1 <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
2
3 <%
4On Error Resume Next
5Dim notify_url,redirect_url,payapiurl,attach
6 notify_url = "www.domain/pay/notify.asp"'⽀付完成后将在后台发送回调处理信息,由本页⾯接受是否成功⽀付的信息
7 redirect_url = "www.doman/pay/pay_ok.asp"'⽀付完成后,跳转到本页⾯,⽤于展⽰订单⽀付提⽰,本页⾯可以⾃⼰修改
8 payapiurl = "h.weixin.qq/pay/unifiedorder"
9 body = "购买元森美⽔果酵素"'Trim(Request.Form("body")) ' 商品名称
10 total_fee = 0.01*100''Trim(Request.Form("total_fee"))*100 ' 以分为单位,⼊库前需要除以100
11 openid = OpenID 'Trim(Request.Form("openid")) ' "oK1dP1tPcSsh6xog898yXiuGlfaI" //测试openid
12 attach = "OnlinePay___1212"' ⽤于标记,⽅便在notify时进⾏数据库相关操作
13
14Dim WxObj,Md5Obj
15Set Md5Obj = Server.CreateObject("WeixinDLL.Md5Class")
16Set WxObj = Server.CreateObject("WeixinDLL.WeixinClass")
17 WxObj.SetAppID = C_AppID
18 WxObj.SetAppSecret = C_AppSecret
19 WxObj.SetMchid = C_mch_id
20 WxObj.SetMchKey = C_mch_key
21 WxObj.SetSoftCodeID = C_SoftCodeID
22 WxObj.SetMd5Obj = Md5Obj
23 WxObj.SetPayUrl = payapiurl
24
25' 通过函数获取参数
26Dim create_ip,timeStamp,nonce_str,out_trade_no,body,total_fee,openid,prepay_id,paySign
27 create_ip = WxObj.GetIP ' 当前⽤户⽹络IP地址
28 out_trade_no = WxObj.MakeRanNum(15) '唯⼀订单号,可以⾃⾏⽣成 "462101*********"
29 timeStamp = WxObj.ToUnixTime(now()) ' 1907-1-1 00:00:00时间戳
30 nonce_str = WxObj.MakeRanNumChar(12) ' 随机字符串
31 prepay_id = _prepay_id(attach, body, nonce_str, notify_url, openid, out_trade_no, total_fee)
32 paySign = _paySign(nonce_str, prepay_id, timeStamp)
33
34Set Md5Obj = Nothing
35Set WxObj = Nothing
36If Err Then Response.Write Err.Description
37 %>
38<!DOCTYPE html>
39<html>
40<head>
41<title>在线下单</title>
42<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
43<meta id="viewport" name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1; user-scalable=no;"/>
44<link href="/wx/fonts/font.css" type="text/css" rel="stylesheet"/>
45<script Language="javascript">
46var prepay_id="<%=prepay_id%>";
47var paySign="<%=paySign%>";
48function Pay_ok(){
49 alert ("⽀付成功");
50 self.location='<%=redirect_url%>?body=<%=body%>&total_fee=<%=total_fee%>&out_trade_no=<%=out_trade_no%>';
51 }
52function callpay(){
53if(prepay_id==""){
54 alert("提⽰:prepay_id获取失败、本次交易结束!");
55 }else{
56 WeixinJSBridge.invoke('getBrandWCPayRequest',{
57 "appId":"<%=C_AppID%>",
58 "timeStamp":"<%=timeStamp%>",
59 "nonceStr":"<%=nonce_str%>",
60 "package":"prepay_id=<%=prepay_id%>",
61 "signType":"MD5",
62 "paySign":"<%=paySign%>"
63 },
64function(res){
_msg=="get_brand_wcpay_request:ok"){
66 Pay_ok();
67 }else _msg=="get_brand_wcpay_request:cancel"){
68 alert("提⽰:取消交易成功!");
69 }else _msg=="get_brand_wcpay_request:fail"){
70 alert("提⽰:⽀付失败!");
71 }else{
72 ___msg);
73 }
74 }
75 );
76 }
77 }
78</script>
79<style type="text/css">
80*{ margin:0;padding:0;list-style:none;word-wrap:break-word; }
81body { -webkit-user-select:none; -webkit-text-size-adjust:none; font-family:Helvetica; background:#eae9e6; }
82a,button,input,img{-webkit-touch-callout:none;outline:none;}
83a{text-decoration:none; color:#666666}
84a[class*="btn"]{display:block;height:42px;line-height:42px;color:#FFFFFF;text-align:center;border-radius:5px;}
85.clear { clear:both; width:100%; height:1px; }
86.btn-blue { background:#3D87C3;border:1px solid #1C5E93;}
87.btn-green { background-image:-webkit-gradient(linear, left top, left bottom, color-stop(0, #43C750), color-stop(1, #31AB40));border:1px solid #2E993C;
88box-shadow:0 1px 0 0 #69D273 inset; height:42px; line-height:42px; margin-top:15px; }
89.PayInfo { border-top:1px solid rgba(0, 0, 0, 0.1);border-bottom:1px solid rgba(0, 0, 0, 0.1); padding:15px 10px; background:#fff;margin-bottom:5px; margin-top:5px; }
90.PayInfo .InfoLine { min-height:42px; line-height:42px; position:relative; display:block; }
91.PayInfo .InfoLine .txtT { width:25%; min-height:42px; line-height:42px; text-align:right; position:absolute; left:0; top:0; font-weight:bold; color:#333; }
92.PayInfo .InfoLine .txtS { text-align:left; text-indent:5px; min-height:42px; line-height:42px; float:left; margin-left:25%; color:#555; width:75%; }
93</style>
94</head>
95<body>
96<div class="top">
97在线⽀付
98</div>
99<div class="clear"></div>
100
101<div class="PayInfo">
102<div class="InfoLine"><span class="txtT">单号:</span><span class="txtS"><%=out_trade_no%></span></div>
103<div class="clear"></div>
104<div class="InfoLine"><span class="txtT">商品:</span><span class="txtS"><%=body%></span></div>
105<div class="clear"></div>
106<div class="InfoLine"><span class="txtT">⽀付⾦额:</span><span class="txtS"><%=FormatNumber(total_fee*0.01,2,-1)%>元</span></div>
107<div class="clear"></div>
108<div class="InfoLine"><a href="javascript:callpay();" class="btn-green">确认⽀付</a></div>
109</div>
110</body>
111</html>
页⾯:pay_ok.asp
1 <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
2<!DOCTYPE html>
3<html>
4<head>
5<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
6<meta id="viewport" name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1; user-scalable=no;"/>
7<link href="/wx/fonts/font.css" type="text/css" rel="stylesheet"/>
8<title>⽀付结果</title>
9<style type="text/css">
10*{ margin:0;padding:0;list-style:none;word-wrap:break-word; }
11body { -webkit-user-select:none; -webkit-text-size-adjust:none; font-family:Helvetica; background:#eae9e6; }
12a,button,input,img{-webkit-touch-callout:none;outline:none;}
13a{text-decoration:none; color:#666666}
14a[class*="btn"]{display:block;height:42px;line-height:42px;color:#FFFFFF;text-align:center;border-ra
dius:5px;}
15.clear { clear:both; width:100%; height:1px; }
16
17.PayInfo { border-top:1px solid rgba(0, 0, 0, 0.1);border-bottom:1px solid rgba(0, 0, 0, 0.1); padding:15px 10px; background:#fff;margin-bottom:5px; margin-top:5px; }
18.PayInfo .InfoLine { min-height:42px; line-height:42px; position:relative; display:block; }
19.PayInfo .InfoLine .txtT { width:25%; min-height:42px; line-height:42px; text-align:right; position:absolute; left:0; top:0; font-weight:bold; color:#333; }
20.PayInfo .InfoLine .txtS { text-align:left; text-indent:5px; min-height:42px; line-height:42px; float:left; margin-left:25%; color:#555; width:75%; }
21.PayInfo .CashStatus { min-height:42px; line-height:42px; font-size:26px; color:#333; display:block; text-align:center; position:relative; }
22.PayInfo .CashStatus:before { font-size:30px;color:#2E993C; }
23.PayInfo .viewBtm { display:block; width:100%; height:52px; line-height:52px; text-align:center; }
24</style>
25</head>
26<body>
27<div class="clear"></div>
28<div class="PayInfo">
29<div class="InfoLine"><span class="txtT">订单编号:</span><span class="txtS"><%=request("out_trade_no")%></span></div>
30<div class="clear"></div>
31<div class="InfoLine"><span class="txtT">商品名称:</span><span class="txtS"><%=request("body")%></span></div>
32<div class="clear"></div>
33<div class="InfoLine"><span class="txtT">下单⾦额:</span><span class="txtS">¥<%=FormatNumber(request("total_fee")*0.01,2,-1)%>元</span></div> 34<div class="clear"></div>
35<div class="font_icon font_wxpay CashStatus">下单成功!</div>
36</div>
37</body>
38</html>
页⾯:notify.asp
1 <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
2 <%
3 Response.cachecontrol="no-cache"
4 Response.addHeader "pragma","no-cache"
5 pires=-1
6 piresAbsolute=now-1
7 Response.CharSet="utf-8"
8Dim notifyObj
9Set notifyObj = New NotifyClass
ify_url_return()
11Set notifyObj = Nothing
12
13 Class NotifyClass
14Private Sub Class_Initialize()
15End Sub
16' 清空⽂件对象内存
17Private Sub Class_Terminate()
18End Sub
19'本接⼝为⽤户⽀付成功后,后台通知结果的接⼝,包括Url上的参数及XML内的参数
20'可通过产品唯⼀订单号和⽀付状态,确定⽤户⽀付成功后执⾏的⼀系列操作
21Public Sub notify_url_return()
22on error resume next
23dim xml_dom,logStr:logStr = ""'⽣成log的内容变量
24set xml_dom = Server.CreateObject("MSXML2.DOMDocument")
25 xml_dom.load Request
26dim return_code,return_msg,result_code,err_code_des
27' 数据正常时的通⽤变量
28dim openid,is_subscribe,trade_type,bank_type,total_fee,transaction_id,out_trade_no,time_end,attach
29
30 return_code = lementsbytagname("return_code").item(0).text
31if return_code="FAIL"then
32'协议级错误
33 return_msg = lementsbytagname("return_msg").item(0).text
34 logStr = "{'error':'401','msg_type':'协议级错误','return_msg':'"&return_msg&"'}"
35else
36 result_code = lementsbytagname("result_code").item(0).text
37if result_code="FAIL"then
38'业务级错误
39 err_code_des = lementsbytagname("err_code_des").item(0).text
40 logStr = "{'error':'402','msg_type':'业务级错误','err_code_des':'"&err_code_des&"'}"
41else
支付分怎么开通42if return_code="SUCCESS"and result_code="SUCCESS"then
43'数据正常
44 openid = lementsbytagname("openid").item(0).text
45 is_subscribe = lementsbytagname("is_subscribe").item(0).text
46 trade_type = lementsbytagname("trade_type").item(0).text
47 bank_type = lementsbytagname("bank_type").item(0).text
48 total_fee = lementsbytagname("total_fee").item(0).text
49 transaction_id = lementsbytagname("transaction_id").item(0).text
50 out_trade_no = lementsbytagname("out_trade_no").item(0).text
51 time_end = lementsbytagname("time_end").item(0).Text
52 attach = lementsbytagname("attach").item(0).Text
53
54' 此处可以调⽤与数据库通信的函数
55end if
56end if
57end if
58dim returnXml,errString
59 returnXml="<xml>"&_
60"<return_code><![CDATA[SUCCESS]]></return_code>"&_
61"</xml>"
62 Response.Write returnXml '返回SUCCESS给
63End Sub
64End Class
65 %>
三个页⾯均⽤到了WeixinDLL组件,有需要的可以联系博主!
发布评论