opentelecoms-org / jsmpp

SMPP implemented in Java
Apache License 2.0
230 stars 160 forks source link

please help me how to use SubmitMultiExample.java #135

Open moonjunchoi opened 3 years ago

moonjunchoi commented 3 years ago

hi, i'm mj.

I am trying to make an smpp server using bulksmsonline.

I found an example called jsmpp -> SubmitMultiExample.

So I'm going to do this.

But I get an error. Below is the source and error code.

Please provide a solution..

=================================== ============== source ================

public class SubmitMultiExample { private static final Logger LOGGER = LoggerFactory.getLogger(SubmitMultiExample.class); private static final TimeFormatter TIME_FORMATTER = new AbsoluteTimeFormatter();

public static void main(String[] args) {

    // Create a new SMPP Session
    SMPPSession session = new SMPPSession();
    try {
        session.setMessageReceiverListener(new MessageReceiverListenerImpl());

        // Bind to the Server
        String systemId = session.connectAndBind("smpp.bulksmsonline.com", 8889,
                                new BindParameter(BindType.BIND_TRX, "myid123Q",
                                                    "mypass!@", "cp",
                                                    TypeOfNumber.UNKNOWN,
                                                    NumberingPlanIndicator.UNKNOWN,
                                                    null));
        LOGGER.info("Connected with SMSC with system id {}", systemId);

        try {
            Address address1 = new Address(TypeOfNumber.INTERNATIONAL, NumberingPlanIndicator.UNKNOWN, "821032550223");
            Address address2 = new Address(TypeOfNumber.INTERNATIONAL, NumberingPlanIndicator.UNKNOWN, "821029704451");
            Address[] addresses = new Address[] {address1, address2};
            SubmitMultiResult result = session.submitMultiple("CMT", TypeOfNumber.INTERNATIONAL, NumberingPlanIndicator.UNKNOWN, "1616",
                addresses, new ESMClass(), (byte)0, (byte)1, TIME_FORMATTER.format(new Date()), null,
                new RegisteredDelivery(SMSCDeliveryReceipt.FAILURE), ReplaceIfPresentFlag.REPLACE,
                new GeneralDataCoding(Alphabet.ALPHA_DEFAULT, MessageClass.CLASS1, false), (byte)0,
                "Test Message SMPP".getBytes());
            LOGGER.info("{} messages submitted, result message id {}", addresses.length, result.getMessageId());
            for (UnsuccessDelivery unsuccessDelivery: result.getUnsuccessDeliveries()){
                LOGGER.info("Unsuccessful delivery to {}: {}", unsuccessDelivery.getDestinationAddress(), unsuccessDelivery.getErrorStatusCode());
            }
            Thread.sleep(2000);
        } catch (PDUException e) {
            // Invalid PDU parameter
            LOGGER.error("Invalid PDU parameter", e);
        } catch (ResponseTimeoutException e) {
            // Response timeout
            LOGGER.error("Response timeout", e);
        } catch (InvalidResponseException e) {
            // Invalid response
            LOGGER.error("Receive invalid response", e);
        } catch (NegativeResponseException e) {
            // Receiving negative response (non-zero command_status)
            LOGGER.error("Receive negative response", e);
        } catch (IOException e) {
            LOGGER.error("I/O error occured", e);
        } catch (InterruptedException e) {
            LOGGER.error("Thread interrupted", e);
        }

        session.unbindAndClose();

    } catch (IOException e) {
        LOGGER.error("Failed connect and bind to host", e);
    }
}

}

=================================== ============= error code ==============

