首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

一个很简单的java有关问题

2012-01-22 
一个很简单的java问题小弟跪求高手解答问题公司要搞个可以收短信的短信猫程序 java的 小弟是弄php的不会ja

一个很简单的java问题
小弟跪求高手解答问题 
公司要搞个可以收短信的短信猫程序 java的 小弟是弄php的不会java 现在二次开发包是有了 
里面有提示这样做
=========================================================
具体的操作步骤如下:
1、把smslib-3.3.3.jar、comm.jar与log4j-1.2.13.jar,ofbiz-entity.jar,放入到工程的lib中;
2、把javax.comm.properties放到%JAVA_HOME%/jre/lib下;
3、把win32com.dll放到%JAVA_HOME%/jre/bin下;还要放在%JAVA_HOME%/bin下;
4 把comm.jar放到%JAVA_HOME%/jre/lib/ext下
我添加成这样...

在原来的工程里的src文件夹里加入类 SendMessages.java

这个类是给的例子
--------------------------java---------------------------------
package com;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.ofbiz.entity.GenericDelegator;
import org.smslib.GatewayException;
import org.smslib.IInboundMessageNotification;
import org.smslib.IOutboundMessageNotification;
import org.smslib.InboundMessage;
import org.smslib.OutboundMessage;
import org.smslib.SMSLibException;
import org.smslib.Service;
import org.smslib.TimeoutException;
import org.smslib.Message.MessageEncodings;
import org.smslib.Message.MessageTypes;
import org.smslib.modem.SerialModemGateway;

