gpt4 book ai didi

java - SMSlib 接收重复消息

转载 作者:行者123 更新时间:2023-11-30 03:37:08 25 4
gpt4 key购买 nike

我正在尝试使用 D-Link USB 调制解调器在计算机上接收短信。我已经在这个 link 上找到了我的问题的解决方案但现在我面临的问题是我收到相同的消息 3 次,就像这样

New Inbound message detected from Gateway: 923145663675 Hello
New Inbound message detected from Gateway: 923145663675 Hello
New Inbound message detected from Gateway: 923145663675 Hello

此外,如果程序长时间保持打开状态,那么上述给定的行将一次又一次地打印在屏幕上我在谷歌上搜索了很多,有些地方我发现了删除未使用的通知的建议,我已经这样做了,但仍然收到重复的消息。代码如下

public void doIt() throws Exception{                
InboundNotification inboundNotification = new InboundNotification();

try{

SerialModemGateway gateway = new SerialModemGateway("modem.com4", "COM7", 921600, "", "");

gateway.setProtocol(Protocols.PDU);
gateway.setInbound(true);
gateway.setSimPin("0000");
Service.getInstance().setInboundMessageNotification(inboundNotification);
Service.getInstance().addGateway(gateway);
Service.getInstance().startService();

System.out.println("Now Sleeping - Hit <enter> to stop service.");
System.in.read();
System.in.read();
}catch (Exception e){
e.printStackTrace();
}finally{
Service.getInstance().stopService();
}
}

public class InboundNotification implements IInboundMessageNotification{
public void process(AGateway gateway, MessageTypes msgType, InboundMessage msg){

if (msgType == MessageTypes.INBOUND) {
System.out.println("New Inbound message detected from Gateway: " + msg.getOriginator() + " " + msg.getText());

try {
gateway.deleteMessage(msg);
} catch (GatewayException ex) {
Logger.getLogger(ReadMessages.class.getName()).log(Level.SEVERE, null, ex);
}

}
}
}

最佳答案

曾经我也面临同样的问题,而我的要求是保留所有传入消息的记录。因此,我在数据库中创建表,并将所有传入消息插入数据库中,并提供完整的详细信息,例如发件人号码、消息内容以及日期和时间。在数据库中,我结合日期、时间和消息内容做了独特的记录。

现在,如果我收到重复的消息,那么日期、时间和消息内容肯定是相同的。之后,当这些值插入数据库时​​,重复的值将不会插入数据库。因此,我们将拥有独特的数据。

但这可能对您不起作用,因为实际上您不会多次收到消息,您只收到一条消息,然后会多次向您显示通知。因为如果您多次收到消息,那么日期和时间必须始终不同。但就我而言,这些总是相同的。因此,首先您应该尝试从收件箱中删除所有消息,然后也许您需要刷新接收端口。

关于java - SMSlib 接收重复消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27587348/

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