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下
注意:路徑放錯(cuò),調(diào)用起來(lái)就會(huì)報(bào)錯(cuò);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("初始化成功,準(zhǔn)備開(kāi)啟服務(wù)");
try {
srv.startService();
System.out.println("服務(wù)啟動(dòng)成功");
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ā)送的手機(jī)號(hào)", "您要發(fā)送的內(nèi)容!");
}
}
相關(guān)文章
使用SpringBoot項(xiàng)目導(dǎo)入openfeign版本的問(wèn)題
這篇文章主要介紹了使用SpringBoot項(xiàng)目導(dǎo)入openfeign版本的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-03-03Jaxb2實(shí)現(xiàn)JavaBean與xml互轉(zhuǎn)的方法詳解
這篇文章主要介紹了Jaxb2實(shí)現(xiàn)JavaBean與xml互轉(zhuǎn)的方法,簡(jiǎn)單介紹了JAXB的概念、功能及實(shí)現(xiàn)JavaBean與xml互轉(zhuǎn)的具體操作技巧,需要的朋友可以參考下2017-04-04詳解mybatis.generator配上最新的mysql 8.0.11的一些坑
這篇文章主要介紹了詳解mybatis.generator配上最新的mysql 8.0.11的一些坑,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-10-10Java面試高頻問(wèn)題之RabbitMQ系列全面解析
在介紹RabbitMQ之前實(shí)現(xiàn)要介紹一下MQ,MQ是什么?MQ全稱(chēng)是Message Queue,可以理解為消息隊(duì)列的意思,簡(jiǎn)單來(lái)說(shuō)就是消息以管道的方式進(jìn)行傳遞。RabbitMQ是一個(gè)實(shí)現(xiàn)了AMQP(Advanced Message Queuing Protocol)高級(jí)消息隊(duì)列協(xié)議的消息隊(duì)列服務(wù),用Erlang語(yǔ)言的2021-11-11解決spring-boot2.0.6中webflux無(wú)法獲得請(qǐng)求IP的問(wèn)題
這幾天在用 spring-boot 2 的 webflux 重構(gòu)一個(gè)工程,寫(xiě)到了一個(gè)需要獲得客戶端請(qǐng)求 IP 的地方,在寫(xiě)的過(guò)程中遇到很多問(wèn)題,下面小編通過(guò)一段代碼給大家介紹解決spring-boot2.0.6中webflux無(wú)法獲得請(qǐng)求IP的問(wèn)題,感興趣的朋友跟隨小編一起看看吧2018-10-10Java Scala實(shí)現(xiàn)數(shù)據(jù)庫(kù)增刪查改操作詳解
這篇文章主要介紹了Java Scala實(shí)現(xiàn)數(shù)據(jù)庫(kù)增刪查改操作,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧2023-04-04