<!--#include file="base.asp"-->
<%
''' EYCMS 微信 消息管理
''' ==================================================================

	function get_msg_type(byval t0)
		dim t1
		select case t0
			case "text":t1="文本"
			case "image":t1="图片"
			case "voice":t1="语音"
			case "video":t1="视频"
			case "location":t1="地理位置"
			case "link":t1="链接"
			case "event":t1="事件"
		end select
		get_msg_type=t1
	end function
	
	sub replydb()
		dim id:id=eycms.getint(eycms.fget("id",0),0)
		dim t0:t0=eycms.enhtml(eycms.fpost("t0",0))
		if eycms.strlen(t0)=0 then
			eycms.echo "回复内容不能为空"
			exit sub
		end if
		dim data:data=eycms.db.dbload(1,"FromUserName,isreply,CreateTime","wx_msg","id="&id&"","")
		if ubound(data)<0 then
			eycms.echo "参数错误"
			exit sub
		end if
		dim ct:ct=eycms.FromUnixTime(data(2,0),"+8")
		if datediff("d",ct,now())>=2 then
			eycms.echo "超过48小时不能再回复"
			exit sub
		end if
		dim funame:funame=data(0,0)
		dim wx,msgdata,json
		set wx=new eycms_weixin
			msgdata=wx.msg_reply(funame,t0)
			set json=toobject(msgdata)
			if json.errcode<>"0" then
				eycms.echo "错误编号："&json.errcode&"，错误代码："&json.errmsg&""
				exit sub
			else
				eycms.db.dbupdate "wx_msg","id="&id&"",array(array("reply",t0,255,1),array("isreply",1,10,0))	
				eycms.echo "1"
			end if
			set json=nothing
		set wx=nothing
	end sub
	
	sub deldb()
		dim id:id=eycms.getint(eycms.fget("id",0),0)
		eycms.db.dbdel "wx_msg","id="&id&""
		eycms.echo "1"
	end sub
	
	sub delsome()
		dim id:id=eycms.enhtml(eycms.fget("id",0))
		dim idarr:idarr=split(id,",")
		if ubound(idarr)<0 then
			eycms.echo "0&#33267;&#23569;&#36873;&#25321;&#19968;&#26465;&#20449;&#24687;"
		else
			dim i
			for i=0 to ubound(idarr)
				if not isnumeric(idarr(i)) then
					eycms.echo "0&#21442;&#25968;&#65306;"&idarr(i)&"&#19981;&#27491;&#30830;&#65292;&#35831;&#30830;&#35748;&#21518;&#20877;&#25805;&#20316;"
					exit sub
				else
					eycms.db.dbdel "wx_msg","id="&idarr(i)&""
				end if
			next
			eycms.echo "1"
		end if
	end sub

	islogin
	checkpagelever 72
	dim act:act=lcase(eycms.fget("act",0))
	dim nat:nat=eycms.getint(eycms.fget("nat",0),1)
	dim natkey:natkey="按性质↓"
	dim sqlwhere:sqlwhere="1=1"
	select case act
		case "reply"
			dim id:id=eycms.getint(eycms.fget("id",0),0)
			dim data:data=eycms.db.dbload(1,"isreply","wx_msg","id="&id&"","")
			if ubound(data)>=0 then
				load theme_msg_reply
			end if
		case "view"
			id=eycms.getint(eycms.fget("id",0),0)
			data=eycms.db.dbload(1,"reply","wx_msg","id="&id&"","")
			if ubound(data)>=0 then
				eycms.echo data(0,0)
			end if
		case "replydb":replydb
		case "del":deldb
		case "delsome":delsome
		case else
			select case nat
				case "1":sqlwhere=sqlwhere&" and MsgType='text'":natkey="文本消息"
				case "2":sqlwhere=sqlwhere&" and MsgType='image'":natkey="图片消息"
				case "3":sqlwhere=sqlwhere&" and MsgType='voice'":natkey="语音消息"
				case "4":sqlwhere=sqlwhere&" and MsgType='video'":natkey="视频消息"
				case "5":sqlwhere=sqlwhere&" and MsgType='location'":natkey="地理位置"
				case "5":sqlwhere=sqlwhere&" and MsgType='link'":natkey="链接消息"
				case "6":sqlwhere=sqlwhere&" and MsgType='event'":natkey="事件消息"
				case else:natkey="全部消息"
			end select
			load theme_msg
	end select
	eycms.db.dbclose
%>