log4j:WARN No such property [append] in org.apache.log4j.ConsoleAppender. [- INFO] 2020-10-12 17:24:32,265 - Broadcasting sms [-DEBUG] 2020-10-12 17:24:32,286 - Connect and bind to smpp.bulksmsonline.com port 8889 [- INFO] 2020-10-12 17:24:32,500 - Connected from port 51138 to smpp.bulksmsonline.com/108.60.201.78:8889 [- INFO] 2020-10-12 17:24:32,503 - Starting PDUReaderWorker [-DEBUG] 2020-10-12 17:24:32,505 - Sending SMPP message 00 00 00 2a 00 00 00 02 00 00 00 00 00 00 00 01 43 6f 72 70 46 69 39 38 34 00 46 69 76 65 30 39 21 21 00 63 70 00 34 00 00 00 [-DEBUG] 2020-10-12 17:24:32,719 - Received SMPP message PDUHeader(25, 80000002, 00000000, 1) 62 73 6f 20 73 6d 70 70 00 [-DEBUG] 2020-10-12 17:24:32,720 - bind_resp header (25, 80000002, 00000000, 1) [- INFO] 2020-10-12 17:24:32,720 - Changing processor degree to 3 [-DEBUG] 2020-10-12 17:24:32,720 - bind response with sequence_number 1 received for session 99ca6a26 [- INFO] 2020-10-12 17:24:32,729 - Optional Parameter Tag class org.jsmpp.bean.OptionalParameter$Sc_interface_version not found [- INFO] 2020-10-12 17:24:32,730 - Connected with SMPP with system id bso smpp [-DEBUG] 2020-10-12 17:24:32,730 - Starting EnquireLinkSender for session 99ca6a26 [-DEBUG] 2020-10-12 17:24:32,736 - Sending SMPP message 00 00 00 56 00 00 00 21 00 00 00 00 00 00 00 02 43 4d 54 00 02 00 41 58 2d 44 45 56 00 02 01 02 00 00 01 02 00 00 00 00 01 32 30 31 30 31 32 31 37 32 34 33 32 37 33 36 2b 00 00 02 01 11 00 16 54 65 73 74 20 6d 65 73 73 61 67 65 20 66 72 6f 6d 20 73 75 63 6b [-DEBUG] 2020-10-12 17:24:32,936 - Received SMPP message PDUHeader(16, 80000000, 00000003, 2) [-ERROR] 2020-10-12 17:24:32,936 - Receive generick_nack. command_status=00000003, sequence_number=00000002 [-ERROR] 2020-10-12 17:24:32,936 - Receive invalid response org.jsmpp.GenericNackResponseException: Receive generic_nack with command_status 00000003 at org.jsmpp.session.state.AbstractGenericSMPPSessionBound.processGenericNack(AbstractGenericSMPPSessionBound.java:95) at org.jsmpp.session.PDUProcessTask.run(PDUProcessTask.java:69) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) [- INFO] 2020-10-12 17:24:32,938 - Pushed message to broker successfully [-DEBUG] 2020-10-12 17:24:32,938 - Unbind and close session 99ca6a26 [-DEBUG] 2020-10-12 17:24:32,938 - Sending SMPP message 00 00 00 10 00 00 00 06 00 00 00 00 00 00 00 03 [-DEBUG] 2020-10-12 17:24:33,138 - Received SMPP message PDUHeader(16, 80000006, 00000000, 3) [-DEBUG] 2020-10-12 17:24:33,138 - unbind response with sequence_number 3 received for session 99ca6a26 [-DEBUG] 2020-10-12 17:24:33,138 - Close session 99ca6a26 in state BOUND_TX [-DEBUG] 2020-10-12 17:24:33,139 - Stop enquireLinkSender for session 99ca6a26 [-DEBUG] 2020-10-12 17:24:33,139 - EnquireLinkSender stopped for session 99ca6a26 [- INFO] 2020-10-12 17:24:33,139 - Reading PDU session 99ca6a26 in state BOUND_TX: Socket Closed [-DEBUG] 2020-10-12 17:24:33,139 - Close session context 99ca6a26 in state BOUND_TX [-DEBUG] 2020-10-12 17:24:33,139 - Close session 99ca6a26 in state BOUND_TX [-DEBUG] 2020-10-12 17:24:33,139 - Close session 99ca6a26 in state CLOSED [-DEBUG] 2020-10-12 17:24:33,139 - PDUReaderWorker-99ca6a26 stopped

pmoerenhout commented 3 years ago

When I decode the submit_sm (00 00 00 56 00 00 00 21 00 00 00 00 00 00 00 02 43 4d 54 00 02 00 41 58 2d 44 45 56 00 02 01 02 00 00 01 02 00 00 00 00 01 32 30 31 30 31 32 31 37 32 34 33 32 37 33 36 2b 00 00 02 01 11 00 16 54 65 73 74 20 6d 65 73 73 61 67 65 20 66 72 6f 6d 20 73 75 63 6b) from the log, it fails because the two destination addresses are null. Also it doesn't seems to be generated from the source mentioned, as the source address is "AX-DEV" and the message is "Test message from suck".

moonjunchoi commented 3 years ago

When I decode the submit_sm (00 00 00 56 00 00 00 21 00 00 00 00 00 00 00 02 43 4d 54 00 02 00 41 58 2d 44 45 56 00 02 01 02 00 00 01 02 00 00 00 00 01 32 30 31 30 31 32 31 37 32 34 33 32 37 33 36 2b 00 00 02 01 11 00 16 54 65 73 74 20 6d 65 73 73 61 67 65 20 66 72 6f 6d 20 73 75 63 6b) from the log, it fails because the two destination addresses are null. Also it doesn't seems to be generated from the source mentioned, as the source address is "AX-DEV" and the message is "Test message from suck".

Thank you so much for answering. I have a few questions.

What should I do if the addresses of both destinations are null? How should I set it up?

I don't have enough knowledge about smpp.

Also, you said the source address is "AX-DEV". I defined this as String address = "AX-DEV". But I don't know the purpose. What does this mean? What is it used for?

pmoerenhout commented 3 years ago

When you send an SMS there is always a source (originator) and a destination (recipient). The source can be a number (MSISDN) or a text (AlphaNumeric). The destination (recipient) is normally always a number (MSISDN). With the submit_multi, you can send a message to multiple recipients. A null value as recipient address doesn't make sense. Either you want to send a message to a known recipient or you don't send a message at all. So if you have both recipients address to be null, there is no recipient at all. The source address "AX-DEV" is the originator which is displayed at the end in your phone as sender. It could be that your SMSC is not allowing random source addresses.