<!--#include file="../../conn/conn.asp"-->
<!--#include file="../../inc/Commoncode.asp"-->
<!--#include file="../../inc/pay_md5.asp"-->
<!--#include file="../../inc/base64.asp"-->
<%
'获取参数
cmdno			= Request("cmdno")
pay_result		= Request("pay_result")
pay_info		= Request("pay_info")
bill_date		= Request("date")
bargainor_id	= Request("bargainor_id")
transaction_id	= Request("transaction_id")
sp_billno		= Request("sp_billno")
total_fee		= Request("total_fee")
fee_type		= Request("fee_type")
attach			= Request("attach")
md5_sign		= Request("sign")

set rs=server.CreateObject("adodb.recordset")
query="select * from Job_pay_online where chk=1 and payflag=6"
rs.open query,conn,1,1
if not rs.eof then
ipayno=rs("shbh")
ipaykey=rs("pay_key")
else
retcode  = "4"
retMsg	 = "支付接口配置错误！"
end if
rs.close  

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

spid=replace(strAnsi2Unicode(Base64decode(strUnicode2Ansi(ipayno))),chr(13)&chr(10),"<br>")
sp_key=replace(strAnsi2Unicode(Base64decode(strUnicode2Ansi(ipaykey))),chr(13)&chr(10),"<br>")

origText ="cmdno=" & cmdno & "&pay_result=" & pay_result &_ 
		       "&date=" & bill_date & "&transaction_id=" & transaction_id &_
			   "&sp_billno=" & sp_billno & "&total_fee=" & total_fee &_
			   "&fee_type=" & fee_type & "&attach=" & attach 
			   
'验签函数
localSignText = UCase(md5(origText & "&key=" & sp_key)) ' 转换为大写
retcode = "0"
retmsg ="支付成功"

If bargainor_id <> spid Then
	retcode	 = "1"
	retMsg	 = "商户号错误"
Else 
' 验签
	If localSignText <> md5_sign Then
		retcode = "2"
		retMsg	 = "签名错误"
	Else
' 检查财付通返回值
		If pay_result <> 0 Then
			retcode  = "3"
			retMsg	 = "财付通返回支付失败"
		End If
	End If
End If

trans_string = "retcode=" & retcode & "&retmsg=" & retmsg

if retcode = "0" then
	payok=true
	query = "select * from JOB_pay_back where pay_oid='"&sp_billno&"'"
	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='"&sp_billno&"'")
	sql="select * from job_member where member_login='"&Request.Cookies(FRHRCMS)("user_login")&"'"
	rs.open sql,conn,1,3
	If rs.RecordCount <> 1 Then
		payok=false
		rs.close
		set rs=nothing
	else
		rs("Member_balance")=rs("Member_balance")+fix(total_fee/100)
		rs.update
		rs.close
		set rs=nothing
	end if
end if
if payok then
	response.Write("<meta name=""TENCENT_ONLINE_PAYMENT"" content=""China TENCENT"">")
	Response.write "<script language=javascript>"
	Response.write "window.location.href='" & SiteUrl&InstallDir&"onlinepay/chinabank/tenpay_show.asp?" & trans_string & "';"  '替换成商户网站相应页面地址
	Response.write "</script>"	
else
	conn.execute("Update JOB_pay_back set pay_pstring='"&trans_string&"',pay_isucceed=2 where pay_oid='"&sp_billno&"'")
	response.Write("<meta name=""TENCENT_ONLINE_PAYMENT"" content=""China TENCENT"">")
	Response.write "window.location.href='" & SiteUrl&InstallDir&"onlinepay/chinabank/tenpay_show.asp?" & trans_string & "';"  '替换成商户网站相应页面地址
	Response.write "</script>"	
end if
%>