<!--#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")
	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='51ka'"

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


	ComeIp = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
	If ComeIp = "" Then ComeIp = Request.ServerVariables("HTTP_Cdn-Src-Ip")
	If ComeIp = "" Then ComeIp = Request.ServerVariables("REMOTE_ADDR")



'商户在51支付网关上的上级商户号
superid="100000"
'商户流水号
sdcustomno = mysp_billno
'商户支付的订单金额
ordermoney= MyPrice
'支付方式
'cardno= mypaytype
cardno= "04"
'卡面值编号
faceno= ka_type
'后台通知地址，商户系统后台接收51支付订单结果的地址
noticeurl="http://"&Request.ServerVariables("HTTP_HOST")&"/Pay/51ka_bank/Receive_51KA.asp"
endcustomer=customerid
endip=ComeIp
'商户备注信息
remarks="banana"
'商户自定义
mark="51esales"
'组合字符串
signstr="customerid="&customerid&"&sdcustomno="&sdcustomno&"&ordermoney="&ordermoney&"&cardno="&cardno&"&faceno="&faceno&"&noticeurl="&noticeurl&"&endcustomer="&endcustomer&"&endip="&endip&"&remarks="&remarks&"&mark="&mark&"&key="&key


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

params="customerid="&customerid&"&sdcustomno="&sdcustomno&"&ordermoney="&ordermoney&"&cardno="&cardno&"&faceno="&faceno&"&noticeurl="&noticeurl&"&endcustomer="&endcustomer&"&endip="&endip&"&remarks="&remarks&"&mark="&mark&"&sign="&sign&""




linkurl="http://it.51esales.net/gateway/"
TOSPPost = linkurl&"sftcardkpay.asp?"&params



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



%>
