短信猫开发

使用java操作wavecom短信猫来发短信的方法  

  实现这个功能,需要两个jar包,可以到http://download.csdn.net/detail/yuexin2/6855961下载smslib-3.3.0b2.jar和http://download.csdn.net/detail/yuexin2/6855979下载javacomm20-win32.zip。

     首先,把smslib-3.3.0b2.jar,放 入工程lib中,再把javacomm20-win32.zip解开,里面的comm.jar需要放到工程lib 下,javax.comm.properties放到%JAVA_HOME%/jre/lib下,win32com.dll放到%JAVA_HOME% /jre/bin下。路径放错了,调用起来就会报错的。注意在官方网站的jar包已经不能运行下面代码。移动测试没问题,其他的暂时没测试。
环境配置好了以后,使用起来很简单,贴下我的代码:

package song.test;

importorg.smslib.IOutboundMessageNotification;

import org.smslib.OutboundMessage;

import org.smslib.Service;

import org.smslib.Message.MessageEncodings;

import org.smslib.modem.SerialModemGateway;

//移动ok

public class SendMessage {

 public class OutboundNotification implementsIOutboundMessageNotification {

 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 = newSerialModemGateway("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("183XXXX7887", "您要发送的内容!");

 }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值