<!--#include virtual="/inc/conn.asp"-->
<!--#include virtual="/inc/sitecon.asp"-->
<!--#include virtual="/inc/chkuser.asp"-->
<%
call lognameadmin() 
Set fso=Server.CreateObject("Scripting.FileSystemObject")
%>

<%if SafeRequest("a")="new" then%>
<title>有新的消息！请及时回复！</title>
<%else%>
<title>微信公众号实时对话</title> 
<%end if%>


<%
function getHTTPmsg(url,cset) 
dim Http 
set Http=server.createobject("MSXML2.XMLHTTP") 
Http.open "GET",url,false 
Http.send() 
if Http.readystate<>4 then exit function 
getHTTPmsg=bytesToBSTR(Http.responseBody,cset) 
set http=nothing 
if err.number<>0 then err.Clear  
end function 


Function ToUnixTime(strTime, intTimeZone)
If IsEmpty(strTime) or Not IsDate(strTime) Then strTime = Now
If IsEmpty(intTimeZone) or Not isNumeric(intTimeZone) Then intTimeZone = 0
ToUnixTime = DateAdd("h",-intTimeZone,strTime)
ToUnixTime = DateDiff("s","1970-1-1 0:0:0", ToUnixTime)
End Function
	
	
if SafeRequest("act")="alldel" then
rs.open "select * from ayweixin",conn,1,3
	if not(rs.bof and rs.eof) then
		do while not rs.eof
		rs.delete
		rs.movenext
		loop
	end if
rs.close
		set linkw=fso.createtextfile(server.mappath("\updata\isweixin.txt"),true)
		linkw.writeline "0"	
		linkw.close
		response.Redirect "index.asp"
end if


if SafeRequest("act")="yidu" then
id=SafeRequest("id")
laiyuan=SafeRequest("laiyuan")
	rs.open "select * from ayweixin where aywxid="&id&"",conn,1,3
	if not(rs.bof and rs.eof) then
	rs("aywxishf")=1
	rs.update
	end if
	rs.close
	
		set linkw=fso.createtextfile(server.mappath("\updata\isweixin.txt"),true)
		linkw.writeline "0"	
		linkw.close
		
	if trim(laiyuan)<>"" then
	response.Redirect "index.asp?aywxfrom="&laiyuan&""
	else
	response.Redirect "index.asp"
	end if
	
end if

if SafeRequest("act")="hf" then

if SafeRequest("aywxfrom")="" or trim(SafeRequestform("hfcon"))="" or SafeRequest("aywxid")="" then call PopErr("内容空")

'获取是否已关注公众号
'if request.Cookies("access_token")="" then
'tokenstr=getHTTPopenid("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="&appid&"&secret="&secret&"","gb2312")
'Set json = toObject(tokenstr)
'response.Cookies("access_token")=json.access_token
'Response.Cookies("access_token").expires=DateAdd("h",2,now())
'Set json = Nothing 
'end if
 
aywxfrom=trim(SafeRequest("aywxfrom")) '微信用户
aywxto=trim(SafeRequestform("aywxto")) '公众号
aywxmsgid=trim(SafeRequestform("aywxmsgid")) '微信消息ID 正数
aywxid=SafeRequest("aywxid")           '平台ID编号
hfcon=SafeRequestform("hfcon")         '内容
laiyuan=SafeRequest("laiyuan")         '来源用户

msgstr=getHTTPmsg(""&weburl&"weixin/hf.php?aywxfrom="&trim(SafeRequest("aywxfrom"))&"&hfcon="&SafeRequestform("hfcon")&"&access_token="&getaccesstoken,"gb2312")


