<!--#include file="../inc/config.asp"-->
<!--#include file="../inc/conn.asp"-->
<!--#include file="../inc/sql_filter.asp"-->
<!--#include file="../inc/md5.asp"-->
<%
Response.ContentType="application/xml"
Response.Charset="gb2312" 
Response.Write("<?xml version=""1.0"" encoding=""gb2312""?>")
response.write("<root>"&chr(10))
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'TotCms会员接口
'参数说明：
'GetKey:应用端提供的访问密钥,此密钥只有和系统设置的密钥相同才具有访问权限
'GetAction：需要执行的动作(1=读取会员信息,2=会员登录,3=积分，4=金币,5=个人会员资料,6=企业会员资料,7扣除积分)
'GetUserId：提交过来的用户ID
'GetUserPass：提交过来的用户密码
'ReturnStr：返回整形数据（0=正常，1=提交数据非法，2=密钥错误，3=用户ID错误，4=密码错误，5=用户被锁定，6=用户不存在）
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
dim GetKey,GetAction,GetUserId,GetUserPass,ReturnStr
ReturnStr=0
GetKey=request.QueryString("GetKey")
GetAction=Cint(request.QueryString("GetAction"))
if(GetKey=MemberGenKey) then
	if(GetAction=1) then
		Call ShowMemberInfo()
	elseif(GetAction=2) then
		Call MemberLogin()
	elseif(GetAction=3) then
		Call MemberScore()
	elseif(GetAction=4) then
		Call MemberMoney()
	elseif(GetAction=5) then
		Call ShowPersonalInfo()
	elseif(GetAction=6) then
		Call ShowEnterpriseInfo()
	elseif(GetAction=7) then
		Call MinusScore()
	else
		ReturnStr=1
	end if
else
	ReturnStr=2
