java調用簡訊貓發簡訊樣本_java

來源:互聯網
上載者:User

具體的操作步驟如下:
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("您要發送的手機號", "您要發送的內容!");
 }
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.