gpt4 book ai didi

java - java smslib 库未收到短信

转载 作者:太空宇宙 更新时间:2023-11-04 11:56:29 24 4
gpt4 key购买 nike

我尝试这样做,但有时无法正常工作..我使用了 while 循环来循环代码。我可以为此添加一些监听器吗?任何人都可以给我正确的答案吗?需要实时获得响应

 while (true) {
msgList = new ArrayList<InboundMessage>();
Service.getInstance().readMessages(msgList, InboundMessage.MessageClasses.ALL);
for (InboundMessage im : msgList) {

if (last < im.getMemIndex()) {
ResultSet rs = DB.getConnection().createStatement().executeQuery("Select * From codes where code='" + im.getText() + "'");
if (rs.next()) {
ResultSet rs2 = DB.getConnection().createStatement().executeQuery("Select * From sms_log where code='" + im.getText() + "' AND tel_no='" + im.getOriginator() + "'");
if (rs2.next()) {
if (m == null) {
m = new SMSClient(1);
}
m.sendMessage(im.getOriginator(), "The Code is Already Sent... Thank You!.");

System.out.println("The Code is Already Sent... Thank You!.");
} else {
System.out.println("The Code Verified... Thank You!.");
if (m == null) {
m = new SMSClient(1);
}

m.sendMessage(im.getOriginator(), "The Code Verified... Thank You!.");
DB.getConnection().createStatement().execute("INSERT INTO sms_log (tel_no,code,status) values('" + im.getOriginator() + "','" + im.getText() + "',1)");

}
} else {
if (m == null) {
m = new SMSClient(1);
}
m.sendMessage(im.getOriginator(), "Invalid Code... Thank You!.");
System.out.println("Invalid Code... Thank You!.");
}

}
}
Thread.sleep(10000);
System.out.println("start");

}

最佳答案

我认为 IInboundMessageNotification 是您正在寻找的接口(interface)

public class InboundNotification implements IInboundMessageNotification {

@Override
public void process(AGateway aGateway, Message.MessageTypes messageTypes, InboundMessage inboundMessage) {
//add you logic for received messages here
}
}

向 smsLib 服务添加通知类

Service.getInstance().setInboundMessageNotification(new InboundNotification())

从现在开始,每次调制解调器收到消息时都会调用 process() 方法。

据我所知,smslib(版本3.5.x)不会删除收到的消息,因此需要手动完成

@Override
public void process(AGateway aGateway, Message.MessageTypes messageTypes, InboundMessage inboundMessage) {
try {
aGateway.deleteMessage(inboundMessage);
} catch (TimeoutException | GatewayException | InterruptedException | IOException e) {
e.printStackTrace();
}
// your logic here
}

否则,每次您收到新消息时,您都会继续收到未删除的消息。

希望您会发现这很有用。

关于java - java smslib 库未收到短信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41343571/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com