Set json = toObject(msgstr)

	if trim(json.errmsg)="ok" then 
	
		conn.Execute("Insert Into ayweixin(aywxto,aywxfrom,aywxdate,aywxtype,aywxcon,aywxmsgid,aywxsid) values('"&trim(aywxfrom)&"','"&trim(aywxto)&"','"&ToUnixTime(now,+8)&"','text','"&trim(hfcon)&"','"&trim(aywxmsgid)&"','"&clng(aywxid)&"')")
		
		conn.execute "update ayweixin set aywxishf=1 where aywxid='"&aywxid&"'"
		
		set linkw=fso.createtextfile(server.mappath("\updata\isweixin.txt"),true)
		linkw.writeline "0"	
		linkw.close
		
		if trim(laiyuan)<>"" then
		call PopErr2("回复成功","index.asp?aywxfrom="&laiyuan&"")
		else
		call PopErr2("回复成功","index.asp")
		end if
		
	else
	call PopErr("失败-"&json.errmsg&"")
	end if
Set json = Nothing 


end if


if SafeRequest("act")="del"then
if SafeRequest("wxid")="" then call PopErr("内容空")
wxid=SafeRequest("wxid")
laiyuan=SafeRequest("laiyuan")         '来源用户

		sql="select * from ayweixin where aywxid="&wxid&"" 
		rs.open sql,conn,1,3
		if not(rs.bof and rs.eof) then
		rs.delete
		end if
		rs.close
		
		if trim(laiyuan)<>"" then
		response.Redirect "index.asp?aywxfrom="&laiyuan&""
		else
		response.Redirect "index.asp"
		end if

end if



if SafeRequest("act")="wxmsnto"then
aywxfrom=trim(SafeRequest("aywxfrom"))

	rs.open "select * from ayweixin where aywxfrom='"&aywxfrom&"'",conn,1,3
	if rs.bof and rs.eof then
	rs.addnew
	rs("aywxfrom")=aywxfrom
	rs("aywxtype")="text"
	rs("aywxcon")="[人工主动请求]"
	'rs("aywxto")=kaifa
	'rs("aywxmsgid")=ToUnixTime(now,+8)
	rs.update
	end if
	rs.close

end if
%>

