java调用短信猫发短信示例
具体的操作步骤如下:
1、把smslib-3.3.0b2.jar、comm.jar与log4j-1.2.11.jar,放入到工程的lib中;
2、把javax.comm.properties放到%java_home%/jre/lib下;
3、把win32com.dll放到%java_home%/jre/bin下;
4 把comm.jar放到%java_home%/jre/ext下
注意:路径放错,调用起来就会报错;jdk的版本,用的版本是jdk-1_5_0_04。
ackage com.alonely.notecat;
import org.smslib.ioutboundmessagenotification;
import org.smslib.outbou、ndmessage;
import org.smslib.service;
import org.smslib.message.messageencodings;
import org.smslib.modem.serialmodemgateway;
public class sendmessage {
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);
}
}
@suppresswarnings("deprecation")
public void sendsms(string mobilephones, string content) {
service srv;
outboundmessage msg;
outboundnotification outboundnotification = new outboundnotification();
srv = new service();
serialmodemgateway gateway = new serialmodemgateway("modem.com3",
"com3", 9600, "wavecom", ""); //设置端口与波特率
gateway.setinbound(true);
gateway.setoutbound(true);
gateway.setsimpin("0000");
gateway.setoutboundnotification(outboundnotification);
srv.addgateway(gateway);
system.out.println("初始化成功,准备开启服务");
try {
srv.startservice();
system.out.println("服务启动成功");
string[] phones = mobilephones.split(",");
for (int i = 0; i < phones.length; i++) {
msg = new outboundmessage(phones[i], content);
msg.setencoding(messageencodings.encucs2); // 中文
srv.sendmessage(msg);
}
srv.stopservice();
} catch (exception e) {
e.printstacktrace();
}
}
public static void main(string[] args) {
sendmessage sendmessage = new sendmessage();
sendmessage.sendsms("您要发送的手机号", "您要发送的内容!");
}
}
上一篇: Spring框架之快速入门