end if
call ReturnStatus()
'''''''''''''''''''''''''''''''''''
Function ReturnStatus
	response.write("<result>"&ReturnStr&"</result>"&chr(10))
end Function

''''''''''''''''''''
'会员金币
''''''''''''''''''''
Function MemberMoney
	dim VarMoney,ret,VarPayType,VarPayDesc,VarPayFrom
	GetUserId=request.queryString("GetUserId")
	VarPayType=request.queryString("VarPayType")
	VarPayDesc=request.queryString("VarPayDesc")
	VarPayFrom=request.queryString("VarPayFrom")
	if(request.QueryString("VarMoney")<>"" and isnumeric(request.QueryString("VarMoney"))) then
		VarMoney=Csng(request.QueryString("VarMoney"))
		call conn.execute("update t_member set GoldMoney=GoldMoney+"&VarMoney&" where UserId='"&GetUserId&"'",ret)
		if(ret=0) then
			ReturnStr=6
		else
			ReturnStr=0
		end if
	else
		ReturnStr=1
	end if
	'消费记录
	if(VarPayType<>"" and VarPayFrom<>"") then
	dim ranNum,pay_billno
	randomize
	ranNum=int(900*rnd)+100
	pay_billno=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum
	set rs=server.CreateObject("adodb.recordset")
	rs.open "select * from t_payhis where 1=0",conn,3,3
	rs.addnew
	rs("PayType")=VarPayType
	rs("PayMoney")=VarMoney
	rs("PayFrom")=VarPayFrom
	rs("PayTo")=GetUserId
	rs("PayDate")=now()
	rs("PayNo")=pay_billno
	rs("PayTitle")=""
	rs("PayDesc")=VarPayDesc&"(金币："&VarMoney&")"
	rs.update
	rs.close
	set rs=nothing
	end if
end Function

''''''''''''''''''''
'扣除积分
''''''''''''''''''''
Function MinusScore
	dim VarScore,ret,rs,CurScore
	GetUserId=request.queryString("GetUserId")
	set rs=server.CreateObject("adodb.recordset")
	rs.open "select Score from t_member where UserId='"&GetUserId&"'",conn,3,3
	if not rs.eof then
		CurScore=rs(0)
	end if
	rs.close
	set rs=nothing
	if(request.QueryString("VarScore")<>"" and isnumeric(request.QueryString("VarScore"))) then
		VarScore=Cint(request.QueryString("VarScore"))
		if(VarScore>CurScore) then
			response.write("<balance>0</balance>"&chr(10))
		else
			call conn.execute("update t_member set Score=Score-"&VarScore&" where UserId='"&GetUserId&"'",ret)
			'返回积分
			set rs=server.CreateObject("adodb.recordset")
			rs.open "select Score from t_member where UserId='"&GetUserId&"'",conn,3,1
			if not rs.eof then
				response.write("<balance>"&rs(0)&"</balance>"&chr(10))
			end if
			rs.close
			set rs=nothing
		end if
	else
		ReturnStr=1
	end if
end Function
''''''''''''''''''''
'会员积分
''''''''''''''''''''
Function MemberScore
	dim VarScore,ret
	GetUserId=request.queryString("GetUserId")
	if(request.QueryString("VarScore")<>"" and isnumeric(request.QueryString("VarScore"))) then
		VarScore=Cint(request.QueryString("VarScore"))
		call conn.execute("update t_member set Score=Score+"&VarScore&" where UserId='"&GetUserId&"'",ret)
		if(ret=0) then
			ReturnStr=6
		else
			ReturnStr=0
			'返回积分
			set rs=server.CreateObject("adodb.recordset")
			rs.open "select Score from t_member where UserId='"&GetUserId&"'",conn,3,1
			if not rs.eof then
				response.write("<balance>"&rs(0)&"</balance>"&chr(10))
			end if
			rs.close
			set rs=nothing
		end if
	else
		ReturnStr=1
	end if
end Function

'''''''''''''''''''
'会员登录
'''''''''''''''''''
Function MemberLogin()
	dim m_pass,m_email,m_type,m_score,m_channel,md5pass_16,md5pass_32
	GetUserId=request.queryString("GetUserId")
	GetUserPass=request.queryString("GetUserPass")
	dim userip
	userip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
	if userip = "" then 
		userip = Request.ServerVariables("REMOTE_ADDR")
	end if
	if(GetUserId<>"" and GetUserPass<>"") then
		md5pass_16=md5(GetUserPass,16)
		md5pass_32=md5(GetUserPass,32)
		set rs=server.CreateObject("adodb.recordset")
		rs.open "select * from t_member where IsCheck=1 and UserId='"&GetUserId&"'",conn,3,3
		if not rs.eof then
			if(rs("UserPass")=md5pass_16 or rs("UserPass")=md5pass_32) then
				if(rs("IsLocked")=0) then
					ReturnStr=0
					rs("LastLoginIp")=userip
					rs("LastLoginDate")=now()
					rs("LoginNum")=rs("LoginNum")+1
					m_pass=rs("UserPass")
					m_email=rs("Email")
					m_type=rs("UserType")
					m_score=rs("Score")
					m_channel=rs("ChannelId")
					rs.update
				else
					ReturnStr=5
				end if
			else
				ReturnStr=4
			end if
		else
			ReturnStr=6
		end if
		rs.close
		set rs=nothing
		if(ReturnStr=0) then
			conn.execute("update t_member set Score=Score+"&Login_Score&" where UserId='"&GetUserId&"'")
		end if
		response.write("<password>"&m_pass&"</password>"&chr(10))
		response.write("<email>"&m_email&"</email>"&chr(10))		
		response.write("<usertype>"&m_type&"</usertype>"&chr(10))
		response.write("<userscore>"&m_score&"</userscore>"&chr(10))
		response.write("<channel>"&m_channel&"</channel>"&chr(10))		
	else
		ReturnStr=1
	end if
end Function

'''''''''''''''''''''
'会员基本信息
'''''''''''''''''''''
Function ShowMemberInfo
	GetUserId=request.queryString("GetUserId")
	if(GetUserId<>"") then
		set rs=server.CreateObject("adodb.recordset")
		rs.open "select * from t_member where UserId='"&GetUserId&"'",conn,3,1
		if not rs.eof then
			response.write("<member>"&chr(10))
			response.write("	<usertype>"&rs("UserType")&"</usertype>"&chr(10))
			response.write("	<email>"&rs("Email")&"</email>"&chr(10))			
			response.write("	<regip>"&rs("RegIp")&"</regip>"&chr(10))
			response.write("	<regdate>"&Cstr(rs("RegDate"))&"</regdate>"&chr(10))
			response.write("	<loginnum>"&Cstr(rs("LoginNum"))&"</loginnum>"&chr(10))
			response.write("	<lastloginip>"&rs("LastLoginIp")&"</lastloginip>"&chr(10))
			response.write("	<lastlogindate>"&Cstr(rs("LastLoginDate"))&"</lastlogindate>"&chr(10))
			response.write("	<islocked>"&Cstr(rs("IsLocked"))&"</islocked>"&chr(10))
			response.write("	<goldmoney>"&Cstr(rs("GoldMoney"))&"</goldmoney>"&chr(10))
			response.write("	<score>"&Cstr(rs("Score"))&"</score>"&chr(10))
			response.write("	<ischeck>"&Cstr(rs("IsCheck"))&"</ischeck>"&chr(10))
			response.write("	<userlevel>"&Cstr(rs("UserLevel"))&"</userlevel>"&chr(10))
			response.write("</member>"&chr(10))
		else
			ReturnStr=6
		end if
		rs.close
		set rs=nothing
	else
		ReturnStr=1
	end if
end Function
'''''''''''''''''''''
'个人会员资料
'''''''''''''''''''''
Function ShowPersonalInfo
	GetUserId=request.queryString("GetUserId")
	if(GetUserId<>"") then
		set rs=server.CreateObject("adodb.recordset")
		rs.open "select * from t_member_p where UserId='"&GetUserId&"'",conn,3,1
		if not rs.eof then
			response.write("<member>"&chr(10))
			response.write("	<email>"&rs("Email")&"</email>"&chr(10))
			response.write("	<username>"&rs("UserName")&"</username>"&chr(10))
			response.write("	<idcard>"&rs("IdCard")&"</idcard>"&chr(10))
			response.write("	<borndate>"&rs("BornDate")&"</borndate>"&chr(10))
			response.write("	<sex>"&rs("Sex")&"</sex>"&chr(10))
			response.write("	<age>"&rs("Age")&"</age>"&chr(10))
			response.write("	<province>"&rs("province")&"</province>"&chr(10))
			response.write("	<city>"&rs("City")&"</city>"&chr(10))
			response.write("	<education>"&rs("Education")&"</education>"&chr(10))
			response.write("	<profession>"&rs("Profession")&"</profession>"&chr(10))
			response.write("	<income>"&rs("inCome")&"</income>"&chr(10))
			response.write("	<tel>"&rs("Tel")&"</tel>"&chr(10))
			response.write("	<mobile>"&rs("mobile")&"</mobile>"&chr(10))
			response.write("	<qq>"&rs("QQ")&"</qq>"&chr(10))
			response.write("	<msn>"&rs("MSN")&"</msn>"&chr(10))
			response.write("	<homepage>"&rs("homepage")&"</homepage>"&chr(10))
			response.write("	<address>"&rs("Address")&"</address>"&chr(10))
			response.write("	<postcode>"&rs("PostCode")&"</postcode>"&chr(10))
			response.write("	<photo>"&rs("Photo")&"</photo>"&chr(10))
			response.write("	<demons>"&rs("Demons")&"</demons>"&chr(10))
			response.write("</member>"&chr(10))
		else
			ReturnStr=6
		end if
		rs.close
		set rs=nothing
	else
		ReturnStr=1
	end if
end Function
'''''''''''''''''''''
'企业会员资料
'''''''''''''''''''''
Function ShowEnterpriseInfo
	GetUserId=request.queryString("GetUserId")
	if(GetUserId<>"") then
		set rs=server.CreateObject("adodb.recordset")
		rs.open "select * from t_member_e where UserId='"&GetUserId&"'",conn,3,1
		if not rs.eof then
			response.write("<member>"&chr(10))
			response.write("	<email>"&rs("Email")&"</email>"&chr(10))
			response.write("	<username>"&rs("UserName")&"</username>"&chr(10))
			response.write("	<parentid>"&rs("ParentId")&"</parentid>"&chr(10))
			response.write("	<industryid>"&rs("IndustryId")&"</industryid>"&chr(10))
			response.write("	<comtype>"&rs("ComType")&"</comtype>"&chr(10))
			response.write("	<createdate>"&rs("CreateDate")&"</createdate>"&chr(10))
			response.write("	<contactman>"&rs("ContactMan")&"</contactman>"&chr(10))
			response.write("	<province>"&rs("Province")&"</province>"&chr(10))
			response.write("	<city>"&rs("City")&"</city>"&chr(10))
			response.write("	<businessscope>"&rs("BusinessScope")&"</businessscope>"&chr(10))
			response.write("	<tel>"&rs("Tel")&"</tel>"&chr(10))
			response.write("	<fax>"&rs("Fax")&"</fax>"&chr(10))
			response.write("	<mobile>"&rs("mobile")&"</mobile>"&chr(10))
			response.write("	<qq>"&rs("QQ")&"</qq>"&chr(10))
			response.write("	<homepage>"&rs("homepage")&"</homepage>"&chr(10))
			response.write("	<address>"&rs("Address")&"</address>"&chr(10))
			response.write("	<postcode>"&rs("PostCode")&"</postcode>"&chr(10))
			response.write("	<photo>"&rs("Photo")&"</photo>"&chr(10))
			response.write("	<demons><![CDATA["&rs("Demons")&"]]></demons>"&chr(10))
			response.write("</member>"&chr(10))
		else
			ReturnStr=6
		end if
		rs.close
		set rs=nothing
	else
		ReturnStr=1
	end if
end Function
response.write("</root>")
call connclose()
%>