<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%

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

'首先将md5.asp包含进来
'然后就可以按照下面的方法进行使用：

'v_mid   = Application("NP_Ipay_ShopID")     '商户编号，改成IPAY负责分配给商户的编号
v_key     =Application("NP_Ipay_Key")     '默认的私钥值，更改私钥后要修改这里

'1----------------接收IPAY平台返回信息---------------------------------------------------------------------------
v_pdate	   =Request.Form("v_date")         
v_mid   = Request.Form("v_mid") 
v_oid      =Request.Form("v_oid")         '支付定单号
v_pamount  =Request.Form("v_amount")         '支付金额
'v_pmode	   =Request.Form("v_pmode")         '支付
v_pstatus  =Request.Form("v_status")         '支付状态，如果为”20“，则表示支付成功
'v_pstring  =Request.Form("v_pstring")         '支付结果说明

v_aspmd5   =Request.Form("v_md5")         '数字签名


'2----------------重新计算md5值----------------------------------------------------------------------------------

dim md5string 
md5string=md5(cstr(v_pdate&v_mid&v_oid&v_pamount&v_pstatus&v_key))    

                               
'3----------------判断返回信息，如果支付成功，并且支付结果可信，则进行进一步的操作-------------------------------
if v_aspmd5<>md5string then      
		ef=True
		ec="非法加密！"    
end if

if v_mid<>Application("NP_Ipay_ShopID") then      
		ef=True
		ec="商号不对！"    
end if

if not ef then
SHOPID = Application("NP_Ipay_ShopID")
ORDERID = v_oid
SucceedFlag = v_pstatus
ORDERMONEY = v_pamount

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,1,3
if dsNP.eof then
		ef=True
		ec="不存在的订单！"
else
  if dsNP("SucceedFlag") =0 then
		ef=True
		ec="状态已更新过了，不能重复操作！"
  end if
'  if dsNP("ORDERMONEY") <>ORDERMONEY then
'		ef=True
'		ec="金额不正确！"
'  end if
end if
end if

if not ef then
if cstr(SucceedFlag)<>"00" then
dsNP("SucceedFlag")=SucceedFlag
dsNP.update
con="error"
con=v_pstring
		ef=True
		ec="支付不成功！返回状态是："&con
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")=0
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,"网上支付ipay4接口订单"&ORDERID&",网站："&Request.ServerVariables("SERVER_NAME"),"网上支付ipay4接口订单"&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%>
