最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

smslib發(fā)短信實例代碼(電腦發(fā)短信)

 更新時間:2013年12月19日 10:49:26   作者:  
smslib發(fā)短信實例,大家可以參考使用開發(fā)自己的程序

SMSLib是一個由很多程序員共同開發(fā)的,用于支持GSM貓或者手機發(fā)送短信的開源項目,下面來個實例代碼

復制代碼 代碼如下:

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 {

 // 短信網(wǎng)關(guān)
 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);
    }
   }
   // 初始化短信網(wǎng)關(guān)
   gateway = new SerialModemGateway("modem." + portName, portName, port,
     "wavecom", "17254");

  } catch (Exception e) {
   LOG.error("網(wǎng)關(guān)初始化失?。? + 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);
 }

 /**
  * 發(fā)送短信
  * @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);// 這句話是發(fā)中文短信必須的
  srv.sendMessage(msg);
 }

 /**
  * 發(fā)送消息類
  * @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 + "條;發(fā)件人:"+msg.getOriginator() + ";內(nèi)容:" + msg.getText() + "\n");
    //sb.append(msg.toString() + "\n");
    LOG.info("第" + num + "條;發(fā)件人:"+msg.getOriginator() + ";內(nèi)容:" + 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);
  }
 }

}

相關(guān)文章

  • SpringBoot模擬員工數(shù)據(jù)庫并實現(xiàn)增刪改查操作

    SpringBoot模擬員工數(shù)據(jù)庫并實現(xiàn)增刪改查操作

    這篇文章主要給大家介紹了關(guān)于SpringBoot模擬員工數(shù)據(jù)庫并實現(xiàn)增刪改查操作的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2021-09-09
  • Java中equals()方法重寫實現(xiàn)代碼

    Java中equals()方法重寫實現(xiàn)代碼

    這篇文章主要介紹了Java中equals()方法重寫實現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下
    2017-05-05
  • 利用Java實體bean對象批量數(shù)據(jù)傳輸處理方案小結(jié)

    利用Java實體bean對象批量數(shù)據(jù)傳輸處理方案小結(jié)

    javabean是對面向?qū)ο笏枷氲囊环N具體實施的表現(xiàn),本文重點給大家介紹利用Java實體bean對象批量數(shù)據(jù)傳輸處理方案小結(jié),本文通過兩種方案給大家介紹的非常詳細,感興趣的朋友跟隨小編一起看看吧
    2021-05-05
  • Java?泛型的上界和下界通配符示例詳解

    Java?泛型的上界和下界通配符示例詳解

    這篇文章主要為大家通過示例介紹了Java?泛型的上界和下界通配符,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-04-04
  • Java8新特性之重復注解與類型注解詳解

    Java8新特性之重復注解與類型注解詳解

    這篇文章主要使介紹了Java8新特性重復注解與類型注解,文章還介紹了JDK5中的注解與之對比,感興趣的朋友可以參考下面具體文章內(nèi)容
    2021-09-09
  • 一文帶你搞懂Java中Synchronized和Lock的原理與使用

    一文帶你搞懂Java中Synchronized和Lock的原理與使用

    這篇文章主要為大家詳細介紹了Java中Synchronized和Lock的原理與使用,文中的示例代碼講解詳細,對我們學習Java有一定的幫助,需要的可以參考一下
    2023-04-04
  • 淺談為什么Java里面String類是不可變的

    淺談為什么Java里面String類是不可變的

    這篇文章主要介紹了為什么Java里面String類是不可變的,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-03-03
  • 解決Spring Security的權(quán)限配置不生效問題

    解決Spring Security的權(quán)限配置不生效問題

    這篇文章主要介紹了解決Spring Security的權(quán)限配置不生效問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • Java實現(xiàn)PDF打印的解決方案

    Java實現(xiàn)PDF打印的解決方案

    今天小編就為大家分享一篇關(guān)于Java實現(xiàn)PDF打印的解決方案,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2018-12-12
  • java中int值直接賦值給char類型的方法詳解

    java中int值直接賦值給char類型的方法詳解

    這篇文章主要給大家介紹了關(guān)于java中int值直接賦值給char類型的相關(guān)資料,文中通過代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2024-12-12

最新評論

武强县| 区。| 彰化县| 克拉玛依市| 定陶县| 营山县| 墨竹工卡县| 富锦市| 乐清市| 凤凰县| 如皋市| 辽阳市| 吴忠市| 凤凰县| 白山市| 二手房| 丹棱县| 石家庄市| 屏东县| 湘潭市| 金华市| 翼城县| 游戏| 革吉县| 高淳县| 东源县| 丰台区| 青州市| 太谷县| 郴州市| 合阳县| 静乐县| 新建县| 当阳市| 普兰县| 富裕县| 萍乡市| 南雄市| 贺州市| 沐川县| 昭平县|