<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> 
<% Response.Charset = "utf-8" %>
<!--#include virtual="/inc/payok.asp"-->
<!--#include virtual="/inc/md5_utf8.asp"-->

<%  
response.Write "{""success"":""true""}"

key=toparkey("zlkey")

Function BytesToBstr(body,Cset) 
dim objstream 
set objstream = Server.CreateObject("adodb.stream") 
objstream.Type = 1
objstream.Mode =3 
objstream.Open
objstream.Write body
objstream.Position = 0 
objstream.Type = 2 
objstream.Charset = Cset 
BytesToBstr = objstream.ReadText  
objstream.Close 
set objstream = nothing 
End Function 

xmlCount = Request.TotalBytes  
If xmlCount>0 Then
	jsonRequest = Request.BinaryRead(xmlCount)  
	jsonResult = BytesToBstr(jsonRequest, "utf-8") 
		
	
	Set json = toObject(jsonResult)
			
	amount=json.amount
	appid=json.appid
	body=json.body
	fee=json.fee
	mchntId=json.mchntId
	mchntOrderNo=json.mchntOrderNo
	orderDt=json.orderDt
	orderNo=json.orderNo
	paidTime=json.paidTime
	paySt=json.paySt
	subject=json.subject
	signature=json.signature
	
	openId=json.openId
	description=json.description
	extra=json.extra
	outTransactionId=json.outTransactionId
	
	str=""
	str="amount="&amount&"&"
	str=str&"appid="&appid&"&"
	str=str&"body="&body&"&"
	if description<>"" then str=str&"description="&description&"&"
	if extra<>"" then str=str&"extra="&extra&"&"
	str=str&"fee="&fee&"&"
	str=str&"mchntId="&mchntId&"&"
	str=str&"mchntOrderNo="&mchntOrderNo&"&"
	if openId<>"" then str=str&"openId="&openId&"&"
	str=str&"orderDt="&orderDt&"&"
	str=str&"orderNo="&orderNo&"&"
	if outTransactionId<>"" then str=str&"outTransactionId="&outTransactionId&"&"
	str=str&"paidTime="&paidTime&"&"
	str=str&"paySt="&paySt&"&"
	str=str&"subject="&subject&"&"
	str=str&"key="&key
	sign=md5(str)

	
	'rs.open "select * from ayceshibz",conn,1,3
	'rs.addnew
	'rs("aybz1")=jsonResult
	'rs("aybz2")=signature
	'rs("aybz3")=sign
	'rs("aybz4")=str
	'rs.update
	'rs.close
	
	'set fs= createobject("scripting.filesystemobject")
	'set ts=fs.OpenTextFile(Server.MapPath("native_call.log"), 8, true)
	'ts.writeline(jsonResult)
	'ts.close
	
	
	if sign=signature then
			
		trade_no = outTransactionId
		out_trade_no = mchntOrderNo
		pay_body = body
		total_fee=amount/100
		
conn.Execute("Insert Into aypayhuitiao(aypaydd,aypaytd,aypayfyu,aypayyu,aypaycon) values('"&out_trade_no&"','掌灵1','"&request.ServerVariables("SERVER_NAME")&"','"&request.ServerVariables("HTTP_REFERER")&"','"&jsonResult&"')")
		
		
		'执行开始***************************************************************************
		if pay_body="buy" then
		call payokbuy(out_trade_no,trade_no,total_fee,"no")	
		end if
	
		if pay_body="chongzhi" then
		call payokchong(out_trade_no,trade_no,total_fee,"no")
		end if
		'执行结束***************************************************************************

	end if
	
	
end if



'response.Write "<br><br>"
'response.Write str
'response.Write "<br><br>"
'response.Write "<br>返回签名54dc6ffb78979a5a9c62aa5a573b0bc0<br>"
'response.Write "验签签名"&md5(str)

%>