发送消息SMSLib

时间:2017-06-19 09:26:36

标签: java sms at-command sms-gateway smslib

我正在使用SMSLib v4在IP模式下与GSM网关通信。 我成功发送和接收消息但问题出在传递消息上。 在使用Diaffan SMS Server进行测试后,我发现当使用国际格式的接收方号码(例如+98 ........)发送时,传递信息来自Diafaan。 我设置了选项,使得两者中的PDU变得相同。但钢铁在我的应用程序中没有收到交货。

我的代码是:

public class TestIPModem 

{
    public  String RECIPIENT1 = "+98...";
    public  String message = "salam";
    public  int count = 1;

    public class InboundMessageCallback implements IInboundMessageCallback
    {
        @Override
        public boolean process(InboundMessageCallbackEvent event)
        {

            if(event.getMessage().getType() == Type.Inbound){
                System.out.println(event.getMessage().getPayload().getText());
            }else if (event.getMessage().getType() == Type.StatusReport){
                System.out.println(event.getMessage().getPayload().getText() + "Delivery");
            }
            return true;
        }
    }

    public class DeliveryReportCallback implements IDeliveryReportCallback
    {
        @Override
        public boolean process(DeliveryReportCallbackEvent event)
        {
            System.out.println("[DeliveryReportCallback] " + event.getMessage().toShortString());
            System.out.println(event.getMessage().toString());
            return true;
        }
    }

    public void test() throws Exception
    {

        {

            Settings.deleteMessagesAfterCallback = true;
            Settings.modemPollingInterval = 100; 
            Service.getInstance().setInboundMessageCallback(new InboundMessageCallback());
            Service.getInstance().setDeliveryReportCallback(new DeliveryReportCallback());
            Service.getInstance().start();

            Modem gateway1 = new Modem("modem1", "192.168.2.77", "9101", "0000", "0000", "+989350001400", "SM");
            gateway1.setRequestDeliveryReport(true);
            Service.getInstance().registerGateway(gateway1);

            new Sender(1,count, RECIPIENT1, message, gateway1).start();

        }
    }

    public class Sender implements Runnable{
        int number;
        int count;
        String receiver;
        String message;
        Modem modem;

        public Sender(int number, int count, String receiver, String message, Modem m) {
            this.number = number;
            this.count = count;
            this.receiver = receiver;
            this.message = "";
            this.modem = m;
        }

        @Override
        public void run() {
            int i = 0;
            while(i < this.count){
                try {
                    OutboundMessage m = new OutboundMessage(this.receiver, this.messager);
                    m.setRequestDeliveryReport(true);
                    try {
                        modem.send(m);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    Thread.currentThread();
                    Thread.sleep(10);
                    i++;
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        }
    }

    public static void main(String[] args) throws Exception {
        new Thread(new Runnable() {
            @Override
            public void run() {
                while(true){
                    try {
                        Thread.currentThread();
                        Thread.sleep(100000);

                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();
        new TestIPModem().test();
    }
}

那么您认为问题在哪里?

更新: 他们说SMSLib不支持+ CDS传送报告。

0 个答案:

没有答案