当前位置: 首页 > 工具软件 > SMSLib > 使用案例 >

smslib linux java commtest.java,java – smslib不发送短信为什么?

阎德辉
2023-12-01

我正在尝试用smslib发送短信但它没有发送消息,有人可以指导我吗?

这是我的代码:

import org.smslib.AGateway;

import org.smslib.IOutboundMessageNotification;

import org.smslib.Library;

import org.smslib.OutboundMessage;

import org.smslib.Service;

import org.smslib.modem.SerialModemGateway;

public class SendMessage

{

public void doIt() throws Exception

{

OutboundNotification outboundNotification = new OutboundNotification();

System.out.println("Example: Send message from a serial gsm modem.");

System.out.println(Library.getLibraryDescription());

System.out.println("Version: " + Library.getLibraryVersion());

SerialModemGateway gateway = new SerialModemGateway("modem.com1", "COM4", 115200, "Huawei", "");

gateway.setInbound(true);

gateway.setOutbound(true);

gateway.setSimPin("0000");

// Explicit SMSC address set is required for some modems.

// Below is for VODAFONE GREECE - be sure to set your own!

gateway.setSmscNumber("+919825068000");

Service.getInstance().setOutboundMessageNotification(outboundNotification);

Service.getInstance().addGateway(gateway);

Service.getInstance().startService();

System.out.println();

System.out.println("Modem Information:");

System.out.println(" Manufacturer: " + gateway.getManufacturer());

System.out.println(" Model: " + gateway.getModel());

System.out.println(" Serial No: " + gateway.getSerialNo());

System.out.println(" SIM IMSI: " + gateway.getImsi());

System.out.println(" Signal Level: " + gateway.getSignalLevel() + " dBm");

System.out.println(" Battery Level: " + gateway.getBatteryLevel() + "%");

System.out.println();

// Send a message synchronously.

OutboundMessage msg = new OutboundMessage("+524747388616", "que onda como andas!");

Service.getInstance().sendMessage(msg);

System.out.println(msg);

// Or, send out a WAP SI message.

//OutboundWapSIMessage wapMsg = new OutboundWapSIMessage("306974000000", new URL("http://www.smslib.org/"), "Visit SMSLib now!");

//Service.getInstance().sendMessage(wapMsg);

//System.out.println(wapMsg);

// You can also queue some asynchronous messages to see how the callbacks

// are called...

//msg = new OutboundMessage("309999999999", "Wrong number!");

//srv.queueMessage(msg, gateway.getGatewayId());

//msg = new OutboundMessage("308888888888", "Wrong number!");

//srv.queueMessage(msg, gateway.getGatewayId());

System.out.println("Now Sleeping - Hit to terminate.");

System.in.read();

Service.getInstance().stopService();

}

public class OutboundNotification implements IOutboundMessageNotification

{

public void process(AGateway gateway, OutboundMessage msg)

{

System.out.println("Outbound handler called from Gateway: " + gateway.getGatewayId());

System.out.println(msg);

}

}

public static void main(String args[])

{

SendMessage app = new SendMessage();

try

{

app.doIt();

}

catch (Exception e)

{

e.printStackTrace();

}

}

}

和我的结果:

Example: Send message from a serial gsm modem.

SMSLib: A Java API library for sending and receiving SMS via a GSM modem or other supported gateways.

This software is distributed under the terms of the Apache v2.0 License.

Web Site: http://smslib.org

Version: 3.5.1

Modem Information:

Manufacturer: Nokia Corporation

Model: Nokia Internet Stick CS-10

Serial No: 359340022861915

SIM IMSI: ** MASKED **

Signal Level: -53 dBm

Battery Level: 0%

===============================================================================

<< OutboundMessage >>

-------------------------------------------------------------------------------

Gateway Id: *

Message Id: 0

Message UUID: e30f84ad-b083-4956-85ef-16dc89020769

Encoding: 7-bit

Date: Fri Mar 09 13:15:52 CST 2012

SMSC Ref No: null

Recipient: 524747388616

Dispatch Date: null

Message Status: FAILED

Failure Cause: UNKNOWN

Validity Period (Hours): -1

Status Report: false

Source / Destination Ports: -1 / -1

Flash SMS: false

Text: que onda como andas!

PDU data: F17A19F47693C3A0F1BBFD0685DDE4F03C04

Scheduled Delivery: null

===============================================================================

Now Sleeping - Hit to terminate.

解决方法:

此示例有关于SMSC编号的额外代码行.我玩过这个相同的库,在我的代码中没有任何SMSC – 在我的代码的任何一行.

这是一个建议,“如果需要的话”,我当然相信摆脱它可以解决你的问题.你很可能不知道你究竟要把它放在什么地方,所以最好把它留下来.然后调制解调器不会尝试手动将此路由到给定的号码,但它可以使其正确,通过SIM卡上的SIM设置知道它.

我要检查的另一件事是调制解调器真的从COM4端口回答.虽然现在似乎这样做,因为读取信号强度.但总是检查一下,因为每次启动服务器都可以将设备映射到不同的端口.我在Linux方面至少遇到过这种问题.

标签:java,sms,smslib

来源: https://codeday.me/bug/20190826/1730383.html

 类似资料: