亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 編程 > Java > 正文

java使用smslib連接短信貓發送短信代碼分享

2019-11-26 15:41:45
字體:
來源:轉載
供稿:網友

復制代碼 代碼如下:

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.smslib.ICallNotification;
import org.smslib.IInboundMessageNotification;
import org.smslib.IOutboundMessageNotification;
import org.smslib.InboundMessage;
import org.smslib.InboundMessage.MessageClasses;
import org.smslib.Library;
import org.smslib.Message.MessageEncodings;
import org.smslib.Message.MessageTypes;
import org.smslib.OutboundMessage;
import org.smslib.Service;
import org.smslib.modem.SerialModemGateway;

/**
 * @author terry
 *
 */
public class SmsModem {

 // 短信網關
 private SerialModemGateway gateway = null;
 java.util.ResourceBundle rb = null;//ResourceBundle.getBundle("SMS");
 static SmsModem smsModem = null;
 OutboundNotification outboundNotification = new OutboundNotification();
 private static final Logger LOG = Logger.getLogger(SmsModem.class);
 Service srv;
 InboundNotification inboundNotification = new InboundNotification();
 // Create the notification callback method for inbound voice calls.
 CallNotification callNotification = new CallNotification();

 public SmsModem() {
  try {
   //ReadMessages rm = new ReadMessages();
   //rm.doIt();

   rb = ResourceBundle.getBundle("sms");
   String portName= "COM10";
   int port = 9600;
   LOG.info("default portName:" + portName);
   LOG.info("default port:" + port);
   if(rb != null)
   {
    LOG.info("RB is not null");
    if(rb.getString("smsport") != null && !"".equals(rb.getString("smsport")))
    {
     portName = rb.getString("smsport");
     LOG.info("portName:" + portName);
    }
    if(rb.getString("smsbolv") != null && !"".equals(rb.getString("smsbolv")))
    {
     port = Integer.valueOf(rb.getString("smsbolv"));
     LOG.info("port:" + port);
    }
   }
   // 初始化短信網關
   gateway = new SerialModemGateway("modem." + portName, portName, port,
     "wavecom", "17254");

  } catch (Exception e) {
   LOG.error("網關初始化失?。? + e.getMessage());
   e.printStackTrace();
  }
 }

 public static SmsModem getInstant() {
  if (smsModem == null) {
   smsModem = new SmsModem();
  }
  return smsModem;
 }

 public SerialModemGateway getGateway() {
  return gateway;
 }

 public void sendMessage(String phone, String content) throws Exception {
  doIt(phone, content);
 }

 /**
  * 發送短信
  * @param phone
  * @param content
  * @throws Exception
  */
 public void doIt(String phone, String content) throws Exception {

  OutboundMessage msg;

  LOG.info("Sent Example: Send message from a serial gsm modem.");
  LOG.info(Library.getLibraryDescription());
  LOG.info("Sent Version: " + Library.getLibraryVersion());
  if (srv == null) {
   srv = new Service();
   srv.S.SERIAL_POLLING = true;
   gateway.setInbound(true);
   gateway.setOutbound(true);
   gateway.setSimPin("0000");
   gateway.setOutboundNotification(outboundNotification);
   gateway.setInboundNotification(inboundNotification);
   gateway.setCallNotification(callNotification);
   srv.addGateway(gateway);
   srv.startService();
  }

  if (gateway != null) {
   LOG.info("Sent Modem Information:");
   LOG.info("Sent  Manufacturer: " + gateway.getManufacturer());
   LOG.info("Sent  Model: " + gateway.getModel());
   LOG.info("Sent  Serial No: " + gateway.getSerialNo());
   LOG.info("Sent  SIM IMSI: " + gateway.getImsi());
   LOG.info("Sent  Signal Level: " + gateway.getSignalLevel() + "%");
   LOG.info("Sent  Battery Level: " + gateway.getBatteryLevel() + "%");
  }
  // Send a message synchronously.

  msg = new OutboundMessage(phone, content);
  msg.setEncoding(MessageEncodings.ENCUCS2);// 這句話是發中文短信必須的
  srv.sendMessage(msg);
 }

 /**
  * 發送消息類
  * @author terry
  *
  */
 public class OutboundNotification implements IOutboundMessageNotification {
  public void process(String gatewayId, OutboundMessage msg) {
   LOG.info("Sent Outbound handler called from Gateway: " + gatewayId);
   LOG.info(msg);
  }
 }
 //接收消息類
 public String readMessage()
 {
  StringBuffer sb = new StringBuffer("");
  List<InboundMessage> msgList;
  // Create the notification callback method for Inbound & Status Report
  // messages.

  try
  {
   System.out.println("Read Example: Read messages from a serial gsm modem.");
   System.out.println(Library.getLibraryDescription());
   System.out.println("Read Version: " + Library.getLibraryVersion());
   // Create new Service object - the parent of all and the main interface
   // to you.
   if (srv == null) {
    srv = new Service();
    srv.S.SERIAL_POLLING = true;
    gateway.setInbound(true);
    gateway.setOutbound(true);
    gateway.setSimPin("0000");
    gateway.setOutboundNotification(outboundNotification);
    gateway.setInboundNotification(inboundNotification);
    gateway.setCallNotification(callNotification);
    srv.addGateway(gateway);
    srv.startService();
   }

   
   // Similarly, you may define as many Gateway objects, representing
   // various GSM modems, add them in the Service object and control all of them.
   //
   // Start! (i.e. connect to all defined Gateways)

   LOG.info("Read Modem Information:");
   LOG.info("Read   Manufacturer: " + gateway.getManufacturer());
   LOG.info("Read   Model: " + gateway.getModel());
   LOG.info("Read   Serial No: " + gateway.getSerialNo());
   LOG.info("Read   SIM IMSI: " + gateway.getImsi());
   LOG.info("Read   Signal Level: " + gateway.getSignalLevel() + "%");
   LOG.info("Read   Battery Level: " + gateway.getBatteryLevel() + "%");
   // Read Messages. The reading is done via the Service object and
   // affects all Gateway objects defined. This can also be more directed to a specific
   // Gateway - look the JavaDocs for information on the Service method calls.
   msgList = new ArrayList<InboundMessage>();
   this.srv.readMessages(msgList, MessageClasses.ALL);
   int num = 1;
   for (InboundMessage msg : msgList)
   {
    sb.append("第" + num + "條;發件人:"+msg.getOriginator() + ";內容:" + msg.getText() + "/n");
    //sb.append(msg.toString() + "/n");
    LOG.info("第" + num + "條;發件人:"+msg.getOriginator() + ";內容:" + msg.getText() + "/n");
    num++;
    LOG.info(msg);
   }
   // Sleep now. Emulate real world situation and give a chance to the notifications
   // methods to be called in the event of message or voice call reception.
   //System.out.println("Now Sleeping - Hit <enter> to terminate.");
   //System.in.read();
  }
  catch (Exception e)
  {
   sb.append(e.getMessage());
   e.printStackTrace();
  }
  finally
  {
   //this.srv.stopService();
  }
  return sb.toString();
 }

 public class InboundNotification implements IInboundMessageNotification
 {
  public void process(String gatewayId, MessageTypes msgType, InboundMessage msg)
  {
   if (msgType == MessageTypes.INBOUND) System.out.println(">>> New Inbound message detected from Gateway: " + gatewayId);
   else if (msgType == MessageTypes.STATUSREPORT) System.out.println(">>> New Inbound Status Report message detected from Gateway: " + gatewayId);
   System.out.println(msg);
   try
   {
    // Uncomment following line if you wish to delete the message upon arrival.
    // srv.deleteMessage(msg);
   }
   catch (Exception e)
   {
    System.out.println("Oops!!! Something gone bad...");
    e.printStackTrace();
   }
  }
 }

 public class CallNotification implements ICallNotification
 {
  public void process(String gatewayId, String callerId)
  {
   System.out.println(">>> New call detected from Gateway: " + gatewayId + " : " + callerId);
  }
 }

}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
亚洲成人av中文字幕| 亚洲精品99久久久久中文字幕| 亚洲情综合五月天| 日韩最新av在线| 欧美精品18videos性欧美| 国模精品视频一区二区| 最近2019年好看中文字幕视频| 国产精品福利在线| x99av成人免费| 久久久久久久爱| 亚洲精品国产福利| 欧美精品电影免费在线观看| 欧美激情第一页xxx| 亚洲午夜精品久久久久久性色| 日韩欧美第一页| 欧美性69xxxx肥| 欧美久久精品午夜青青大伊人| 欧美在线激情视频| 97视频在线观看免费高清完整版在线观看| 日韩精品在线私人| 欧美成人四级hd版| 久久精品电影一区二区| 亚洲成人999| 欧美激情性做爰免费视频| 久久久成人av| 国产精品视频自拍| 欧美片一区二区三区| 成人黄色影片在线| 欧美成人剧情片在线观看| 蜜月aⅴ免费一区二区三区| 国产日韩一区在线| 国产成人精品亚洲精品| 亚洲精品suv精品一区二区| 777国产偷窥盗摄精品视频| 91亚洲永久免费精品| 国产成人精彩在线视频九色| 成人网在线观看| 国产精品视频在线播放| 在线看日韩av| 懂色av影视一区二区三区| 91网站在线看| 国产成人鲁鲁免费视频a| 日韩一区二区av| 欧美精品久久久久| 国产精品网址在线| 日韩av网站导航| 国产成人亚洲综合| 日韩在线欧美在线| 欧美性精品220| 亚洲国产精品字幕| 在线午夜精品自拍| 国产日韩在线一区| 日韩av在线免费观看| 日韩国产高清污视频在线观看| 97在线视频免费看| 日韩国产高清污视频在线观看| 亚洲iv一区二区三区| 久久久久日韩精品久久久男男| 欧美激情区在线播放| 亚洲欧美日韩中文在线| 欧美精品福利在线| 国内伊人久久久久久网站视频| 国产综合福利在线| 欧美成年人在线观看| 欧美成人精品激情在线观看| 国产999在线| 欧美在线视频网站| 精品人伦一区二区三区蜜桃免费| 国产精品wwwwww| 最近中文字幕mv在线一区二区三区四区| 久久av.com| 国产精品香蕉国产| 中文字幕亚洲无线码a| 欧美黑人巨大精品一区二区| 久久九九全国免费精品观看| 亚洲福利影片在线| 欧美激情网站在线观看| 尤物99国产成人精品视频| 亚洲电影中文字幕| 少妇高潮久久久久久潘金莲| 日韩色av导航| 日韩中文视频免费在线观看| 日韩免费观看av| 色综合久久悠悠| 成人精品aaaa网站| 久久福利视频导航| 国产精品免费久久久久久| 亚洲一区二区三区sesese| 在线亚洲午夜片av大片| 欧美色视频日本版| 97免费中文视频在线观看| 国产精品热视频| 欧美人与性动交| 69久久夜色精品国产7777| 国产日韩在线免费| 欧美片一区二区三区| 亚洲欧美国产精品va在线观看| 欧美情侣性视频| 日韩中文字幕在线视频播放| www高清在线视频日韩欧美| 中文字幕日韩av电影| 中文字幕在线观看日韩| 中文日韩在线观看| 热久久这里只有精品| 91久久久国产精品| 理论片在线不卡免费观看| 欧美性视频网站| 91免费综合在线| 亚洲高清色综合| 欧美日韩福利电影| 亚洲乱码av中文一区二区| 日韩亚洲欧美中文在线| 欧美午夜视频在线观看| 高清一区二区三区四区五区| 日韩精品免费在线播放| 综合久久五月天| 日韩av中文字幕在线播放| 91av在线精品| 日韩中文字幕在线看| 色婷婷久久一区二区| 中文字幕精品av| 欧美激情中文字幕乱码免费| 欧美高清自拍一区| 日本三级韩国三级久久| 国产偷国产偷亚洲清高网站| 国产精品成人一区二区| 俺去亚洲欧洲欧美日韩| 欧美日韩亚洲精品内裤| 亚洲一区二区三区在线视频| 国产精品老牛影院在线观看| 97欧美精品一区二区三区| 97碰在线观看| 国产福利视频一区二区| 国产香蕉一区二区三区在线视频| 欧美成人精品三级在线观看| 国产精品免费一区豆花| www高清在线视频日韩欧美| 性色av一区二区三区免费| 精品亚洲国产成av人片传媒| 亚洲午夜女主播在线直播| 精品视频在线观看日韩| 欧美黑人狂野猛交老妇| 欧美综合国产精品久久丁香| 日韩欧美福利视频| 国内久久久精品| 亚洲四色影视在线观看| 欧美成人午夜激情在线| 欧美成人性色生活仑片| 久久国产精品影片| 91色精品视频在线| 另类图片亚洲另类| 一本一本久久a久久精品牛牛影视| 欧美自拍大量在线观看| 在线精品视频视频中文字幕| 欧美激情在线一区| 91精品久久久久久综合乱菊| 奇米成人av国产一区二区三区| 亚洲夜晚福利在线观看| 国产精品日韩在线一区| 日韩精品在线电影| 欧美激情综合色综合啪啪五月| 国产美女精品视频免费观看| 欧美日韩一区二区精品| 91啪国产在线|