<%@ page language="java" contentType="text/html; charset=GBK"
    pageEncoding="GBK"%>
<%@ page import="java.io.*"%>
<%@ page import="java.net.*"%>
<%@ page import="java.util.Iterator"%>
<%@ page import="cn.sendsms.addressbook.*"%>
<%@ page import="cn.sendsms.cache.CachePool"%>
<%@ page import="cn.sendsms.jdsmsserver.JDSMSServer"%>
<%@ page import="cn.sendsms.util.SysConts"%>
<%@ page import="java.util.ArrayList" %>
<%@ page import="cn.sendsms.jdsmsserver.*"%>
<%
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragrma","no-cache");
response.setDateHeader("Expires",0);
String testUrl="http://"+request.getLocalAddr()+":"+request.getLocalPort()+"/test.jsp?gatewayId=modemX&text=MyText&originator=127001";
String gatewayId =request.getParameter("gatewayId");
String text=request.getParameter("text");
String originator=request.getParameter("originator");
String logText="[回调接口日志]端口["+gatewayId+"]接收到来自"+originator+"的短信:["+text+"]";
JDSMSServer.getInstance().getService().getLogger().logInfo(logText,null,null);

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>回调接口测试工具</title>
<link href="css.css" type="text/css" rel="stylesheet">
</head>
<body>
<div id="top"><span><img src="img/tu1.jpg"></span>回调接口测试工具</div>
<div id="center">
<div id="welcome" class="content" style="display:block;">
  <div >
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p><strong>回调接口测试工具使用简述</strong></p>   	
	<p>用浏览器或post工具访问 <a href="<%=testUrl %>"><%=testUrl %></a> 即可将回调接口产生的内容记录到日志中</p>
	<p>格式如下</p>  
	<pre><%=logText %></pre>
	<p>相应的，中间件的回调工具将以同样的方式将短信内容发送到您的程序，即可及时获取到收到的短信</p>
