<!--#include file="../util/md5.asp"-->
<!--#include file="../util/tenpay_util.asp"-->
<%
'
'即时到帐支付应答类
'============================================================================
'api说明：
'getKey()/setKey(),获取/设置密钥
'getParameter()/setParameter(),获取/设置参数值
'getAllParameters(),获取所有参数
'isTenpaySign(),是否财付通签名,true:是 false:否
'doShow(),显示处理结果
'getDebugInfo(),获取debug信息
'
'============================================================================
'


Class PayResponseHandler

	'密钥
	Private key

	'应答的参数
	Private parameters

	'debug信息
	Private debugInfo

	'初始构造函数
	Private Sub class_initialize()
		key = ""
		Set parameters = Server.CreateObject("Scripting.Dictionary")
		debugInfo = ""
				
		parameters.RemoveAll
		
		Dim k
		Dim v
		
		'GET
		For Each k In Request.QueryString
			v = Request.QueryString(k)
			setParameter k,v
		Next
		
		'POST
		For Each k In Request.Form
			v = Request(k)
			setParameter k,v
		Next
		
	End Sub

	'获取密钥
	Public Function getKey()
		getKey = key
	End Function
	
	'设置密钥
	Public Function setKey(key_)
		key = key_
	End Function
	
	'获取参数值
	Public Function getParameter(parameter)
		getParameter = parameters.Item(parameter)
	End Function
	
	'设置参数值
	Public Sub setParameter(parameter, parameterValue)
		If parameters.Exists(parameter) = True Then
			parameters.Remove(parameter)
		End If
		parameters.Add parameter, parameterValue	
	End Sub

	'获取所有请求的参数,返回Scripting.Dictionary
	Public Function getAllParameters()
		getAllParameters = parameters
	End Function

	'是否财付通签名
	'true:是 false:否
	Public Function isTenpaySign()
		
		Dim cmdno
		Dim pay_result
		Dim date
		Dim transaction_id
		Dim sp_billno
		Dim total_fee
		Dim fee_type
		Dim attach

		cmdno = getParameter("cmdno")
		pay_result = getParameter("pay_result")
		date = getParameter("date")
		transaction_id = getParameter("transaction_id")
		sp_billno = getParameter("sp_billno")
		total_fee = getParameter("total_fee")		
		fee_type = getParameter("fee_type")
		attach = getParameter("attach")
		
		'组织签名串
		Dim signPars
		signPars = "cmdno=" & cmdno & "&" &_
				"pay_result=" & pay_result & "&" &_
				"date=" & date & "&" &_
				"transaction_id=" & transaction_id & "&" &_
				"sp_billno=" & sp_billno & "&" &_
				"total_fee=" & total_fee & "&" &_
				"fee_type=" & fee_type & "&" &_
				"attach=" & attach & "&" &_
				"key=" & key

		Dim sign
		sign= LCase(ASP_MD5(signPars))
		
		Dim tenpaySign
		tenpaySign = LCase( getParameter("sign"))

		'debugInfo
		debugInfo = signPars & " => sign:" & sign & " tenpaySign:" & tenpaySign

		isTenpaySign = (sign = tenpaySign)

	End Function

	'显示处理结果。
	'show_url 显示处理结果的url地址,绝对url地址的形式(http://www.xxx.com/xxx.asp)。
	Public Function doShow(show_url)
		Dim newLine
		Dim strHtml
		newLine = chr(13) & chr(10)
		strHtml = "<html><head>" & newLine &_
			"<meta name=""TENCENT_ONLINE_PAYMENT"" content=""China TENCENT"">" & newLine &_
			"<script language=""javascript"">" & newLine &_
				"window.location.href='" & show_url & "';" & newLine &_
			"</script>" & newLine &_
			"</head><body></body></html>"
		
		Response.Write(strHtml)

		Response.End

	End Function

	'获取debug信息
	Function getDebugInfo()
		getDebugInfo = debugInfo
	End Function
	
End Class




%>