<!--#include file="../../inc/payconn.asp"-->
<!--#include file="asp_md5.asp"-->
<%

Function BytesToBstr(body)
	dim objstream
	set objstream = Server.CreateObject("adodb.stream")
		objstream.Type = 1
		objstream.Mode =3
		objstream.Open
		objstream.Write body
		objstream.Position = 0
		objstream.Type = 2
		objstream.Charset = "GB2312" 
		BytesToBstr = objstream.ReadText
	objstream.Close
	set objstream = nothing
End Function


on error resume next
mysp_billno = request.QueryString("num")
cardNo = request.QueryString("cardNo")
cardPwd = request.QueryString("cardPwd")
cardid = request.QueryString("ka_type")
Price = request.QueryString("Price")

If cardid = "" or mysp_billno ="" or cardNo="" or cardPwd="" or Price=""  Then
Response.Write("缺少参数！")
Response.End()
End If


Call ConnectionDatabase()
Set Res = GrateRs("Select * From [L_pay] Where ptype='95588'",1)
'商户在互赢支付网关上的商户号
MerchantID=Res("sId")
'商户流水号
MerOrderNo = mysp_billno
CardType = cardid
Money = Price
'点卡卡号
CardNo=cardNo
'点卡密码
CardPassword=cardPwd
'后台通知地址，商户系统后台接收互赢支付订单结果的地址
NoticeURL="http://"&Request.ServerVariables("SERVER_NAME")&"/Pay/95588_card/receive.asp"
'商户密钥，请登陆商户后台查询
key=Res("sKey")
res.close
'组合字符串
sign_text =   MerchantID &  MerOrderNo &  CardType  & CardNo & CardPassword &  NoticeURL &  Money & key


'sign_text = "user_id=" & user_id & "&sp_id=" & sp_id &"&sp_billno=" & sp_billno & "&sp_key=" & sp_key & "&sp_returnurl=" & sp_returnurl & "&sp_extdata=" & sp_extdata
'生成MD5签名

'sign = UCase(ASP_MD5(sign_text))        ' 转换为大写
sign = MD5(sign_text)  


TOSPPost = "MerOrderNo=" & MerOrderNo & "&MerchantID=" & MerchantID & "&CardType=" & CardType & "&CardNo=" & CardNo & "&CardPassword=" & CardPassword & "&Money=" & Money & "&NoticeURL=" & NoticeURL & "&sign=" & sign&""

'response.Write(TOSPPost)
'response.End()



Set http = server.CreateObject("WinHttp.WinHttpRequest.5.1")  
http.Option(4) = 13056
http.Option(6) = False
url = "http://superapi.95588.tw:9180/busias/PayRequest"
http.Open "POST", url, False  
http.setrequestheader "Connection", "Keep-Alive"
http.setrequestheader "User-Agent", "Mozilla/4.0"
http.setrequestheader "Content-Length",len(TOSPPost)
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.Send TOSPPost
body=BytesToBstr(http.ResponseBody)

If http.status=200 Then
r = split(body,",")
if Ubound(r)>0 then

if r(0)="OK" then
response.Write("OK")
else
response.Write(r(1))
end if

else
response.Write "返回状态出错"
end if

else
response.Write "通讯失败"
end if

'response.Write body
%>


