亲宝软件园·资讯

展开

java发短信 java调用短信猫发短信示例

人气:0
想了解java调用短信猫发短信示例的相关内容吗,在本文为您仔细讲解java发短信的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:短信猫,发短信,下面大家一起来学习吧。

具体的操作步骤如下:
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("您要发送的手机号", "您要发送的内容!");
 }
}

加载全部内容

相关教程
猜你喜欢
用户评论