<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<!--#include file="md5.inc"-->
<%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_BJ_ShopID")="123" Or Application("NP_BJ_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
    
	 ' 表单的各项参数如下：
	 ' v_rcvname 
	 '      收单人
	 ' v_rcvaddr
	 '      收货地址	       
	 ' v_rcvtel
	 '      订单人电话	
	 ' v_rcvpost
	 '      邮编
	 ' v_ordername
	 '      发单人
	 ' v_amount
	 '      订单金额
	 ' v_ymd      
	 '      订单产生日期    	 
	 ' BillNo
	 '      产生6位订单号
	 ' v_mid
	 '      商户号,这里为测试商户号1001，替换为自己的商户号即可，4位数  
	 ' key
	 '      测试私钥
	 ' v_oid
	 '      订单号，构成格式 年月日-商户号-小时分钟秒   
	 ' v_moneytype
	 '      支付币种0为人民币1为美金        
	 ' v_orderstatus
	 '      配货状态，1配齐0未配齐
	 ' v_url
	 '      商户自定义返回接收支付结果的页面	 
	 ' key_key
	 '      拼凑字符串 
	 ' remark1 
	 '      备注字段1
	 ' remark2 
	 '      备注字段2
	 ' style
	 '      指网关模式0，1
if not ef then
sUserName = LCase(Trim(request.form("USERNAME")))
sShopID = Application("NP_BJ_ShopID")
sOrderMoney=request.form("ORDERMONEY")
If Application("NetPaypercent")>0 Then sOrderMoney=sOrderMoney*(1+Application("NetPaypercent"))
sOrderMoney=FormatNumber(sOrderMoney,2,-1,-1,0)

'v_rcvname=&shouhuorendizhi=&shouhuorendianhua=&shouhuorenyoubian=&dinghuorenxingming=&
'v_oid_l=6943&
'v_orderstatus=0&submit=4&v_action=%CC%E1%BD%BB&v_amount=19.55



name=sUserName
address=Request.Form("shouhuorendizhi")
tel=Request.Form("shouhuorendianhua")
zip=Request.Form("shouhuorenyoubian")
user=Request.Form("dinghuorenxingming")
'amount=Request.Form ("v_amount")
amount=sOrderMoney
id=right("00"&hour(time),2)&right("00"&minute(time),2)&right("00"&second(time),2)

dim key_key,v_mid,v_oid,v_rcvname,v_rcvaddr
dim v_rcvtel,v_rcvpost,v_amount,v_orderstatus,v_url
dim v_ordernam,v_moneytype,yy,mm,dd,v_ymd
v_mid=sShopID
v_oid=request.form("v_oid")
v_rcvname=request.form("v_rcvname")
v_rcvaddr=request.form("shouhuorendizhi")
v_rcvtel=request.form("shouhuorendianhua")
v_rcvpost=request.form("shouhuorenyoubian")
v_amount=amount
v_orderstatus=0'mod
v_ordername=request.form("dinghuorenxingming")
v_moneytype=request.form("v_moneytype")
v_oid_l=id
'v_url="http://www.beijing.com.cn"

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


dim iii,ooo
iii=split(v_amount,".")
if ubound(iii)=0 then
v_amount=cstr(v_amount) & ".00"
else
if len(iii(1))=1 then v_amount=cstr(iii(0)) & "." &cstr(iii(1)) & "0"
if len(iii(1))=2 then v_amount=cstr(v_amount)
if len(iii(1))>2 then v_amount=cstr(iii(0)) & "." & left(iii(1),2)


end if

yy=year(date)
mm=month(now)
if len(mm)=1 then mm="0"&mm
dd=day(Date)
if len(dd)=1 then dd="0"&dd
v_ymd=yy&mm&dd 

count=v_oid_l
v_oid=v_ymd&"-"&v_mid&"-"&count
key_key="0"&v_ymd&amount&name&v_ymd&"-"&v_mid&"-"&id&v_mid&v_url
'Response.write (key_key)
dim md

dim a,b
'set md=server.CreateObject ("md5_VB.md5class")
'f=md.hmac(cstr(key_key),"test")

     dim retMAC
     retMAC=hex_hmac_md5(cstr(key_key),Application("NP_BJ_Key"))





sOrderID = v_oid

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

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

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_ADDR")
		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%>
<br>

<form method="post" action="http://pay.beijing.com.cn/prs/user_payment.checkit" name="E_FORM" target=new>
<input type=submit name=v_action value="首都电子商城网上安全支付平台">
<SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript>
<!--

Sub button1_onclick
	window.history.back 
End Sub

-->
</SCRIPT>
    <input type="button" name="button1" id="button1" value="返回">

	<input type="hidden" name="v_md5info" size="100"  value="<%=retMAC%>">
	<input type="hidden" name="v_mid" value="<%=v_mid%>">
	<input type="hidden" name="v_oid" value="<%=v_oid%>">
	<input type="hidden" name="v_rcvname" value="<%=name%>">
	<input type="hidden" name="v_rcvaddr" value="<%=Request.ServerVariables("SERVER_NAME")%>">
	<input type="hidden" name="v_rcvtel" value="<%=tel%>">
	<input type="hidden" name="v_rcvpost" value="<%=zip%>">
	<input type="hidden" name="v_amount" value="<%=amount%>">
	<input type="hidden" name="v_ymd"  value="<%=v_ymd%>">
	<input type="hidden" name="v_orderstatus"  value="0">
	<input type="hidden" name="v_ordername"  value="<%=user%>">
	<input type="hidden" name="v_moneytype"  value="0">
	<input type="hidden" name="v_url" value="<%=v_url%>">
</form>

<%=htmlwrite("html4")%>
<%
end if

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