<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
'适用对象:Window2000/NT用户

If not ef Then
If Application("NP_IPS_ShopID")="1234" Or Application("NP_IPS_ShopID")="" Then
		ef=True
		ec="商号尚未设置！"
End if
end If

'验证方式：
'	交易返回接口采用Md5withRSA验证(RetEncodeType=1)

'参考对象:交易返回接口采用Md5withRSA验证(RetEncodeType=1)
'明文信息:Md5摘要原文=订单编号+订单金额+订单日期+成功标志+IPS订单编号
'验证结果:根据下列函数的返回结果result判断:
'			result=0， 表示签名验证成功
'			result=-1，表示系统错误
'			result=-2，表示文件绑定错误
'			result=-3，表示读取公钥失败
'			result=-4，表示签名长度错误
'			result=-5，表示签名验证失败
'			result=-99，表示系统锁定失败



'防止刷新
Response.AddHeader "Pragma", "No-Cache"
Response.Buffer = True 
Response.ExpiresAbsolute = Now() - 1 
Response.Expires = 0 
Response.CacheControl = "no-cache"

dim billno
dim amount 
dim mydate
dim succ
dim msg
dim attach
dim ipsbillno
dim encodetype
dim signature

'----------------------------------------------------
'接收数据
'Receive the data
'----------------------------------------------------

billno=Request.QueryString("billno")
amount=Request.QueryString("amount")
mydate=request.querystring("date")
succ=Request.QueryString("succ")
msg=request.querystring("msg")
attach=request.querystring("attach")
ipsbillno=Request.QueryString("ipsbillno")
retEncodeType=Request.QueryString("retencodetype")
signature=request.querystring("signature")	

'----------------------------------------------------
'判断交易是否成功
'See the successful flag of this transaction
'----------------------------------------------------

'if succ="Y" then continue
if succ<>"Y" then
		ef=True
		ec="交易失败！"
	Response.Write "交易失败！"
	Response.End 
else
		'----------------------------------------------------
		'验证签名
		'verify  signature
		'----------------------------------------------------
		content=billno & amount & mydate & succ & ipsbillno
		'Md5摘要原文=订单编号+订单金额+订单日期+成功标志+IPS订单编号

		
		if md5(content&Application("NP_IPS_Key"))<>signature then
		ef=True
		ec="非法加密！"
			Response.Write "非法加密！"
	Response.End 
		end if

end if

if not ef then
SHOPID = Application("NP_IPS_ShopID")
ORDERID = billno
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
Set dsNP = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Netpay where ORDERID='"&ORDERID&"' and SHOPID='"&SHOPID&"' "

if RegExpTest("[^A-Za-z0-9]",ORDERID) Or RegExpTest("[^A-Za-z0-9]",SHOPID) then
	ef=True
	ec="ORDERID或SHOPID不正确！用户试图SQL注入被拦截,内容:"&ORDERID&SHOPID
FreeHost_oplog "error","信息","实时返回支付出错"&ec
response.write "fail"&ec
response.end
end If

'	Application("NPS_test")=sql&"   "&FD_NPSId
'	response.write sql
'	response.end
		dsNP.Open Sql,conn,3,2
if dsNP.eof then
		ef=True
		ec="不存在的订单！"
else
  if dsNP("SucceedFlag") <>0 then
		ef=True
		ec="状态已更新过了，不能重复操作！"
  end if
   if dsNP("ORDERMONEY") >amount then
		ef=True
		ec="金额不正确！"
  end if
end if
end if



if not ef then

UserName=dsNP("UserName")
OrderMoney=dsNP("OrderMoney")
Set dsreg = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_AGENT where username='"&UserName&"' and agenttype<>'n'"
		dsreg.Open Sql,conn,1,3
If dsreg.Eof Then
Set dsreg = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_USER where username='"&UserName&"'"
		dsreg.Open Sql,conn,1,3
If dsreg.Eof Then
		ef=True
		ec="会员名不存在！"
end if
end if
end if


if not ef then
dsNP("SucceedFlag")=1
dsNP.update
olduser_money=dsreg("usermoney")
If Application("NetPaypercent")>0 Then OrderMoney=OrderMoney/(1+Application("NetPaypercent"))
OrderMoney=Round(OrderMoney,2)
moneych=OrderMoney
dsreg("usermoney")=dsreg("usermoney")+OrderMoney
newuser_money=dsreg("usermoney")
dsreg.update

if not isnull(dsreg("kefunow")) then
Set dskefu = Server.CreateObject("ADODB.Recordset")	
	Sql="Select finishmoney from FreeHost.FreeHost_KeFu where kefumd5='"&md5(trim(dsreg("kefunow")))&"'"
	dskefu.Open Sql,conn,1,3
if not dskefu.Eof then
dskefu("finishmoney")=dskefu("finishmoney")+OrderMoney
dim kefu
kefu=dsreg("kefunow")
dskefu.update
end if
dskefu.close
end if

FreeHost_moneyNewlog conn,"y","n","n","n","y",isAgnHostSer,moneych,UserName,UserName,UserName,olduser_money,newuser_money,agnusername,agnStmoney,agnEndmoney,supusername,"网上支付IPS接口订单"&ORDERID&",网站："&Request.ServerVariables("SERVER_NAME"),"网上支付IPS接口订单"&ORDERID&",网站："&Request.ServerVariables("SERVER_NAME"),whichProduct,pdid,pingzheng,type1,"在线支付",haveget,havecheck
%>
<!--#include virtual="/inc-freehost-function/htmlwrite.asp"--><%=htmlwrite("html2")%>　返回结果
<%=htmlwrite("html3")%>
支付完成。
用户的原金额：<%=olduser_money%>元<br>
用户的金额变化：<font color=red><%=moneych%>元</font><br>
用户的新金额：<%=newuser_money%>元<br>
<%dsreg.close
set dsreg=nothing
conn.close
set conn=nothing
%>
<%=htmlwrite("html4")%>
<%
end if

if ef then
Response.Redirect "e.asp?e="&ec
end if%>