<SCRIPT type="text/javascript" src="/Template/Template4/old1/jquery-1.9.1.min.js" ></SCRIPT>
<script language="javascript">window.onload = function(){queryOrderState()}</script>
<script type="text/javascript">
var xmlhttp;try{xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");}catch (e){try{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}catch (e){try{xmlhttp=new XMLHttpRequest();}catch (e){}}}

function trim(str){return str.replace(/(^\s*)|(\s*$)/g, "");}


	$(document).ready(function(){setInterval(queryOrderState, 5000);});
						
	function queryOrderState()
	{ 
	xmlhttp.open("get","/updata/isweixin.txt");
		xmlhttp.onreadystatechange=function()
		{
			if(trim(xmlhttp.responseText)=="1")
			{	
			<%
			set linkw=fso.createtextfile(server.mappath("\updata\isweixin.txt"),true)
			linkw.writeline "0"	
			linkw.close
			%>
			window.location.href="/weixin/index.asp?a=new";
			}
		}
	xmlhttp.send(null); 
	}
</script>

<STYLE>
BODY {FONT-SIZE: 12px; COLOR: #666; WORD-BREAK: break-all; FONT-FAMILY: "宋体"; BACKGROUND-COLOR: #fff}
HTML {PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px}
BODY {PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px}
DIV {PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px}
UL {PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px}
LI {PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px;LIST-STYLE-TYPE: none}
header {PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px}
footer {PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px}
A {COLOR: #333; TEXT-DECORATION: none}
A:visited {COLOR: #333; TEXT-DECORATION: none}
A:hover {COLOR: #008000! important; TEXT-DECORATION: none}
.second_login_toolbar {TEXT-ALIGN: right}
.second_login_toolbar .c9 {COLOR: #999}
.second_login_toolbar .c11 {COLOR: #fff}
.second_login_toolbar .goto_old {DISPLAY: inline-block; PADDING-LEFT: 23px; BACKGROUND: url(/images/goto_old_bg.png) no-repeat; WIDTH: 54px; COLOR: #666; PADDING-TOP: 1px; HEIGHT: 17px; TEXT-ALIGN: left}
header {OVERFLOW: hidden; WIDTH: 100%; HEIGHT: 74px}
header .logo {MARGIN-TOP: 15px; WIDTH: 297px; height:97px;}
header .logotxt {PADDING-TOP: 32px;WIDTH: 285px}
.fleft {FLOAT: left}
.fright {FLOAT: right}
#main1200 {margin:10px 10px 10px 10px;}
.apply_style {POSITION: absolute}
.right_title A {LINE-HEIGHT: 27px; WIDTH: 126px; DISPLAY: inline-block; BACKGROUND: url(/images/bg22.gif) no-repeat; HEIGHT: 27px}
.right_title A.current {BACKGROUND: url(/images/main_right_title_bg.gif) no-repeat; COLOR: #fff; FONT-WEIGHT: bold}
.table_style_1 TD {HEIGHT: 38px}
.table_style_home_info TD {PADDING-BOTTOM: 0px; PADDING-LEFT: 10px; PADDING-RIGHT: 0px; HEIGHT: 30px; PADDING-TOP: 0px}
#main_left {WIDTH: 360px; FLOAT: left}
UL.left_menu {HEIGHT: 338px;BORDER-BOTTOM: #dadada 1px solid; BORDER-LEFT: #dadada 1px solid; PADDING-BOTTOM: 10px; PADDING-LEFT: 10px; PADDING-RIGHT: 10px; BORDER-TOP: #dadada 1px solid; BORDER-RIGHT: #dadada 1px solid; PADDING-TOP: 10px}
UL.left_menu LI {BORDER-BOTTOM: #dadada 1px solid; LINE-HEIGHT: 28px; HEIGHT: 28px}
UL.left_menu LI A {LINE-HEIGHT: 28px; PADDING-LEFT: 10px;HEIGHT: 28px; COLOR: #000; TEXT-DECORATION: none}
UL.left_menu LI A:hover {TEXT-DECORATION: underline} 
#main_right {PADDING-LEFT: 365px}
#main_right_content {text-align:left;}
.right_titleadmin {BORDER-RIGHT: #dadada 1px solid; BORDER-TOP: #dadada 1px solid; BORDER-BOTTOM: #dadada 1px solid; BORDER-LEFT: #dadada 1px solid; WIDTH: 99%; height:27px;background:url(/images/reAllbgs.png) repeat-x; text-align:left;line-height:27px;font-size:12px; color:#666; FONT-WEIGHT: bold}
#main {width:995px;margin:auto;}
#main1200 {margin:10px 10px 10px 10px;}
.footer_shadow{text-align:center;color:#666;padding:10px 0;border-top:1px solid #666;margin-top:10px}
.auto {MARGIN: 0px auto}
.lh20 {LINE-HEIGHT: 20px}
.c9 {COLOR: #999}
.mt23 {MARGIN-TOP: 23px}
.left_title {BORDER-RIGHT: #dadada 1px solid; BORDER-TOP: #dadada 1px solid; BORDER-LEFT: #dadada 1px solid; WIDTH: 358; height:27px;background:url(/images/reAllbgs.png) repeat-x; text-align:center;line-height:27px;font-size:12px; color:#666; FONT-WEIGHT: bold}
</STYLE>

<DIV class=clear></DIV>


<DIV id=main1200> 


<DIV id=main_left style="text-align:center">
<DIV class=left_title>通话记录</DIV>
<UL class=left_menu > 
<%
set rs2=server.CreateObject("adodb.recordset")
set rs3=server.CreateObject("adodb.recordset")
rs.open "select distinct aywxfrom from ayweixin where aywxsid=0",conn,1,1
if not(rs.eof) then
do while not rs.eof
%>
<LI><%
rs3.open "select aytrueuser,wxopenid from ayname where wxopenid='"&trim(rs("aywxfrom"))&"'",conn,1,1
if not(rs3.eof) then
response.Write "("&trim(rs3("aytrueuser"))&")"
end if
rs3.close
%><A style="COLOR: #FF0000" href="?aywxfrom=<%=trim(rs("aywxfrom"))%>"><%=trim(rs("aywxfrom"))%></A>
<%isnew="no"
	rs2.open "select * from ayweixin where aywxfrom='"&trim(rs("aywxfrom"))&"'",conn,1,1
	if not(rs2.eof) then 
		do while not rs2.eof
		if cint(rs2("aywxishf"))=0 then isnew="yes"
		rs2.movenext 
		loop
		response.Write "("&rs2.RecordCount&")"
		if isnew="yes" then response.Write "<span style=color:#FF00CC>●</span>"
	end if
	rs2.close
%></LI>
<%rs.movenext 
loop
end if
rs.close
%>

</UL>
</DIV>
  






<DIV id=main_right>
<DIV id=main_right_content>

<DIV class=right_titleadmin>&nbsp;&nbsp;<a href="/weixin/index.asp">微信公众号实时对话</a> (<a href="?act=alldel">全部删除</a> ) <a href="https://mp.weixin.qq.com" target="_blank">[进入微信公众平台]</a></DIV>
<DIV class=main>

  <TABLE width="850" height="500" border="0" class=table_style_2 >
  <TBODY>

<%
if SafeRequest("aywxfrom")<>"" then
rs.open "select * from ayweixin where aywxsid=0 and aywxfrom='"&trim(SafeRequest("aywxfrom"))&"' order by aywxid desc",conn,1,1
else
rs.open "select * from ayweixin where aywxsid=0 order by aywxid desc",conn,1,1
end if
if not(rs.eof) then
do while not rs.eof%>

  <TR>
    <TD width="728" valign="top"  style="BORDER-BOTTOM: #6699FF 1px dashed; font-size:13px; line-height:20px;"><br><br>
<form action="?act=hf&aywxto=<%=trim(rs("aywxto"))%>&aywxfrom=<%=trim(rs("aywxfrom"))%>&aywxid=<%=rs("aywxid")%>&aywxmsgid=<%=trim(rs("aywxmsgid"))%>&laiyuan=<%=trim(SafeRequest("aywxfrom"))%>" method="post" name="form" id="form">
微信用户：<span style="color:#09C"><%
rs3.open "select aytrueuser,wxopenid from ayname where wxopenid='"&trim(rs("aywxfrom"))&"'",conn,1,1
if not(rs3.eof) then
response.Write "("&trim(rs3("aytrueuser"))&")"
end if
rs3.close
%>
<a style="color:#F93" href=?aywxfrom=<%=trim(rs("aywxfrom"))%>><%=trim(rs("aywxfrom"))%></a> </span> 消息类型：<%=trim(rs("aywxtype"))%> 消息ID：<%=trim(rs("aywxmsgid"))%> <a href="?act=del&wxid=<%=rs("aywxid")%>&laiyuan=<%=SafeRequest("aywxfrom")%>">[删除]</a> 
<%if rs("aywxishf")=0 then%>
<a href="?act=yidu&id=<%=rs("aywxid")%>&laiyuan=<%=SafeRequest("aywxfrom")%>">[标记已读]</a> 
<%end if%>
<br>
消息内容：[<%=rs("aywxtime")%>]
<%if trim(rs("aywxtype"))="text" then%>
<%=trim(rs("aywxcon"))%>
<%else
imgurl=replace(trim(rs("PicUrl")),"http://mmbiz.qpic.cn/mmbiz/","https://mmbiz.qpic.cn/mmbiz/")
imgurl=imgurl&"?wx_fmt=png"
%>
<a href="<%=imgurl%>" target="_blank"><img src="<%=imgurl%>" width="40px" height="40px"></a>
<%end if%>
<br>
	<%
    rs2.open "select * from ayweixin where aywxsid="&rs("aywxid")&" order by aywxid asc",conn,1,1
    if not(rs2.eof) then
    do while not rs2.eof%>
	<span style="color:#F6C">回复内容：[<%=rs2("aywxtime")%>] <%=trim(rs2("aywxcon"))%></span><br>
	<%rs2.movenext 
    loop
    end if
    rs2.close
    %>
回复内容：<input name="hfcon" type="text" id="hfcon" size="50" /><input type="submit" name="Submit" value=" 回 复 该 用 户 ">
</form>
<br>
<br>
</TD>
    </TR>
<%rs.movenext 
loop
end if
rs.close
%>	
  </TBODY></TABLE>




</DIV></DIV>
<DIV class=clear></DIV></DIV>
</DIV>





