<!--#include file="conn.asp"-->
<!--#include file="tenpay_md5.asp"-->
<!--#include file="../include/Lebi_config.asp"-->
<!--#include file="../union/config.asp"-->
<%
'****************************************	' MD5密钥要跟订单提交页相同，如Send.asp里的 key = "test" ,修改""号内 test 为您的密钥
											' 如果您还没有设置MD5密钥请登陆我们为您提供商户后台，地址：https://merchant3.chinabank.com.cn/
key = Pay_chinabank(2)						' 登陆后在上面的导航栏里可能找到“B2C”，在二级导航栏里有“MD5密钥设置”
											' 建议您设置一个16位以上的密钥或更高，密钥最多64位，但设置16位已经足够了
'****************************************
v_oid=Replace(request("v_oid"),"'","")'订单号
v_pmode=request("v_pmode")'银行名称 如：招商银行
v_pstatus=request("v_pstatus")'支付状态 如：20 支付成功，30 支付失败
v_pstring=request("v_pstring")
v_amount=request("v_amount")
v_moneytype=request("v_moneytype")
v_md5str=request("v_md5str")
remark1=request("remark1")
remark2=request("remark2")
if v_md5str = "" then
	response.write("error")
	response.end
end if
text = v_oid&v_pstatus&v_amount&v_moneytype&key
md5text = Ucase(trim(ASP_MD5(text)))
if md5text<>v_md5str then '与网银在线发送过来的MD5效验码对比，确保是网银在线发送的信息
	response.write("error")
	response.end
else
	response.write("ok") '告诉服务器已经正确接收以及验证参数正确，要求停止发送
	if v_pstatus = "20" then
		conn.execute("UPDATE [Lebi_pay_log] SET l_state=1 where l_ordernum='"&v_oid&"'")
		Set rs = server.CreateObject("adodb.recordset")
		rs.open "select orderzt,paymenttype,paidmoney,id,zt from [Lebi_orders] where order_number='"& v_oid &"'",conn,1,3
		If Not rs.eof Then
			orderzt = orderzt & rs(0) &",2,"
			rs(0) = orderzt
			rs(1) = Pay_chinabank(8)
			rs(2) = rs(2) + v_amount
			rs.update 
			conn.execute("insert into [Lebi_Orders_Paylog](p_price,p_type,p_content,p_time,oid)values("& v_amount &",1,'"& Pay_chinabank(8) &"',"& sqlnowstring &","& rs(3) &")")
			If Config_Lebi_Eshop(23) = 1 And rs(4) = 0 Then '付款后扣除库存 by 56770.kingdge 2012-08-28
				Set rsbasket = conn.execute("select cpid,basket_count,spvalue from [lebi_basket] where order_number = "& rs(3) &"")
				Do While Not rsbasket.eof 
					conn.execute("update [Lebi_product] set buys = buys + "& rsbasket("basket_count")&",kucun = kucun - "& rsbasket("basket_count") &",html = 0 where id = " & rsbasket("cpid") &"")
					conn.execute("update [Lebi_Product_Stock] set p_buys = p_buys + "& rsbasket("basket_count") &",p_stock = p_stock - "& rsbasket("basket_count") &" where p_id = " & rsbasket("cpid") &" and s_value"& LangTxt &" = '"& rsbasket("spvalue") &"'")
				rsbasket.movenext 
				Loop
				rsbasket.close : Set rsbasket = Nothing 
			End If 
		End If
		rs.close : Set rs = Nothing
		'支付已经成功
		'此处加入商户系统的逻辑处理（例如判断金额，判断支付状态(20成功,30失败)，更新订单状态等等）......
	end if
end if
%>