public class SendMessageWithPortsSMSLib {
//自身类
static SendMessageWithPortsSMSLib smwps=null;
//读取全部消息
public static final org.smslib.InboundMessage.MessageClasses ALL_MESSAGE=org.smslib.InboundMessage.MessageClasses.ALL;
//读取已读消息
public static final org.smslib.InboundMessage.MessageClasses READ_MESSAGE=org.smslib.InboundMessage.MessageClasses.READ;
//读取未读消息
public static final org.smslib.InboundMessage.MessageClasses UNREAD_MESSAGE =org.smslib.InboundMessage.MessageClasses.UNREAD;
//消息服务
Service srv=null;
//发送消息回调实现类
OutboundNotification outboundNotification = new OutboundNotification();
//读取消息回调实现类
InboundNotification inboundNotification=new InboundNotification();
//数据库柄
private GenericDelegator delegator=null;

//设备名称
private static String gateName="SMS";

private SendMessageWithPortsSMSLib(){}

//构造类的实例,只产生一个对象实例

public static SendMessageWithPortsSMSLib newInstanceSend(String com) throws TimeoutException, GatewayException, SMSLibException, IOException, InterruptedException{
if(smwps==null)
smwps=new SendMessageWithPortsSMSLib();
if (smwps.srv==null)
smwps.open(com,gateName);
return smwps;
}
public static SendMessageWithPortsSMSLib newInstanceSend(String com,GenericDelegator delegator) throws TimeoutException, GatewayException, SMSLibException, IOException, InterruptedException{
if(smwps==null)
smwps=new SendMessageWithPortsSMSLib();
if (smwps.srv==null)
smwps.open(com,gateName);
smwps.delegator=delegator;
return smwps;
}
public static SendMessageWithPortsSMSLib newInstanceSend(String com,GenericDelegator delegator,String gateName) throws TimeoutException, GatewayException, SMSLibException, IOException, InterruptedException{
if(smwps==null)
smwps=new SendMessageWithPortsSMSLib();
if (smwps.srv==null)
smwps.open(com,gateName);
smwps.delegator=delegator;
SendMessageWithPortsSMSLib.gateName=gateName;
return smwps;
}

//打开端口,开启服务
private void open(String com,String gateName) throws TimeoutException, GatewayException, SMSLibException, IOException, InterruptedException {
srv = new Service();  
//comPort 串口名,比如COM1或者/dev/ttyS1
//baudRate 端口速度,WAVECOM是9600
//manufacturer,model 制造商和型号随便填
SerialModemGateway gateway= new SerialModemGateway(gateName,com,9600,"",srv.getLogger().toString());
gateway.setInbound(true);
gateway.setOutbound(true);


//gateway.setSimPin("0000");
// gateway.setOutboundNotification(outboundNotification);
 
//gateway.setInboundNotification(inboundNotification);
//srv.setOutboundNotification(outboundNotification);
//srv.setInboundNotification(inboundNotification);
// srv.S.SERIAL_POLLING_INTERVAL=10;
//srv.S.SERIAL_POLLING=true;
srv.addGateway(gateway); 
srv.startService();
}
//读取信息
public List <org.smslib.InboundMessage> readSms(org.smslib.InboundMessage.MessageClasses messageType) throws TimeoutException, GatewayException, IOException, InterruptedException{
List <InboundMessage> smss=new LinkedList<InboundMessage>();
//InboundMessage inm=null;
srv.readMessages(smss,messageType,gateName);
//System.out.println(smss);
//System.out.println(msg);
return smss;

//发送单条消息
public boolean sendSms(String mobile,String content) {
OutboundMessage msg = new OutboundMessage(mobile, content);
msg.setEncoding(MessageEncodings.ENCUCS2);
//msg.setStatusReport(true);
try {

srv.sendMessage(msg);
// System.out.println(msg);
} catch (Exception e) {
// System.out.println("--"+e);
return false;
}
return true;
}
//群发消息
public List<Map<String, String>> sendSms(List<Map<String,String>> messages) {
List <Map<String, String>> failList=new ArrayList <Map<String, String>>();
Iterator<Map<String, String>> itr= messages.iterator();
while(itr.hasNext()){
Map<String, String> message=(Map<String, String>)itr.next();
String mobile=(String)message.get("mobile");
String content=(String)message.get("content");
if(!sendSms(mobile,content))
failList.add(message);
}
return failList;
}
//关闭服务
public void close() {
try {
srv.stopService();
}catch (Exception ex) {
System.out.println("**"+ex);
}
}
 
public class OutboundNotification implements IOutboundMessageNotification{
public void process(String gatewayId, OutboundMessage msg){
System.out.println("Outbound handler called from Gateway: " + gatewayId);
System.out.println(msg);
}
}
public class InboundNotification implements IInboundMessageNotification{

public void process(String arg0, MessageTypes arg1, InboundMessage arg2) {
// TODO Auto-generated method stub
//System.out.println(arg0);
//System.out.println(arg1);
//System.out.println(arg2);

}


public static void main(String[] args) throws TimeoutException, GatewayException, IOException, InterruptedException {  
String mob="13636316288";
String content="一只小熊去山里创业,农夫给了他一把镰刀,木匠给了他一把锤子, 小熊来到山里遇到老虎,吓得把镰刀、锤子举在头顶, 老虎说:没看出来,就你这熊样还是个党员来!";
SendMessageWithPortsSMSLib sms=new SendMessageWithPortsSMSLib();//newInstance(); 
try {
sms.open("COM6","SMS");
} catch (TimeoutException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (GatewayException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SMSLibException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("1、发送短消息");
System.out.println("quit、退出");
String str="";
System.out.println("1、发送短消息");



System.out.println("quit、退出");
while(true){
System.out.print ("请选择: "); 
InputStreamReader stdin = new InputStreamReader(System.in);//键盘输入  
BufferedReader bufin = new BufferedReader(stdin);
try {
str = bufin.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(str.equals("quit")){
sms.close();
break;
}else if(str.equals("1"))
System.out.println(sms.sendSms(mob,content));
else{
System.out.println("短消息!");
sms.readSms(SendMessageWithPortsSMSLib.ALL_MESSAGE);
}
}
//sms.readSms();
//sms.sendSms(mob, content);
//sms.close();
}

}
csdn的分剩的不多 全给了

[解决办法]
//这是放到你的项目lib中
1、把smslib-3.3.3.jar、comm.jar与log4j-1.2.13.jar,ofbiz-entity.jar,放入到工程的lib中;
//%JAVA_HOME%指的是你的JAVA安装路径如c:\java
2、把javax.comm.properties放到%JAVA_HOME%/jre/lib下;
//同2
3、把win32com.dll放到%JAVA_HOME%/jre/bin下;还要放在%JAVA_HOME%/bin下;
//同2
4 把comm.jar放到%JAVA_HOME%/jre/lib/ext下
[解决办法]
如果是JAVA项目 那你就手动弄个lib 把他放到 里边 然后用 Myeclipse的 Build Path 把这个包导入到 项目环境中
如果是WEB项目 在webroot/WEB-INF/下边有个lib

热点排行