<!--#include file="../../conn/conn.asp"-->
<!--#include file="../../inc/Commoncode.asp"-->
<!--#include file="../../inc/pay_md5.asp"-->
<!--#include file="../../inc/base64.asp"-->
<%
set rs=server.CreateObject("adodb.recordset")
query="select * from Job_pay_online where chk=1 and payflag=1"
rs.open query,conn,1,1
if not rs.eof then
ipayid=rs("shid")
ipaykey=rs("pay_key")
else
retcode  = "4"
retMsg	 = "支付接口配置错误！"
end if
rs.close  

if ipayno="" then
retcode  = "4"
retMsg	 = "支付接口配置错误！"
end if

partner=replace(strAnsi2Unicode(Base64decode(strUnicode2Ansi(ipayid))),chr(13)&chr(10),"<br>")
key=replace(strAnsi2Unicode(Base64decode(strUnicode2Ansi(ipaykey))),chr(13)&chr(10),"<br>")

out_trade_no	=DelStr(Request.Form("out_trade_no"))      '获取定单号
total_fee		=DelStr(Request.Form("total_fee"))         '获取支付的总价格
'如需获取其它参数，可填写 参数 =DelStr(Request.Form("获取参数名"))
	
'*******************判断消息是不是支付宝发出***********************
alipayNotifyURL = "http://notify.alipay.com/trade/notify_query.do?"
alipayNotifyURL = alipayNotifyURL &"partner=" & partner & "&notify_id=" & request.Form("notify_id")
Set Retrieval = Server.CreateObject("Msxml2.ServerXMLHTTP.3.0")
Retrieval.setOption 2, 13056 
Retrieval.open "GET", alipayNotifyURL, False, "", "" 
Retrieval.send()
ResponseTxt = Retrieval.ResponseText
Set Retrieval = Nothing
'*******************************************************************

'*******************获取支付宝POST过来通知消息**********************
For Each varItem in Request.Form
	mystr=varItem&"="&Request.Form(varItem)&"^"&mystr
Next 
If mystr<>"" Then 
	mystr=Left(mystr,Len(mystr)-1)
End If 
mystr = SPLIT(mystr, "^")
Count=ubound(mystr)
'对参数排序
For i = Count TO 0 Step -1
	minmax = mystr( 0 )
	minmaxSlot = 0
	For j = 1 To i
		mark = (mystr( j ) > minmax)
		If mark Then 
			minmax = mystr( j )
			minmaxSlot = j
		End If 
	Next
	If minmaxSlot <> i Then 
		temp = mystr( minmaxSlot )
		mystr( minmaxSlot ) = mystr( i )
		mystr( i ) = temp
	End If
Next
'构造md5摘要字符串
For j = 0 To Count Step 1
	value = SPLIT(mystr( j ), "=")
	If  value(1)<>"" And value(0)<>"sign" And value(0)<>"sign_type"  Then
		If j=Count Then
			md5str= md5str&mystr( j )
		Else 
			md5str= md5str&mystr( j )&"&"
		End If 
	End If 
Next
md5str=md5str&key
mysign=md5(md5str)

'*************************交易状态返回处理*************************
If mysign=request.Form("sign") And ResponseTxt="true" Then 	
	If request.Form("trade_status") = "TRADE_FINISHED" Then 
		query = "select * from JOB_pay_back where pay_oid='"&out_trade_no&"'"
		rs.Open query, conn, 1, 1
		If rs.RecordCount <> 1 Then
		retcode  = "5"
		retMsg	 = "接口通讯错误！"
		ElseIf rs("pay_isucceed") = 1 Then
		retcode  = "6"
		retMsg	 = "该定单已支付完成！"
		End If
		rs.Close
		
		conn.execute("Update JOB_pay_back set pay_isucceed =1 where pay_oid='"&out_trade_no&"'")
		sql="select * from job_member where member_login='"&Request.Cookies(FRHRCMS)("user_login")&"'"
		rs.open sql,conn,1,3
		If rs.RecordCount <> 1 Then
			rs.close
			set rs=nothing
		else
			rs("Member_balance")=rs("Member_balance")+fix(total_fee)
			rs.update
			rs.close
			set rs=nothing
		end if 
	 	returnTxt	= "success"
	Else
		returnTxt	= "fail"
	End If
	Response.Write returnTxt
Else
response.write "fail"
End If

Function DelStr(Str)
	If IsNull(Str) Or IsEmpty(Str) Then
		Str	= ""
	End If
	DelStr	= Replace(Str,";","")
	DelStr	= Replace(DelStr,"'","")
	DelStr	= Replace(DelStr,"&","")
	DelStr	= Replace(DelStr," ","")
	DelStr	= Replace(DelStr,"　","")
	DelStr	= Replace(DelStr,"%20","")
	DelStr	= Replace(DelStr,"--","")
	DelStr	= Replace(DelStr,"==","")
	DelStr	= Replace(DelStr,"<","")
	DelStr	= Replace(DelStr,">","")
	DelStr	= Replace(DelStr,"%","")
End Function
%>