<%@ 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
If Application("NP_Ipay_ShopID")="123" Or Application("NP_Ipay_ShopID")="" Then
		ef=True
		ec="商号尚未设置！"
End if
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
sUserName = request.form("USERNAME")
sShopID = Application("NP_Ipay_ShopID")
sOrderMoney=request.form("ORDERMONEY")
If Application("NetPaypercent")>0 Then sOrderMoney=sOrderMoney*(1+Application("NetPaypercent"))
sOrderMoney=FormatNumber(sOrderMoney,2,-1,-1,0)

	n=Cstr(hour(now)&minute(now)&second(now))
if 	application("orderid")=n then n=Cstr(Clng(n)+1)
application("orderid")=n
n=cstr(n)
ln=len(n)
if ln=1 then n="00000"&n
if ln=2 then n="0000"&n
if ln=3 then n="000"&n
if ln=4 then n="00"&n
if ln=5 then n="0"&n
sOrderID = n

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



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

v_mid   = sShopID     '商户编号，改成IPAY负责分配给商户的编号
v_oid   =sOrderID    '定单号，由商户负责产生的6位数字编号，一天内不能重复
v_amount=sOrderMoney     '定单金额，单位元，小数点后保留两位，如10或12.34，如果为整数，则不需要小数点
v_key     =Application("NP_Ipay_Key")     '默认的私钥值，更改私钥后要修改这里
dim md5string 
v_email=dsreg("email")
v_mobile="13810000000"
'md5string=md5(cstr(v_mid&v_oid&v_amount&v_key))
v_md5=md5(v_mid+v_oid+v_amount+v_email+ v_mobile +v_key)

	sReturnURL="http://"&Request.ServerVariables("SERVER_NAME")&"/netpay/ipay4/receive.asp"
	v_url=sReturnURL

dsNP.addnew
dsNP("username")=sUserName
dsNP("SHOPID")=sShopID
dsNP("ORDERID")=sOrderID
dsNP("ORDERMONEY")=sOrderMoney
dsNP("SUCCEEDFLAG")=99
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 method="post" name="post" action="http://www.ipay.cn/4.0/bank.shtml">
<input type=HIDDEN name="v_mid"    value="<%=v_mid%>"> 	
<input type=HIDDEN name="v_oid"    value="<%=v_oid%>">  	
<input type=HIDDEN name="v_amount" value="<%=v_amount%>">  
<input type=HIDDEN name="v_rname"  value="<%=sUserName%>">
<input type=HIDDEN name="v_email" value="<%=v_email%>">
<input type=HIDDEN name="v_mobile"   value="<%=v_mobile%>">
<input type=HIDDEN name="v_name"value="<%=sUserName%>">
<input type=HIDDEN name="v_md5"    value="<%=v_md5%>"> 
<input type="hidden" name="v_url" value="<%=v_url%>">
<input type="hidden" name="v_comment" value="<%=Request.ServerVariables("SERVER_NAME")%>">
<input type=submit name=v_action value="下一步进入付费流程>>>">
</form>
<%=htmlwrite("html4")%>
<%
end if

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