当前位置: 代码迷 >> Java Web开发 >> 一个很简单的java有关问题
  详细解决方案

一个很简单的java有关问题

热度:27   发布时间:2016-04-17 11:13:54.0
一个很简单的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);
  相关解决方案