<%

 /*
 //String name=new String(text.getBytes("ISO-8859-1"),"UTF-8"); 
 boolean isModify=false,isAdd=false;
 String name="",phoneNumber="";
 //英文中的冒号
 if(text.indexOf("modify:")!=-1){
	 int iFind=text.indexOf("modify:");
	 text=text.substring(iFind);
		 //提取出手机号
     text=text.split(":")[1].trim();
     isModify=true;
 }else if(text.indexOf("modify：")!=-1){
	 int iFind=text.indexOf("modify：");
	 text=text.substring(iFind);
		 //提取出手机号
	 text=text.split("：")[1].trim();  
	 isModify=true;
 }else if(text.indexOf("add:")!=-1){
	 int iFind=text.indexOf("add:");
	 text=text.substring(iFind);
	 phoneNumber=text.split(":")[1].trim();
	 name=text.split(":")[2].trim();
	 isAdd=true;
 }else if(text.indexOf("add：")!=-1){
	 int iFind=text.indexOf("add：");
	 text=text.substring(iFind);
	 phoneNumber=text.split("：")[1].trim();
	 name=text.split("：")[2].trim();
	 isAdd=true;
 }
 if(isModify){
	 //修改公共通讯录，如果公共通讯录有此条记录修改
	 AddressList addrlist=null;
	 String strListFile = "",parentFullID = "/";
	 ArrayList<Address> aladdr = new ArrayList<Address>();
	 strListFile = JDSMSServer.getInstance().getAddressBookPath()+SysConts.FILE_SEPARATOR;
	 strListFile = strListFile + "address.xml";
	 File file = new File(strListFile);
	 if (file.exists())
			addrlist = (AddressList)CachePool.m_cmPublicAddrBook.getCacheObj(strListFile, file.lastModified());
		if (addrlist == null)
		{
			addrlist = new AddressList();
			addrlist.init(null, null, "public");
		}
	 originator=originator.substring(originator.indexOf("86")+2);
	 addrlist.findAddr(aladdr,"","","",originator); 
	 if(aladdr.size()!=0){
		 Address address=aladdr.get(0);
		 if(address.m_parentFolder!=null){
			 parentFullID = address.m_parentFolder.getFullId();
		 }
		 address=addrlist.findAddress_idid(address.m_id,parentFullID);
		 address.Telephone=text;
		 try{
			    addrlist.save();
			}catch(Exception e){
				JDSMSServer.getInstance().getService().getLogger().logWarn("修改通讯录   姓名: "+address.Name+" 手机号码为: "+address.Telephone+" 这条记录时出现异常", e,null);
			}
		 aladdr.clear();
	 }
	 File userDirectory=new File(JDSMSServer.getInstance().getAddressBookPath());
	 File[]userFiles=userDirectory.listFiles();
	 for(int i=0;i<userFiles.length;i++){
		 File userFile = userFiles[i];
		 if(userFile.isDirectory()){
				addrlist = new AddressList();
				parentFullID="/";
				addrlist.init(null,userFile.getName().trim(), "personal");
				 addrlist.findAddr(aladdr,"","","",originator); 
				 if(aladdr.size()!=0){
					 Address address=aladdr.get(0);
					 if(address.m_parentFolder!=null){
						 parentFullID = address.m_parentFolder.getFullId();
					 }
					 address=addrlist.findAddress_idid(address.m_id,parentFullID);
					 address.Telephone=text;
					 try{
						    addrlist.save();
						}catch(Exception e){
							JDSMSServer.getInstance().getService().getLogger().logWarn("修改通讯录   姓名: "+address.Name+" 手机号码为: "+address.Telephone+" 这条记录时出现异常", e,null);
						}
					 aladdr.clear();
				 }
		 }
	 }
 }else if(isAdd){
	 AddressList addrlist=null;
	 String strListFile = "";
	 strListFile = JDSMSServer.getInstance().getAddressBookPath()+SysConts.FILE_SEPARATOR;
	 strListFile = strListFile + "address.xml";
	 File file = new File(strListFile);
	 if (file.exists())
			addrlist = (AddressList)CachePool.m_cmPublicAddrBook.getCacheObj(strListFile, file.lastModified());
		if (addrlist == null)
		{
			addrlist = new AddressList();
			addrlist.init(null, null, "public");
		}
		ArrayList<Address> aladdr = new ArrayList<Address>();
	    addrlist.findAddr(aladdr,"","","",phoneNumber); 
	    if(aladdr.size()==0){
	    	Address addr = new Address();
			addr.Name = name;
	    	addr.m_id = AddressList.createId();
	    	addr.Telephone=phoneNumber;
	    	addr.m_foldertype = "public";
			addrlist.addAddress_id(addr, "/");
			try{
		    addrlist.save();
			}catch(Exception e){
				JDSMSServer.getInstance().getService().getLogger().logWarn("向通讯录添加  姓名: "+name+" 手机号码为: "+phoneNumber+" 这条记录时出现异常", e,null);
			}
	    } 
 }
 if(text.indexOf("modify:")!=-1||text.indexOf("add:")!=-1||text.indexOf){
	 int iFind=text.indexOf("modify:");
	 if(iFind!=-1){
		 text=text.substring(iFind);
		 //提取出手机号
		 text=text.split(":")[1].trim();
	 }else{
		 AddressList addrlist=null;
		
		 String strListFile = "";
		 strListFile = JDSMSServer.getInstance().getAddressBookPath()+SysConts.FILE_SEPARATOR;
		 strListFile = strListFile + "address.xml";
		 File file = new File(strListFile);
		 if (file.exists())
				addrlist = (AddressList)CachePool.m_cmPublicAddrBook.getCacheObj(strListFile, file.lastModified());
			if (addrlist == null)
			{
				addrlist = new AddressList();
				addrlist.init(null, null, "public");
			}
			ArrayList<Address> aladdr = null;
		    addrlist.findAddr(aladdr,"","","",phoneNumber); 
		    if(aladdr.size()==0){
		    	Address addr = new Address();
				addr.Name = name;
		    	addr.m_id = AddressList.createId();
		    	addr.Telephone=phoneNumber;
		    	addr.m_foldertype = "public";
				addrlist.addAddress_id(addr, "/");
				try{
			    addrlist.save();
				}catch(Exception e){
					JDSMSServer.getInstance().getService().getLogger().logWarn("向通讯录添加  姓名: "+name+" 手机号码为: "+phoneNumber+" 这条记录时出现异常", e,null);
				}
		    }

 }
 } */
 %>   
</div>
</div>
</div>
</body>
</html>