Sunday, 15 January 2012

Using SMPP to send sms texts in JAVA -



Using SMPP to send sms texts in JAVA -

i trying send sms using java. after googling, found out smpp protocol used , stumbled upon below source code.

public class sendsms { public static void main(string[] args) throws exception { sendsms obj = new sendsms(); sendsms.sendtextmessage("<mobile number>"); } private timeformatter tf = new absolutetimeformatter(); /* * method used send sms given msisdn */ public void sendtextmessage(string msisdn) { // bind param instance created parameters binding smsc bindparameter bp = new bindparameter( bindtype.bind_tx, "<user_name>", "<pass_word>", "<system_type>", typeofnumber.unknown, numberingplanindicator.unknown, null); smppsession smppsession = null; seek { // smpp session created using bindparam , smsc ip address/port smppsession = new smppsession("<smsc_ip_address>", 7777, bp); } grab (ioexception e1) { e1.printstacktrace(); } // sample textmessage string message = "this test message"; generaldatacoding datacoding = new generaldatacoding(false, true, messageclass.class1, alphabet.alpha_default); esmclass esmclass = new esmclass(); seek { // submitshortmessage(..) method parametrized necessary // elements of smpp submit_sm pdu send short message // message length short message 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()); } grab (exception e) { e.printstacktrace(); } }

}

but problem encounter source code requires specific set of parameters user_name, pass_word, system_type, smsc ip address etc have no clue of. have known smpp protocol , unaware of how code working fulfil usecase of sending sms mobile. can please help me code work or guide me place can larn doing this?

i've been working on smpp project recently.

the library used smpp protocol opensmpp.

here illustration of class building , 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"); seek { submitsm request = new submitsm(); // request.setsourceaddr(createaddress(senderphonenumber)); // can skip request.setdestaddr(createaddress(recipientphonenumber)); request.setshortmessage(messagetext); // request.setscheduledeliverytime(deliverytime); // can skip request.setreplaceifpresentflag((byte) 0); request.setesmclass((byte) 0); request.setprotocolid((byte) 0); request.setpriorityflag((byte) 0); request.setregistereddelivery((byte) 1); // want delivery reports request.setdatacoding((byte) 0); request.setsmdefaultmsgid((byte) 0); session session = getsession(smschost, smscport, smscusername, smscpassword); submitsmresp response = session.submit(request); } grab (throwable e) { // error } } private session getsession(string smschost, int smscport, string smscusername, string smscpassword) throws exception{ if(sessionmap.containskey(smscusername)) { homecoming 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); homecoming 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); homecoming addressinst; } }

and operator gave me parameters smpp. there many configuration options these essential

#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

so if want test code without registering gsm service provider, can simulate smpp server on computer. smppsim great project testing. download , run on computer. can configured in multiple ways e.g. request delivery reports smpp server, set sms fail ratio , e.t.c. i've tested smppsim on linux.

java smpp jsmpp

1 comment:

  1. yeah!! SMPP Service have been the most renowned Bulk Messaging technique that is ruling business marketing today. Each organization wills to harness the benefits of SMPP services for communicating with their target audiences.

    ReplyDelete