<!--#include file="conn.asp"-->
<!--#include file="tenpay_md5.asp"-->
<!--#include file="../include/Lebi_config.asp"-->
<!--#include file="../union/config.asp"-->
<%
session.codepage=65001
response.charset="utf-8"
Dim v_oid,v_pmode,v_pstatus,v_pstring,v_md5info,v_amount,v_moneytype,v_md5money,v_md5,key,text,md5text,orderzt
v_oid=request("v_oid")
v_pmode=request("v_pmode")
v_pstatus=request("v_pstatus")
v_pstring=request("v_pstring")
v_md5info=request("v_md5info")
v_amount=request("v_amount")
v_moneytype=request("v_moneytype")
v_md5money=request("v_md5money")
v_md5=request("v_md5")
key=Pay_chinabank(2)
orderzt=""
remark1 = request("remark1")
If InStr(remark1,"|") > 0 Then 
	LangTxt = Split(remark1,"|")(0)
	user_id = Split(remark1,"|")(1)
Else
	user_id = ""
End If 
if request("v_md5info")="" then
	response.Write("v_md5info：数据校验出错！")
	response.end
end if
'md5校验
text = v_oid&v_pstatus&v_amount&v_moneytype&key
md5text = trim(ASP_MD5(text))
'按md5检验情况输出结果 Ucase转换为大写
if Ucase(md5text)<>Ucase(v_md5) then
	response.write("error")
else
	response.write("received")
	'或response.write "sent',依据商品物流特征决定。

	'提示：仅是对校验码校验通过不表示该支付结果是成功只意味着该信息是由网银传回
	'校验成功需对传回的v_pstatus参数做判断，其中1或20都意味着支付成功（只是支付状态分非实时和实时两种），30表示支付失败
	'如果商户涉及实时售卡，请对返回的金额与数据库中原始金额做大小判断，以防恶意行为
    '操作数据库
	'''''''''''''''''''''开始写入数据库''''''''''''''''''''
	If user_id = "" 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 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 Then '付款后扣除库存 by 56770.kingdge 2012-05-14
						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
	Else
			rem 增加防刷新 2006-7-25 by 56770.kingdge
			set Rs = conn.execute("select * from [Lebi_money_log] where m_order_num='"& v_oid &"' and m_zt=0")
			If not rs.eof Then
					conn.execute("UPDATE [Lebi_money_log] SET m_zt=1 where m_order_num='"& v_oid &"'")
					conn.execute("UPDATE [Lebi_buy] SET orderzt=1 where order_num='"& v_oid &"'")
					conn.execute("UPDATE [Lebi_User] SET usermoney = usermoney + "& v_amount &" where user_id = '"& rs("user_id") &"'")
			End If
			rs.close : Set rs = Nothing
			response.redirect Eshop_url & Split(remark1,"|")(0) &"user/pay.asp?action=update"
	End If 
   '-----------------------------------------------
   '若有错误发生
   If Err.Number <> 0 Then
      Response.Write "error" & Err.Number & "<br>"
      Response.Write "error" & Err.Source & "<br>"
      Response.Write "error" & Err.Description & "<br>"
   Else

   End If
   response.redirect"../"
   response.End
end If
%>