<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%> 
<!--#include file="../../inc/payok.asp"--> 
<!--#include file="../../inc/md52.asp"--> 
<!--#include file="class/inc.asp"-->

<%

'这个页面是获取微信支付以后回调页面
set objXML = Server.CreateObject("Msxml2.DOMDocument")
objXML.resolveExternals = false
objXML.async = false
objXML.load(request)
set parentNodes= objXML.documentElement.selectSingleNode("//xml")
childNodesLength=parentNodes.ChildNodes.Length
notify_jg="abc"
Set d =Server.CreateObject("Scripting.Dictionary")
d.Add "tongzhiym",notify_jg 
for i=0 to childNodesLength-1
   if parentNodes.ChildNodes(i).nodeName<>"sign" then
   	d.Add parentNodes.ChildNodes(i).nodeName,parentNodes.ChildNodes(i).text
   else
   	sign=parentNodes.ChildNodes(i).text
   end if
next

d.Add "paykey", skey 
return_code=d("return_code")
result_code=d("result_code")
transaction_id=d("transaction_id")  '微信交易号
out_trade_no=d("out_trade_no")
total_fee=d("total_fee")
attach=d("attach")  '自定义数据
sfd=parseURL(d)

Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.Open "POST", paytoUrl, false
xmlhttp.SetRequestHeader "content-type", "application/x-www-form-urlencoded"
xmlhttp.Send sfd		
sfdx=xmlhttp.responseTEXT
		
'log_result("notify:qstring:"&chr(10)& sfdx &"：" & sign  &chr(10))

			'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 sfdx=sign then
	xmlContent = "<xml>"
	xmlContent	= xmlContent & "<return_code>SUCCESS</return_code>"
	xmlContent	= xmlContent & "</xml>"
		
	if return_code="FAIL" then
		log_result("【通信出错】")
	elseif result_code="FAIL" then
		log_result("【业务出错】")
	else
		


	pay_body=attach
	total_fee=total_fee/100
	trade_no=transaction_id
	
conn.Execute("Insert Into aypayhuitiao(aypaydd,aypaytd,aypayfyu,aypayyu,aypaycon) values('"&out_trade_no&"','微信官方','"&request.ServerVariables("SERVER_NAME")&"','"&request.ServerVariables("HTTP_REFERER")&"','"&sfd&"')")
		
	
	'执行开始***************************************************************************
	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
	'执行结束***************************************************************************
	
	
	
	
		'此处应该更新一下订单状态，商户自行增删操作
		'log_result("【支付成功】")
	end if
else
	xmlContent = "<xml>"
	xmlContent	= xmlContent & "<return_code>FAIL</return_code>"
	xmlContent	= xmlContent & "<return_code>签名失败</return_code>"
	xmlContent	= xmlContent & "</xml>"
end if

'log_result(""&attach&"")
'log_result(""&total_fee&"")
'log_result(""&out_trade_no&"")
'log_result(""&transaction_id&"")

response.Write xmlContent


Function log_result(sWord)
		set fs= createobject("scripting.filesystemobject")
		set ts=fs.OpenTextFile(Server.MapPath("./native_call.log"), 8, true)
		ts.writeline(sWord)
		ts.close
		set ts=Nothing
		set fs=Nothing
End Function
%>