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

<%  
On error resume next 

key=ycnewkey50

response.Write "<xml><return_code>SUCCESS</return_code></xml>"

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 

'截取返回xml
Function mysubstr(s, sstart, sstop)
	Dim src,p1
	src = s
	p1 = instr(src, sstart)
	src = Mid(src, p1+Len(sstart), Len(src)-Len(sstart)-p1+1)
	p1 = instr(src, sstop)
	src = Mid(src, 1, p1-1)
	mysubstr = src
End Function

xmlCount = Request.TotalBytes
jsonRequest = Request.BinaryRead(xmlCount)  
jsonstr = BytesToBstr(jsonRequest, "utf-8") 

If xmlCount>0 Then

			
			return_msg= mysubstr(jsonstr, "<return_msg><![CDATA[", "]]></return_msg>")
			sign_type= mysubstr(jsonstr, "<sign_type><![CDATA[", "]]></sign_type>")
			appid= mysubstr(jsonstr, "<appid><![CDATA[", "]]></appid>")
			charset= mysubstr(jsonstr, "<charset><![CDATA[", "]]></charset>")
			nonce_str  = mysubstr(jsonstr, "<nonce_str><![CDATA[", "]]></nonce_str>")
			out_trade_no  = mysubstr(jsonstr, "<out_trade_no><![CDATA[", "]]></out_trade_no>")
			transaction_id  = mysubstr(jsonstr, "<transaction_id><![CDATA[", "]]></transaction_id>")
			version= mysubstr(jsonstr, "<version><![CDATA[", "]]></version>")
			sign  = mysubstr(jsonstr, "<sign><![CDATA[", "]]></sign>")
			result_code = mysubstr(jsonstr, "<result_code><![CDATA[", "]]></result_code>")
			mch_id  = mysubstr(jsonstr, "<mch_id><![CDATA[", "]]></mch_id>")
			attach  = mysubstr(jsonstr, "<attach><![CDATA[", "]]></attach>")
			total_fee  = mysubstr(jsonstr, "<total_fee><![CDATA[", "]]></total_fee>")
			pass_trade_no  = mysubstr(jsonstr, "<pass_trade_no><![CDATA[", "]]></pass_trade_no>")
			time_end  = mysubstr(jsonstr, "<time_end><![CDATA[", "]]></time_end>")
			method= mysubstr(jsonstr, "<method><![CDATA[", "]]></method>")
			return_code  = mysubstr(jsonstr, "<return_code><![CDATA[", "]]></return_code>")
			openid  = mysubstr(jsonstr, "<openid><![CDATA[", "]]></openid>")
			
			out_transaction_id  = mysubstr(jsonstr, "<out_transaction_id><![CDATA[", "]]></out_transaction_id>")
			trade_type  = mysubstr(jsonstr, "<trade_type><![CDATA[", "]]></trade_type>")
			trade_state  = mysubstr(jsonstr, "<trade_state><![CDATA[", "]]></trade_state>")
			err_code  = mysubstr(jsonstr, "<err_code><![CDATA[", "]]></err_code>")
			err_code_des  = mysubstr(jsonstr, "<err_code_des><![CDATA[", "]]></err_code_des>")
			device_info  = mysubstr(jsonstr, "<device_info><![CDATA[", "]]></device_info>")
			buyer_id  = mysubstr(jsonstr, "<buyer_id><![CDATA[", "]]></buyer_id>")
			bank_type  = mysubstr(jsonstr, "<bank_type><![CDATA[", "]]></bank_type>")
			cash_fee  = mysubstr(jsonstr, "<cash_fee><![CDATA[", "]]></cash_fee>")
			coupon_fee  = mysubstr(jsonstr, "<coupon_fee><![CDATA[", "]]></coupon_fee>")
			fee_type  = mysubstr(jsonstr, "<fee_type><![CDATA[", "]]></fee_type>")
			is_subscribe  = mysubstr(jsonstr, "<is_subscribe><![CDATA[", "]]></is_subscribe>")
			buyer_logon_id= mysubstr(jsonstr, "<buyer_logon_id><![CDATA[", "]]></buyer_logon_id>")
			fund_bill_list= mysubstr(jsonstr, "<fund_bill_list><![CDATA[", "]]></fund_bill_list>")
			

			str=""
			if appid<>"" then str=str&"appid="&appid&"&"
			if attach<>"" then str=str&"attach="&attach&"&"
			if bank_type<>"" then str=str&"bank_type="&bank_type&"&"
			if buyer_id<>"" then str=str&"buyer_id="&buyer_id&"&"
			if buyer_logon_id<>"" then str=str&"buyer_logon_id="&buyer_logon_id&"&"
			if cash_fee<>"" then str=str&"cash_fee="&cash_fee&"&"
			if charset<>"" then str=str&"charset="&charset&"&"
			if coupon_fee<>"" then str=str&"coupon_fee="&coupon_fee&"&"
			if device_info<>"" then str=str&"device_info="&device_info&"&"
			if err_code<>"" then str=str&"err_code="&err_code&"&"
			if err_code_des<>"" then str=str&"err_code_des="&err_code_des&"&"
			if fee_type<>"" then str=str&"fee_type="&fee_type&"&"
			if fund_bill_list<>"" then str=str&"fund_bill_list="&fund_bill_list&"&"
			if is_subscribe<>"" then str=str&"is_subscribe="&is_subscribe&"&"
			if mch_id<>"" then str=str&"mch_id="&mch_id&"&"
			if method<>"" then str=str&"method="&method&"&"
			if nonce_str<>"" then str=str&"nonce_str="&nonce_str&"&"
			if openid<>"" then str=str&"openid="&openid&"&"
			if out_trade_no<>"" then str=str&"out_trade_no="&out_trade_no&"&"
			if out_transaction_id<>"" then str=str&"out_transaction_id="&out_transaction_id&"&"
			if pass_trade_no<>"" then str=str&"pass_trade_no="&pass_trade_no&"&"
			if result_code<>"" then str=str&"result_code="&result_code&"&"
			if return_code<>"" then str=str&"return_code="&return_code&"&"
			if return_msg<>"" then str=str&"return_msg="&return_msg&"&"
			if sign_type<>"" then str=str&"sign_type="&sign_type&"&"
			if time_end<>"" then str=str&"time_end="&time_end&"&"
			if total_fee<>"" then str=str&"total_fee="&total_fee&"&"
			if trade_state<>"" then str=str&"trade_state="&trade_state&"&"
			if trade_type<>"" then str=str&"trade_type="&trade_type&"&"
			if transaction_id<>"" then str=str&"transaction_id="&transaction_id&"&"
			if version<>"" then str=str&"version="&version&"&"
			str=str&"key="&key
			sign2=UCase(md5(str))
						
			
			'rs.open "select * from ayceshibz",conn,1,3
			'rs.addnew
			'rs("aybz1")=jsonstr
			'rs("aybz2")=str
			'rs("aybz3")=sign
			'rs("aybz4")=sign2
			'rs.update
			'rs.close
				

						
			if sign=sign2 then
					
				trade_no = transaction_id
				out_trade_no = out_trade_no
				pay_body = attach
				total_fee=total_fee/100
				
conn.Execute("Insert Into aypayhuitiao(aypaydd,aypaytd,aypayfyu,aypayyu,aypaycon) values('"&out_trade_no&"','优畅50','"&request.ServerVariables("SERVER_NAME")&"','"&request.ServerVariables("HTTP_REFERER")&"','"&jsonstr&"')")
	
				
				'执行开始***************************************************************************
				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)

%>