程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> 關於JAVA >> java挪用短信貓發短信示例

java挪用短信貓發短信示例

編輯:關於JAVA

java挪用短信貓發短信示例。本站提示廣大學習愛好者:(java挪用短信貓發短信示例)文章只能為提供參考,不一定能成為您想要的結果。以下是java挪用短信貓發短信示例正文


詳細的操作步調以下:
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("您要發送的手機號", "您要發送的內容!");
 }
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved