<%
mainpath="data/iheeo_db.mdb"
Set conn = Server.CreateObject("ADODB.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(mainpath)
conn.Open connstr

set rs=server.CreateObject("adodb.recordset")
rs.Open "select mailaddress,mailusername,mailuserpass,mailname,mailsend from BJX_config",conn,1,1
mailaddress=rs("mailaddress")
mailusername=rs("mailusername")
mailuserpass=rs("mailuserpass")
mailname=rs("mailname")
mailsend=rs("mailsend")
rs.close
set rs=nothing

Function viate(itemnumber,paymentid,payamount,payeremail)
set rs=server.CreateObject("adodb.recordset")
sql="select * from BJX_action where actionid="&request("aid")&""  
rs.open sql,conn,1,3

If Not(rs.bof Or rs.eof) Then 
   rs("zhuangtai")="2"
   rs.update

Else 
   response.write "<script>alert('NO this order number ! Please contact website administrator !!');</script>"
End If 
rs.close
Set rs=Nothing 

set rs1=server.CreateObject("adodb.recordset")
sql="select top 1 * from ka where bookid="&request("aid")&" and fasong=2 order by id"  
rs1.open sql,conn,1,3

If Not(rs.bof Or rs.eof) Then 
   rs("fasong")="2"
   kahao= rs("kahao")
   mima= rs("mima")
   rs.update

    mailbody = mailbody &"您订购的卡号信息：<br><br>"
	mailbody = mailbody &"卡号："&kahao&"<br><br>"
	mailbody = mailbody &"密码："&mima&"<br><br>"
	mailbody = mailbody &"请您注意保管。"

	set jmail = server.CreateObject ("jmail.message")  '创建对象
    jmail.Silent = true                         '一般不用改
    jmail.Charset = "gb2312"                    '信件的语言编码
    jmail.ContentType = "text/html"             '信件的格式html或纯文本
    jmail.From = mailsend                '发信人邮箱
    jmail.FromName = mailname         '发信人姓名
    jmail.Subject = "您订购的卡的信息"  '信件主题
    jmail.AddRecipient mailsend           '收信人地址
    jmail.HTMLBody = mailbody'信件正文
    jmail.MailServerUserName = mailusername '服务器登陆用户名(您的邮件地址)
    jmail.MailServerPassWord = mailuserpass         '服务器登陆密码(您的邮件密码)
    jmail.Send(mailaddress)                 '服务器地址
    jmail.Close	

Else 
   response.write "<script>alert('NO this order number ! Please contact website administrator !!');</script>"
End If 
rs.close
Set rs=Nothing 

End Function 

function urldecode(encodestr)   '这个函数是对paypal返回值的urldecode解码的
newstr="" 
havechar=false 
lastchar="" 
for i=1 to len(encodestr) 
char_c=mid(encodestr,i,1) 
if char_c="+" then 
newstr=newstr & " " 
elseif char_c="%" then 
next_1_c=mid(encodestr,i+1,2) 
next_1_num=cint("&H" & next_1_c) 
if havechar then 
havechar=false 
newstr=newstr & chr(cint("&H" & lastchar & next_1_c)) 
else 
if abs(next_1_num)<=127 then 
newstr=newstr & chr(next_1_num) 
else 
havechar=true 
lastchar=next_1_c 
end if 
end if 
i=i+2 
else 
newstr=newstr & char_c 
end if 
next 
urldecode=newstr 
end Function

str1=Trim(request.querystring("tx"))
str2="&at=jQqJG9bXv6t39YDtAabOQPKhm5_dpG7O_wuqMb7c3R7ir0fm5_EXBQ9lY3i"                             '这里是Paypal身份标记    获取方法

str = "?tx="&str1& "&cmd=_notify-synch"&str2
'https://www.sandbox.paypal.com/cgi-bin/webscr
paypalurl="https://www.sandbox.paypal.com/cgi-bin/webscr"
paypalurl=paypalurl&str
'response.write "<br>"&paypalurl&"<br>"&"<br>"&"<br>"

Set objHttp=Server.CreateObject("Msxml2.ServerXMLHTTP.3.0")
objHttp.setOption 2, 13056 
objHttp.open "POST",paypalurl,False,"","" 
objHttp.send()

ResponseTxt = objHttp.ResponseText           '示例下面有写
Set objHttp=Nothing
'-------------------------------------------------核对取得值
ResponseTxt=UrlDecode(ResponseTxt)                '将返回值解码并赋给 responsetxt 
If Mid(ResponseTxt,1,7) = "SUCCESS" Then          '取得返回值的状态, sucess表示支付成功 ! Fail 表示支付失败 ! 返回值只有这两种情况 !
ResponseTxt = Mid(ResponseTxt,9)                  '取得除了前9个字符的返回值,并返回给responsetxt
sParts = Split(ResponseTxt, vbLf)                 '将返回值以vbLf(在vb里面这是回车<换行>的意思)分开,并赋给一个数组sParts
iParts = UBound(sParts) - 1                      '对这个数组分离取值, 后面的应该都可以看得懂的吧!
ReDim sResults(iParts, 1)
For i = 0 To iParts
aParts = Split(sParts(i), "=")
sKey = aParts(0)
sValue = aParts(1)
sResults(i, 0) = sKey
sResults(i, 1) = sValue

Select Case sKey
Case "first_name"
firstName = sValue
Case "last_name"
lastName = sValue
Case "item_name"
itemName = sValue
Case "mc_gross"
mcGross = sValue
Case "mc_currency"
mcCurrency = sValue
Case "txn_id"
liushuihao = Trim(sValue)
Case "payer_email"
payeremail=Trim(sValue)
End Select
Next
Call viate(itemName,liushuihao,mcGross,payeremail)        '这里调用viate()这个function 进行认证, 并对这个订单状态进行更新 !
Msg="Pay for success! Please wait for delivery! "&"\n \n Your Order Number: "&itemName&" !"
Else
Msg="Sorry ! Your operating error! Please contact website administrator !!"
End If
response.write "<script>alert('"&msg&"');location.href='user.asp?action=dindan'</script>" '支付完毕返回 用户信息页 !
%>
