Using SMPP to send sms texts in JAVA

I am trying to send sms using JAVA. After googling, I found out that SMPP protocol should be used for this and came across the source code below.

public class SendSMS
{
public static void main(String[] args) throws Exception
{
    SendSMS obj = new SendSMS();
    SendSMS.sendTextMessage("<mobile number>");
}

private TimeFormatter tF = new AbsoluteTimeFormatter();

/*
 * This method is used to send SMS to for the given MSISDN
 */
public void sendTextMessage(String MSISDN)
{

    // bind param instance is created with parameters for binding with SMSC
    BindParameter bP = new BindParameter(
            BindType.BIND_TX, 
            "<user_name>",
            "<pass_word>", 
            "<SYSTEM_TYPE>", 
            TypeOfNumber.UNKNOWN,
            NumberingPlanIndicator.UNKNOWN,
            null);

    SMPPSession smppSession = null;

    try
    {
        // smpp session is created using the bindparam and the smsc ip address/port
        smppSession = new SMPPSession("<SMSC_IP_ADDRESS>", 7777, bP);
    }
    catch (IOException e1)
    {
        e1.printStackTrace();
    }

    // Sample TextMessage
    String message = "This is a Test Message";

    GeneralDataCoding dataCoding = new GeneralDataCoding(false, true,
            MessageClass.CLASS1, Alphabet.ALPHA_DEFAULT);

    ESMClass esmClass = new ESMClass();

    try
    {
        // submitShortMessage(..) method is parametrized with necessary
        // elements of SMPP submit_sm PDU to send a short message
        // the message length for short message is 140
        smppSession.submitShortMessage(
                "CMT",
                TypeOfNumber.NATIONAL,
                NumberingPlanIndicator.ISDN,
                "<MSISDN>",
                TypeOfNumber.NATIONAL, 
                NumberingPlanIndicator.ISDN, 
                MSISDN,
                esmClass, 
                (byte) 0, 
                (byte) 0, 
                tF.format(new Date()),
                null,
                new RegisteredDelivery(SMSCDeliveryReceipt.DEFAULT),
                (byte) 0,
                dataCoding, 
                (byte) 0, 
                message.getBytes());
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}

      

}

But the problem I am running into with the original code is that it requires a certain set of parameters like username, pass_word, system_type, SMSC IP address, etc., which I am not aware of. I only recently learned about the SMPP protocol and therefore do not know how to get this code to work in order to execute my utility to send sms to my mobile phone. So can someone please help me get this code to work or guide me to a place where I can find out about this?

+3


source to share


3 answers


I recently worked on an SMPP project.

The library I used for the SMPP protocol is OpenSMPP .

Here is an example of my class for generating and sending SMPP data

public class SmppTransport implements Transport {

@Override
public void send(String url, Map<String, String> map) throws IOException {
    int smscPort = Integer.parseInt(map.get("port"));
    String smscHost = map.get("send_url");
    String smscUsername = map.get("username");
    String smscPassword = map.get("password");
    String recipientPhoneNumber = map.get("phone_num");
    String messageText = map.get("text");

    try {
        SubmitSM request = new SubmitSM();
     // request.setSourceAddr(createAddress(senderPhoneNumber)); // you can skip this
        request.setDestAddr(createAddress(recipientPhoneNumber));
        request.setShortMessage(messageText);
     // request.setScheduleDeliveryTime(deliveryTime);           // you can skip this
        request.setReplaceIfPresentFlag((byte) 0);
        request.setEsmClass((byte) 0);
        request.setProtocolId((byte) 0);
        request.setPriorityFlag((byte) 0);
        request.setRegisteredDelivery((byte) 1); // we want delivery reports
        request.setDataCoding((byte) 0);
        request.setSmDefaultMsgId((byte) 0);

        Session session = getSession(smscHost, smscPort, smscUsername, smscPassword);
        SubmitSMResp response = session.submit(request);
    } catch (Throwable e) {
        // error
    }
}

private Session getSession(String smscHost, int smscPort, String smscUsername, String smscPassword) throws Exception{
    if(sessionMap.containsKey(smscUsername)) {
        return sessionMap.get(smscUsername);
    }

    BindRequest request = new BindTransmitter();
    request.setSystemId(smscUsername);
    request.setPassword(smscPassword);
 // request.setSystemType(systemType);
 // request.setAddressRange(addressRange);
    request.setInterfaceVersion((byte) 0x34); // SMPP protocol version

    TCPIPConnection connection = new TCPIPConnection(smscHost, smscPort);
 // connection.setReceiveTimeout(BIND_TIMEOUT);
    Session session = new Session(connection);
    sessionMap.put(smscUsername, session);

    BindResponse response = session.bind(request);
    return session;
}

private Address createAddress(String address) throws WrongLengthOfStringException {
    Address addressInst = new Address();
    addressInst.setTon((byte) 5); // national ton
    addressInst.setNpi((byte) 0); // numeric plan indicator
    addressInst.setAddress(address, Data.SM_ADDR_LEN);
    return addressInst;
}

}

      



And my operator gave me these parameters for SMPP. There are many configuration options, but they are necessary

#host = 192.168.10.10 // operator smpp server ip
#port = 12345         // operator smpp server port
#smsc-username = "my_user" 
#smsc-password = "my_pass" 
#system-type = "" 
#source-addr-ton = 5
#source-addr-npi = 0

      

Therefore, if you want to test your code without registering with a GSM service provider, you can simulate an SMPP server on your computer. SMPPSim is a great testing project. Download it and run it on your computer. It can be configured in several ways, for example. request delivery reports from SMPP server, set sms change rate and etc I tested SMPPSim on Linux.

+4


source


Use this simulator here.It acts as a service, after building and testing your application on it, you only need to change the configuration parameters (username, password, ip, port, ...) provided to you by the service provider.



you can find all the configurations to connect to this simulator in the conf file.

+1


source


SMPP is a protocol between mobile network operators / operators and content providers. The fields you provided (username, password, SMSC IP) are provided by operators. Unfortunately, unless you work for a content provider or have a deal with an operator, you are unlikely to get this data.

Simulators may let you test your SMPP code, but they don't actually deliver content to your phone.

My best advice if you want to send SMS from your Java application would be to use SMS API like Twilio .

0


source







All Articles