본문
SMPP(Short Message Peer-to-Peer)(JAVA)
# SMPP(Short Message Peer-to-Peer)
Applications that send short messages (SMS), using SMPP protocol, can communicate with SMS center (SMSC) and deliver messages very fast. Also, can receive asynchronously, delivery reports for each message, so you can know the status for each SMS you send, automatically.
1. https://en.wikipedia.org/wiki/Short_Message_Peer-to-Peer
2. http://www.inviosmart.it/en/messaging-services/send-sms-smpp-gateway-multiple-bulk-messages
(image : http://www.inviosmart.it/en/messaging-services/send-sms-smpp-gateway-multiple-bulk-messages)
# jsmpp API
http://grepcode.com/file/repo1.maven.org/maven2/com.googlecode.jsmpp/jsmpp/2.1.0/org/jsmpp
# jsmpp example source code for java
# Configuring SMPP
https://www.watchguard.com/help/docs/ssl/2/en-US/Content/FAQs/configure_smpp_faq.html
sample source)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | /* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package org.jsmpp.examples; import java.io.IOException; import java.util.Date; import org.apache.log4j.BasicConfigurator; import org.jsmpp.InvalidResponseException; import org.jsmpp.PDUException; import org.jsmpp.bean.AlertNotification; import org.jsmpp.bean.Alphabet; import org.jsmpp.bean.BindType; import org.jsmpp.bean.DataSm; import org.jsmpp.bean.DeliverSm; import org.jsmpp.bean.DeliveryReceipt; import org.jsmpp.bean.ESMClass; import org.jsmpp.bean.GeneralDataCoding; import org.jsmpp.bean.MessageClass; import org.jsmpp.bean.MessageType; import org.jsmpp.bean.NumberingPlanIndicator; import org.jsmpp.bean.RegisteredDelivery; import org.jsmpp.bean.SMSCDeliveryReceipt; import org.jsmpp.bean.TypeOfNumber; import org.jsmpp.extra.NegativeResponseException; import org.jsmpp.extra.ProcessRequestException; import org.jsmpp.extra.ResponseTimeoutException; import org.jsmpp.session.BindParameter; import org.jsmpp.session.DataSmResult; import org.jsmpp.session.MessageReceiverListener; import org.jsmpp.session.SMPPSession; import org.jsmpp.session.Session; import org.jsmpp.util.AbsoluteTimeFormatter; import org.jsmpp.util.InvalidDeliveryReceiptException; import org.jsmpp.util.TimeFormatter; /** * @author terukizm * */ public class SimpleSubmitSimpleReceiveExample { private static TimeFormatter timeFormatter = new AbsoluteTimeFormatter();; public static void main(String[] args) { String server = "localhost"; int port = 8056; String message = "jSMPP simplify SMPP on Java platform"; // bind(connect) SMPPSession session = new SMPPSession(); try { session.connectAndBind(server, port, new BindParameter(BindType.BIND_TRX, "test", "test", "cp", TypeOfNumber.UNKNOWN, NumberingPlanIndicator.UNKNOWN, null)); } catch (IOException e) { System.err.println("Failed connect and bind to host"); e.printStackTrace(); } // send Message try { // set RegisteredDelivery final RegisteredDelivery registeredDelivery = new RegisteredDelivery(); registeredDelivery.setSMSCDeliveryReceipt(SMSCDeliveryReceipt.SUCCESS_FAILURE); String messageId = session.submitShortMessage("CMT", TypeOfNumber.INTERNATIONAL, NumberingPlanIndicator.UNKNOWN, "1616", TypeOfNumber.INTERNATIONAL, NumberingPlanIndicator.UNKNOWN, "628176504657", new ESMClass(), (byte)0, (byte)1, timeFormatter.format(new Date()), null, registeredDelivery, (byte)0, new GeneralDataCoding(Alphabet.ALPHA_DEFAULT, MessageClass.CLASS1, false), (byte)0, message.getBytes()); System.out.println("Message submitted, message_id is " + messageId); } catch (PDUException e) { // Invalid PDU parameter System.err.println("Invalid PDU parameter"); e.printStackTrace(); } catch (ResponseTimeoutException e) { // Response timeout System.err.println("Response timeout"); e.printStackTrace(); } catch (InvalidResponseException e) { // Invalid response System.err.println("Receive invalid respose"); e.printStackTrace(); } catch (NegativeResponseException e) { // Receiving negative response (non-zero command_status) System.err.println("Receive negative response"); e.printStackTrace(); } catch (IOException e) { System.err.println("IO error occur"); e.printStackTrace(); } // receive Message BasicConfigurator.configure(); // Set listener to receive deliver_sm session.setMessageReceiverListener(new MessageReceiverListener() { public void onAcceptDeliverSm(DeliverSm deliverSm) throws ProcessRequestException { if (MessageType.SMSC_DEL_RECEIPT.containedIn(deliverSm.getEsmClass())) { // delivery receipt try { DeliveryReceipt delReceipt = deliverSm.getShortMessageAsDeliveryReceipt(); long id = Long.parseLong(delReceipt.getId()) & 0xffffffff; String messageId = Long.toString(id, 16).toUpperCase(); System.out.println("received '" + messageId + "' : " + delReceipt); } catch (InvalidDeliveryReceiptException e) { System.err.println("receive faild"); e.printStackTrace(); } } else { // regular short message System.out.println("Receiving message : " + new String(deliverSm.getShortMessage())); } } public void onAcceptAlertNotification(AlertNotification alertNotification) { System.out.println("onAcceptAlertNotification"); } public DataSmResult onAcceptDataSm(DataSm dataSm, Session source) throws ProcessRequestException { System.out.println("onAcceptDataSm"); return null; } }); // wait 3 second try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } // unbind(disconnect) session.unbindAndClose(); System.out.println("finish!"); } } | cs |
댓글