import lotus.domino.*;
import java.net.*;
import java.io.*;
public class JavaAgent extends AgentBase {
Database db = null;
Session session = null;
public void CreadSendSmsLog(String SendUser, String SendTo ,String Tel ,String Body){
//创建发送手机短信日志
Document LogDoc = null;
DateTime dt = null;
try{
dt = session.createDateTime("Today");
//dt.setNow();
LogDoc = db.createDocument();
LogDoc.replaceItemValue("form","smslog");
LogDoc.replaceItemValue("Subject",Body);
LogDoc.replaceItemValue("SendUser",SendUser);
LogDoc.replaceItemValue("SendTo",SendTo);
LogDoc.replaceItemValue("Tel",Tel);
LogDoc.replaceItemValue("SendDate",dt);
LogDoc.save(true,false);
}catch(NotesException ne){
ne.printStackTrace();
}finally{
try{
if(null!=LogDoc)LogDoc.recycle();
if(null!=dt)dt.recycle();
}catch(NotesException e){
e.printStackTrace();
}
}
}
public void NotesMain() {
PrintWriter out = null;
iSMSClient2000 objSMS = null;
View viewsmslist = null;
ViewEntryCollection vec = null;
ViewEntry entry = null;
Document viewdoc = null;
Document logdoc = null;
AgentContext ac = null;
try {
session = getSession();
ac = session.getAgentContext();
// Document doc = ac.getDocumentContext();
objSMS = new iSMSClient2000();
db = ac.getCurrentDatabase();
viewsmslist = db.getView("viewsmslist");
vec = viewsmslist.getAllEntries();
if (objSMS.OpenSMS("127.0.0.1", 8090)) {
for (int i = 1; i<=vec.getCount();i++){
try{
System.out.println(i);
entry = vec.getNthEntry(i);
viewdoc = entry.getDocument();
String Body=viewdoc.getItemValueString("Body");
String SendUser=viewdoc.getItemValueString("SendUser");
String SendTo=viewdoc.getItemValueString("UserName");
String Tel=viewdoc.getItemValueString("Tel");
if (objSMS.SendSMS("1",Tel,Body)) {
//out.println("发送成功!");
viewdoc.replaceItemValue("IsSent","1");
viewdoc.save(true,false);
CreadSendSmsLog(SendTo,SendUser,Tel,Body);
} else {
//out.println("发送失败!");
viewdoc.replaceItemValue("IsSent","1");
viewdoc.save(true,false);
CreadSendSmsLog(SendTo,SendUser,Tel,Body);
}
}catch(NotesException ne){
ne.printStackTrace();
}finally{
if(null!=viewdoc){viewdoc.recycle();}
if(null!=entry){entry.recycle();}
}
}
} else {
out.println("打开服务器失败!");
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try{
if(null!=vec)vec.recycle();
if(null!=viewsmslist)viewsmslist.recycle();
if(null!=db)db.recycle();
if(null!=ac)ac.recycle();
if(null!=session)session.recycle();
//out.close();
}catch(NotesException nne){
nne.printStackTrace();
}
objSMS.CloseSMS();
System.gc();
}
}
}
如何在Lotus Domino中实现发送短信
最新推荐文章于 2016-03-07 17:25:01 发布