java調(diào)用短信貓發(fā)短信示例
具體的操作步驟如下:
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下
注意:路徑放錯,調(diào)用起來就會報錯;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", ""); //設(shè)置端口與波特率
gateway.setInbound(true);
gateway.setOutbound(true);
gateway.setSimPin("0000");
gateway.setOutboundNotification(outboundNotification);
srv.addGateway(gateway);
System.out.println("初始化成功,準備開啟服務(wù)");
try {
srv.startService();
System.out.println("服務(wù)啟動成功");
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("您要發(fā)送的手機號", "您要發(fā)送的內(nèi)容!");
}
}
相關(guān)文章
使用SpringBoot項目導(dǎo)入openfeign版本的問題
這篇文章主要介紹了使用SpringBoot項目導(dǎo)入openfeign版本的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-03-03Jaxb2實現(xiàn)JavaBean與xml互轉(zhuǎn)的方法詳解
這篇文章主要介紹了Jaxb2實現(xiàn)JavaBean與xml互轉(zhuǎn)的方法,簡單介紹了JAXB的概念、功能及實現(xiàn)JavaBean與xml互轉(zhuǎn)的具體操作技巧,需要的朋友可以參考下2017-04-04詳解mybatis.generator配上最新的mysql 8.0.11的一些坑
這篇文章主要介紹了詳解mybatis.generator配上最新的mysql 8.0.11的一些坑,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-10-10解決spring-boot2.0.6中webflux無法獲得請求IP的問題
這幾天在用 spring-boot 2 的 webflux 重構(gòu)一個工程,寫到了一個需要獲得客戶端請求 IP 的地方,在寫的過程中遇到很多問題,下面小編通過一段代碼給大家介紹解決spring-boot2.0.6中webflux無法獲得請求IP的問題,感興趣的朋友跟隨小編一起看看吧2018-10-10Java Scala實現(xiàn)數(shù)據(jù)庫增刪查改操作詳解
這篇文章主要介紹了Java Scala實現(xiàn)數(shù)據(jù)庫增刪查改操作,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧2023-04-04