<!--#include file="../../inc/payconn.asp"-->
<!--#include file="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

	mysp_billno = request("num")
	MyPrice = request("price")
	ka_type = request("ka_type")
	ka_number = Request("cardNo")
	ka_password = Request("cardPwd")
	PayID = Request("PayID")
	
		Call ConnectionDatabase()
	Dim prs	
	If PayID = "" or mysp_billno ="" or MyPrice="" or ka_type="" or ka_type="" or ka_type="" Then
		Response.Write("缺少参数！")
		Response.End()
	End If
	
	Set prs = Conn.Execute("Select psort,wangguan From [H_Plist] Where ID="&Cint(PayID))
	if prs.Eof Then
		Response.Write("找不到支付方式！")
		Response.End()
	Else
		psort = prs("psort")
		mypaytype = prs("wangguan")
	End If

SQL = "Select * From [L_pay] Where ptype='46ka'"

Set crs = Server.CreateObject("ADODB.Recordset")
crs.Open SQL,Conn,1,1
if crs.eof Then
 Response.Write "支付未设置！"
 Response.End()
 else
 	customerid		= crs("sId")                                       ' 这里替换为您的实际商户号
	key	= crs("sKey")				' 商户密钥,测试时即为商户号,正式上线后需修改	
End If

'商户流水号
sdcustomno = mysp_billno
'商户支付的订单金额
ordermoney= MyPrice
'支付方式
cardno= replace(mypaytype,"46","")
'卡面值编号
faceno= ka_type
'点卡卡号
cardnum= ka_number
'点卡密码
cardpass= ka_password
'后台通知地址，商户系统后台接收46ka支付订单结果的地址
noticeurl="http://"&Request.ServerVariables("HTTP_HOST")&"/Pay/46ka/Receive_46ka.asp"
'商户自定义
remarks="46ka"
'组合字符串

signstr = "user_id=" & customerid & "&sp_id=" & faceno &"&sp_billno=" & sdcustomno & "&sp_key=" & key & "&sp_returnurl=" & noticeurl & "&sp_extdata=" & remarks


'生成MD5签名
sign= UCase(MD5(signstr))



params = "user_id=" & customerid & "&sp_billno=" & sdcustomno & "&sp_id=" & faceno & "&sp_cardnumber=" & cardnum & "&sp_cardpassword=" & cardpass & "&sp_returnurl=" & noticeurl & "&sp_extdata=" & remarks & "&sign=" & sign


 'Response.Write params
 'Response.End()



Set http = server.CreateObject("WinHttp.WinHttpRequest.5.1")  
http.Option(4) = 13056
http.Option(6) = False
url = "http://post.46ka.com/index.asp"
http.Open "POST", url, False  
http.setrequestheader "Connection", "Keep-Alive"
http.setrequestheader "User-Agent", "Mozilla/4.0"
http.setrequestheader "Content-Length",len(params)
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.Send params
body=BytesToBstr(http.ResponseBody)

If http.status=200 Then

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


%>
