小弟买了一个短信猫(Wavecom), 按网上使用smslib包发送手机短信,按要求将
把smslib-3.3.0b2.jar和comm.jar,放入工程lib中,javax.comm.properties放到%JAVA_HOME%/jre/lib下,
win32com.dll放到%JAVA_HOME%/jre/bin下, 代码如下:
public void sendSMS(String mobilePhones, String content) throws GatewayException {
//服务
Service srv;
//输出消息对象
OutboundMessage msg;
//通知类对象
//OutboundNotification outboundNotification = new OutboundNotification();
srv = new Service();
//网关
SerialModemGateway gateway = new SerialModemGateway("modem.com7", "COM7", 9600, "wavecom", "");
//收件箱
gateway.setInbound(true);
//发件箱
gateway.setOutbound(true);
//ping码
gateway.setSimPin("0000");
srv.addGateway(gateway);
try {
//服务启动
srv.startService();
//发件箱信息
msg = new OutboundMessage(mobilePhones, content);
msg.setEncoding(MessageEncodings.ENCUCS2); // 中文
//真正发送消息
srv.sendMessage(msg);
srv.stopService();
} catch (Exception e) {
e.printStackTrace();