zl程序教程

您现在的位置是:首页 >  后端

当前栏目

java调用短信猫发短信示例

JAVA 示例 调用 短信 发短信
2023-06-13 09:15:25 时间

具体的操作步骤如下:
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。

复制代码代码如下:


ackagecom.alonely.notecat;
importorg.smslib.IOutboundMessageNotification;
importorg.smslib.Outbou、ndMessage;
importorg.smslib.Service;
importorg.smslib.Message.MessageEncodings;
importorg.smslib.modem.SerialModemGateway;

publicclassSendMessage{
 publicclassOutboundNotificationimplementsIOutboundMessageNotification{
 publicvoidprocess(StringgatewayId,OutboundMessagemsg){
  System.out.println("OutboundhandlercalledfromGateway:"
    +gatewayId);
  System.out.println(msg);
 }
 }
 @SuppressWarnings("deprecation")
 publicvoidsendSMS(StringmobilePhones,Stringcontent){
 Servicesrv;
 OutboundMessagemsg;
 OutboundNotificationoutboundNotification=newOutboundNotification();
 srv=newService();
 SerialModemGatewaygateway=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(inti=0;i<phones.length;i++){
   msg=newOutboundMessage(phones[i],content);
   msg.setEncoding(MessageEncodings.ENCUCS2);//中文
   srv.sendMessage(msg);
  }
  srv.stopService();
 }catch(Exceptione){
  e.printStackTrace();
 }
 }
 publicstaticvoidmain(String[]args){
 SendMessagesendMessage=newSendMessage();
 sendMessage.sendSMS("您要发送的手机号","您要发送的内容!");
 }
}