<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%If Request.Form ("username")="" or RegExpTest("[^A-Za-z0-9]",Request.Form ("username")) Then
	ef=True
	ec="用户名没填或非法！"
ElseIf Not IsNumeric(request.form("ORDERMONEY")) Then
	ef=True
	ec="金额必须是数字！"
ElseIf Clng(request.form("ORDERMONEY"))<Application("netpaylessmoney") Then
	ef=True
	ec="金额不能小于"&Application("netpaylessmoney")&"元"
End if

'验证会员资格
If not ef then
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
Set dsreg = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_AGENT where username='"&Request.Form ("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='"&Request.Form ("username")&"'"
		dsreg.Open Sql,conn,1,3
If dsreg.Eof Then
		ef=True
		ec="会员名不存在！"
end if
end if
end If

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

if not ef then
sUserName = request.form("USERNAME")
sShopID = Application("NP_NPS_ShopID")
sOrderMoney=request.form("ORDERMONEY")
If Application("NetPaypercent")>0 Then sOrderMoney=sOrderMoney*(1+Application("NetPaypercent"))
sOrderMoney=FormatNumber(sOrderMoney,2,-1,-1,0)

sReturnURL="http://"&Application("sitearry")(0)&"/netpay/nps4/receive.asp"	

    sOrderID = year(Now)&right("00"& month(Now),2)& right("00" & day(Now),2)& right("00" & hour(Now),2)& right("00"& Minute(Now),2)& right( "00"& second(Now),2)
Set dsNP = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Netpay where ORDERID='"&ORDERID&"'"
		dsNP.Open Sql,conn,1,3
if not dsNP.eof then
		ef=True
		ec="重复订单！"
end if
end if

if not ef then



' 接收订单提交信息
	m_id		= 	sShopID
	m_orderid	= 	sOrderID
	m_oamount	= 	sOrderMoney
	m_ocurrency = 	"1"
	m_url		= 	sReturnURL
	m_language	= 	"1"
	s_name		= 	sUserName
	s_addr		= 	"null"
	s_postcode	= 	"0"
	s_tel		= 	"0"
	s_eml		= 	"null"
	r_name		= 	sUserName
	r_addr		= 	"null"
	r_postcode	= 	"0"
	r_tel		= 	"0"
	r_eml		= 	"null"
	m_ocomment	= 	"7i24.COM_NPS支付平台"
	m_status	=	0
	modate		= 	NOW
	






	' 创建NPS安全组件
	on error resume next
	Set NPSMAC = Server.CreateObject("NPSDigest.NPSSecurity")
	if -2147221005 = Err then
response.write "服务器没有安装NPS组件，请联系NPS安装并注册组件。"
response.end
	end if
	
	'组织订单信息
	m_info = m_id&"|"&m_orderid&"|"&m_oamount&"|"&m_ocurrency&"|"&m_url&"|"&m_language
	s_info = s_name&"|"&s_addr&"|"&s_postcode&"|"&s_tel&"|"&s_eml&"|"&r_name
	r_info = r_addr&"|"&r_postcode&"|"&r_tel&"|"&r_eml&"|"&m_ocomment&"|"&m_status&"|"&modate

	NPSMAC.OrderInfo =  m_info&"|"&s_info&"|"&r_info
	' 设置密钥
	NPSMAC.NPSKey = Application("NP_NPS_Key")
	
	' 加密
	OrderInfo = NPSMAC.GetEncrypt
	NPSMAC.OrderInfo = OrderInfo
	digest = NPSMAC.GetDigest



dsNP.addnew
dsNP("username")=sUserName
dsNP("SHOPID")=sShopID
dsNP("ORDERID")=sOrderID
dsNP("ORDERMONEY")=sOrderMoney
dsNP("SUCCEEDFLAG")=0
dsNP("paytime")=now
dsNP("ip")=Request.ServerVariables("REMOTE_HOST")
		dsNP.update
		dsNP.close
%>
<!--#include virtual="/inc-freehost-function/htmlwrite.asp"--><%=htmlwrite("html2")%>　网上支付
<%=htmlwrite("html3")%>
<br>
用户名:<%=sUserName%> 请确认用户名是否正确 支付金额:<%=sOrderMoney%> 元<%If Application("NetPaypercent")>0 Then %>(增加<%=Application("NetPaypercent")*100%>%手续费)<%End if%>
<form name="FORM" method="post" action="https://payment.nps.cn/ReceiveMerchantAction.do">
	<input type="hidden" name="OrderMessage" value="<%=OrderInfo%>">
	<input type="hidden" name="digest" value="<%=digest%>">
		<input type="hidden" name="M_ID" value="<%=m_id%>">
	<input type=submit name=s value="下一步进入付费流程>>>">
</form>
<%=htmlwrite("html4")%>
<%
end if

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