<%@ 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_IPS_ShopID")="1234" Or Application("NP_IPS_ShopID")="" Then
		ef=True
		ec="商号尚未设置！"
End if
end If

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

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

'订单交易日期(YYYYMMDD)，建议商户取系统当前日期作为订单交易日期
datestr=year(now())&right("0"&month(now()),2)&right("0"&day(now()),2)
'response.write datestr
'response.end
'订单号后6位，订单号为12位：6位商户号+6位随机号，一天内不能重复
'此例子给了一个订单号生成算法，取系统当前时间做为订单号
'但我们建议商户自己建立一个sequence序列号来作为6位随机号
billstr=(hour(now())+54)&(minute(now())+21)&(second(now())+19)

ORDERID=Application("NP_IPS_ShopID")&billstr

signmd5=MD5(ORDERID&amount&datestr&Application("NP_IPS_Key"))  '如果采用OrderEncodeType=1的方式提交的话采用此方式加密

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

dsNP.addnew
dsNP("username")=sUserName
dsNP("SHOPID")=sShopID
dsNP("ORDERID")=ORDERID
dsNP("ORDERMONEY")=sOrderMoney
dsNP("SUCCEEDFLAG")=0
dsNP("paytime")=now
dsNP("ip")=Request.ServerVariables("REMOTE_ADDR")
		dsNP.update
		dsNP.close
%>
<!--#include virtual="/inc-freehost-function/htmlwrite.asp"--><%=htmlwrite("html2")%>　网上支付
<%=htmlwrite("html3")%><br>

	<%'测试环境,用商户号000004,测试密码88888888%>
	<!--<form action="https://www.ips.net.cn/ipay/test_ipayment.asp" METHOD=POST name="frm1">-->
	<%'正式环境%>
	<form action="https://www.ips.com.cn/ipay/ipayment.asp" METHOD=POST name="frm1">
	<table width="400" border="1" cellspacing="0" cellpadding="3" bordercolordark="#FFFFFF" bordercolorlight="#333333" bgcolor="#F0F0FF" align="center">

		<tr> 
			<td>订单号</td>
			<td><input type="text" name="billNo" size="16" value="<%=ORDERID%>"></td>
		</tr>
		<tr> 
			<td>金&nbsp;&nbsp;额</td>
			<td><input type="text" name="amount" size="16" value="<%=request.form("ORDERMONEY")%>" readonly="true">
			  元<%If Application("NetPaypercent")>0 Then %>(增加<%=Application("NetPaypercent")*100%>%手续费)<%End if%></td>
		</tr>
		<tr> 
			<td colspan="2"><div align="center"><input type="submit" value="下一步" name="B1"></div></td>
		</tr>
	</table>
	<%'将商户返回地址存于此字段%>
	<input type="hidden" name="merchanturl" value="<%="http://"&Request.ServerVariables("SERVER_NAME")&"/netpay/ips/receive.asp"%>">
	<input type="hidden" name="mer_code" size="16" value="<%=Application("NP_IPS_ShopID")%>">
    <input type="hidden" name="attach" size="16" value="<%=sUserName%>">	
    <input name="lang" type="hidden" value="1">
    <input name="currency" value="01" type=hidden>
    <input type="hidden" name="date" size="16" value="<%=datestr%>">
    <input type="hidden" name="SignMD5" size="35" value="<%=signmd5%>">
    <input name="OrderEncodeType" value="1" type=hidden>
    <input name="RetEncodeType" value="2" type=hidden> 
    <input name="RetType" value="brower" type=hidden> 
    <input type="hidden" name="DispAmount" size="16" value="<%=request.form("ORDERMONEY")%>">  
        </form> 
<%=htmlwrite("html4")%>
<%
end if

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