www.gusucode.com > 中网景企业网站源码时尚版 2009.73码程序 > chinese/pay_receive_tenpay.asp

    <!--#include file="../opendb.asp" -->
<!-- #include file="../common/md5.asp" -->
<% Response.Buffer = true %>
<meta name="TENCENT_ONELINE_PAYMENT" content="China TENCENT">
<html>
<%
'取返回参数
Dim cmdno,pay_result,pay_result,pay_info,bill_date,bargainor_id,transaction_id,sp_billno,total_fee,fee_type
Dim attach,md5_sign,spid,sp_key
cmdno			= Request("cmdno")
pay_result	= Request("pay_result")
pay_info		= Request("pay_info")
bill_date		= Request("date")
bargainor_id	= Request("bargainor_id")
transaction_id	= Request("transaction_id")
sp_billno		= Request("sp_billno")
total_fee		= Request("total_fee")
fee_type		= Request("fee_type")
attach			= Request("attach")
md5_sign		= Request("sign")

'本地参数
rs.open "select * from cnk_payway where payname='tenpay' and isopen=1",conn,1,1 
spid	= rs("payid")	' 这里替换为您的实际商户号
sp_key = rs("paykey")		' sp_key是32位商户密钥, 请替换为您的实际密钥
rs.close

'返回值定义
Private Const retOK = 0					' 成功					
Private Const invalidSpid = 1			' 商户号错误
Private Const invalidSign = 2			' 签名错误
Private Const tenpayErr	= 3				' 财付通返回支付失败

'验签函数
Function verifyMd5Sign
	Dim origText,localSignText
	origText = "cmdno=" & cmdno & "&pay_result=" & pay_result &_ 
		       "&date=" & bill_date & "&transaction_id=" & transaction_id &_
			   "&sp_billno=" & sp_billno & "&total_fee=" & total_fee &_
			   "&fee_type=" & fee_type & "&attach=" & attach &_
			   "&key=" & sp_key
	
	localSignText = UCase(ASP_MD5(origText)) ' 转换为大写
	verifyMd5Sign = (localSignText = md5_sign)
	
End Function

'返回值
Dim retValue
retValue = retOK

'判断商户号
If bargainor_id <> spid Then
	retValue = invalidSpid
Else 
' 验签
	If verifyMd5Sign <> True Then
		retValue = invalidSign
	Else
' 检查财付通返回值
		If pay_result <> 0 Then
			retValue = tenpayErr
		End If
	End If
End If

'在这里处理业务逻辑

'输出信息
Dim pay_msg
Select Case retValue
	Case retOK
		pay_msg = "支付成功!"
		conn.execute("update cnk_orderform set zhuangtai=1,payway='财付通' where orderid='"&sqlchkchar(sp_billno)&"'")	'处理订单状态
	Case invalidSpid	pay_msg = "错误的商户号!"	
	Case invalidSign	pay_msg = "验证MD5签名失败!"
	Case Else			pay_msg = "支付失败!"
End Select

Call Closedb()

Response.write "<script language=javascript>"
Response.write "window.location.href='pay_showResult.asp?msg=" & pay_msg & "';"  '替换成商户网站相应页面地址
Response.write "</script>"
%>
</html>