用SMSLib通过COM来发短信(JAR包及配置) XML

  第一步:
The installation procedure for both the old Java Comm v2 and the new Java Comm v3 is identical.

Java Comm v2 is for Win32 systems and it is available on the Download page.

Java Comm v3 is for Linux systems and it is available for download directly from SUN downloads (registration is required)

To install it, unzip the downloaded archive file in a temporary place and do the following copies:

File comm.jar should go under JDKDIR/jre/lib/ext/
File javax.comm.properties should go under JDKDIR/jre/lib/
Library files (i.e. win32com.dll for Win32 or the .so Linux library files) should go under JDKDIR/jre/bin/
If you have a separate JRE directory, do the same copies for the JREDIR directory!

即comm.jar导入引用包中,javax.comm.properties拷贝到JDKDIR/jre/lib/下,win32com.dll拷贝到 JDKDIR/jre/bin/下



第二步:
把相应的包导入就可以了。

当时在做的时候,发现通过SMSLib发送程序还是比较麻烦的,他的日志采用的是slf4j,而slf4j是基于log4j的,这几个不同的JAR包都是在不同的地方下载的,在此所有的JAR整理出来,希望大家节约时间

JAR包下载地址http://www.ziddu.com/download/7798641/phonesendmessageJAR.rar.html


测试源码:
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--> package  org.asdtiang.phone.sendMessage;

import  org.smslib.IOutboundMessageNotification;
import  org.smslib.Message.MessageEncodings;
import  org.smslib.OutboundMessage;
import  org.smslib.modem.SerialModemGateway;

public   class  Main {
private   static  org.smslib.Service srv  =   new  org.smslib.Service();;

public   static   void  creatService() {
SerialModemGateway gateway 
=   new  SerialModemGateway( " SMS " " COM3 " ,
9600 " LENOVO " " 6070 " );
gateway.setInbound(
true );
gateway.setOutbound(
true );
try  {
srv.addGateway(gateway);
srv.startService();
System.out.println(
" Modem connected. " );
sendSms(
" 15100164985 " " 测试用 " );
catch  (Exception ex) {
ex.printStackTrace();
}
}

public   static  org.smslib.Service getService() {
if  (srv  ==   null ) {
creatService();
}
return  srv;
}

public   static   void  disconnect() {
try  {
//  srv.disconnect();

System.out.println(
" Modem disconnected. " );
catch  (Exception ex) {
ex.printStackTrace();
}

}

public   static   void  main(String args[]) {
creatService();
}

public   static   boolean  sendSms(String mobile, String content) {
OutboundMessage msg 
=   new  OutboundMessage(mobile, content);
msg.setEncoding(MessageEncodings.ENCUCS2);
try  {
srv.sendMessage(msg);
System.out.println(msg);
catch  (Exception ex) {
//  log.error(ex);
return   false ;
}
return   true ;
}

public   void  close() {
try  {
srv.stopService();
catch  (Exception ex) {
//  log.error(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);
}
}
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值