<%
'☆★☆★☆★☆★☆★☆★财付通测试开关   0 关闭测试    1 开启测试☆★☆★☆★☆★☆★☆★
beta_switch		="0"
version	= "2"
chnid		= "1201973301"
class tencent_online_payment
'===================================================================
'类描述：财付通支付标准生成函数
'tencent_online_payment:Version 1.0.0
'encode_type 编码标准
'mch_name 商品名称
'mch_price商品价格
'transport_desc 物流信息描述
'transport_fee 物流费用
'mch_desc 交易描述
'mch_type交易类型：1、实物交易，2、虚拟交易。
'mch_vno 商家订单号
'===================================================================	
	Public function tenpay_interface_pay (encode_type,mch_name,mch_price,transport_desc,transport_fee,mch_desc,mch_type,mch_vno,attach)
		

			mch_price=csng(mch_price*100)
			transport_fee=csng(transport_fee*100)
			retcode = "0"
			retmsg = "正常"

'检查传入参数
if encode_type = "" then
	retcode = "06001"
	retmsg = "缺少encode_type,将被默认设置为gb2312"
	encode_type="utf-8"
end if 

if mch_price = "" then
	retcode = "09001"
	retmsg = "缺少商品价格"
end if 

if transport_desc = "" then
	retcode = "06003"
	retmsg = "缺少物流信息描述,将被默认设置为无物流信息"
	transport_desc ="无物流信息"
end if

if mch_name ="" then
	retcode = "06002"
	retmsg = "缺少商品名称，将被默认设置为网站地址加订单号"
	mch_name = domain & mch_vno
end if

if transport_fee ="" then
	if retcode = "06003" then
		transport_fee="0"
	else
		retcode = "09002"
		retmsg = "缺少物流价格"
		end if
end if

if mch_desc ="" then 
	retcode = "06004"
	retmsg = "缺少交易描述信息，将被默认设置为网站地址加交易购物"
	mch_desc = domain & "交易购物"
end if

if need_buyerinfo = "" then 
	retcode = "06005"
	retmsg = "缺少need_buyerinfo，将被默认设置为不需要"
	need_biyerinfo = "2"
end if

'mch_type交易类型：1、实物交易，2、虚拟交易。
if mch_type = "" then
	retcode = "06006"
	retmsg = "缺少交易类型，将被设置为实物交易"
	mch_type = "1"
end if

if mch_vno = "" then 
	retcode = "09003"
	retmsg = "缺少商家订单号"
end if

if mch_returl= "" then
		retcode = "06007"
		retmsg = "缺少通知地址，将被默认设置为"& domain & tenpay_dir &"/tenpay_notify.asp"
		mch_returl= domain & tenpay_dir &"/tenpay_notify.asp"
end if

if show_url= "" then 
	retcode = "06008"
	retmsg = "缺少返回地址，将被默认设置为不返回"
	show_url = "https://www.tenpay.com"
end if 

			if beta_switch = "1" then
				mch_price = "1"
				transport_fee = "0"
			end if
		
				if csng(retcode) < 09000 then 
						
					dim buffer
					buffer = AddParameter(buffer, "attach", 		attach)
					buffer = AddParameter(buffer, "chnid", 			chnid)
					buffer = AddParameter(buffer, "cmdno", 			"12")
					buffer = AddParameter(buffer, "encode_type", 	encode_type)
					buffer = AddParameter(buffer, "mch_desc", 		mch_desc)
					buffer = AddParameter(buffer, "mch_name", 		mch_name)
					buffer = AddParameter(buffer, "mch_price", 		mch_price)
					buffer = AddParameter(buffer, "mch_returl", 	mch_returl)
					buffer = AddParameter(buffer, "mch_type", 		mch_type)
					buffer = AddParameter(buffer, "mch_vno", 		mch_vno)
					buffer = AddParameter(buffer, "need_buyerinfo", need_buyerinfo)
					buffer = AddParameter(buffer, "seller", 		seller)
					buffer = AddParameter(buffer, "show_url", 		show_url)
					buffer = AddParameter(buffer, "transport_desc", transport_desc)
					buffer = AddParameter(buffer, "transport_fee", 	transport_fee)
					buffer = AddParameter(buffer, "version", 		version)
					
					dim parameters
					parameters = buffer
					
					buffer = AddParameter(buffer, "key", 			sp_key)
					
'					response.write("<br/>buffer:" & buffer & "<br/><br/>")
					
					dim sign
					sign = ASP_MD5(buffer)
													
					payto= pay_url	& "?" & parameters & "&sign=" & sign 
		
					if beta_switch = "1" then 
						response.Write(payto)
						response.Write("<br></br>")
						response.Write(get_tenpay_button_URL (payto,imgtitle,imgsrc))
						response.Write("<br></br>")
						response.Write("err ："& retcode & retmsg)
			
					end if
		
					if beta_switch = "0" then 
							tenpay_interface_pay = get_tenpay_button_URL (payto,imgtitle,imgsrc)

			
					end if
				else 
					response.Write(retcode&"："&retmsg)
				end if
			
	
	
	
	end function

	
	
	
'===================================================================
'类描述：html生成函数
'tencent_online_payment:Version 1.0.0
'===================================================================	
	Public Function get_tenpay_button_URL(itemURL,imgtitle,imgsrc)
'		dim responseText1
'		responseText1	=	responseText1 & "<a href='" & itemURL & "' target='_blank'>"		'购买网址
'		responseText1	=	responseText1 & "<img alt='" & imgtitle & "' src='"				'图片说明
'		responseText1	=	responseText1 & imgsrc											'图片地址
'		responseText1	=	responseText1 & "' align='absmiddle' border='0'/></a>"
'		get_tenpay_button_URL=responseText1
		get_tenpay_button_URL=itemURL
	End Function


end class

dim TenPay
Set TenPay	= New tencent_online_payment
'Tenpay.tenpay_interface_pay encode_type,"商品名称","1","物流信息","1","商品说明","1","20080409190320"

'添加参数,若参数值不为空串,则添加。反之,不添加。
'parameterName 参数名
'parameterValue 参数值
Public Function AddParameter(buffer,parameterName,parameterValue)
	
	if parameterValue = "" then
		AddParameter = buffer
		exit Function
	end if

	if buffer = "" then
		buffer = parameterName & "=" & parameterValue
	else
		buffer = buffer & "&" & parameterName & "=" & parameterValue
	end if
	
	AddParameter = buffer
	
End Function
%>
