⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smpppacket.java

📁 SMPP(点到点短消息协议)的java实现
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package ie.omk.smpp.message;import ie.omk.smpp.Address;import ie.omk.smpp.message.tlv.TLVTable;import ie.omk.smpp.message.tlv.Tag;import ie.omk.smpp.util.AlphabetEncoding;import ie.omk.smpp.util.BinaryEncoding;import ie.omk.smpp.util.EncodingFactory;import ie.omk.smpp.util.MessageEncoding;import ie.omk.smpp.util.SMPPDate;import ie.omk.smpp.util.SMPPIO;import ie.omk.smpp.version.SMPPVersion;import java.io.OutputStream;import java.util.Date;/** * This is the abstract class that all SMPP messages are inherited from. *  * @author Oran Kelly * @version 1.0 */public abstract class SMPPPacket {    /** Command Id: Negative Acknowledgement */    public static final int GENERIC_NACK = 0x80000000;    /** Command Id: Bind Receiver */    public static final int BIND_RECEIVER = 0x00000001;    /** Command Id: Bind Receiver Response */    public static final int BIND_RECEIVER_RESP = 0x80000001;    /** Command Id: Bind transmitter */    public static final int BIND_TRANSMITTER = 0x00000002;    /** Command Id: Bind transmitter response */    public static final int BIND_TRANSMITTER_RESP = 0x80000002;    /** Command Id: Query message */    public static final int QUERY_SM = 0x00000003;    /** Command Id: Query message response */    public static final int QUERY_SM_RESP = 0x80000003;    /** Command Id: Submit message */    public static final int SUBMIT_SM = 0x00000004;    /** Command Id: Submit message response */    public static final int SUBMIT_SM_RESP = 0x80000004;    /** Command Id: Deliver Short message */    public static final int DELIVER_SM = 0x00000005;    /** Command Id: Deliver message response */    public static final int DELIVER_SM_RESP = 0x80000005;    /** Command Id: Unbind */    public static final int UNBIND = 0x00000006;    /** Command Id: Unbind response */    public static final int UNBIND_RESP = 0x80000006;    /** Command Id: Replace message */    public static final int REPLACE_SM = 0x00000007;    /** Command Id: replace message response */    public static final int REPLACE_SM_RESP = 0x80000007;    /** Command Id: Cancel message */    public static final int CANCEL_SM = 0x00000008;    /** Command Id: Cancel message response */    public static final int CANCEL_SM_RESP = 0x80000008;    /** Command Id: Bind transceiver */    public static final int BIND_TRANSCEIVER = 0x00000009;    /** Command Id: Bind transceiever response. */    public static final int BIND_TRANSCEIVER_RESP = 0x80000009;    /** Command Id: Outbind. */    public static final int OUTBIND = 0x0000000b;    /** Command Id: Enquire Link */    public static final int ENQUIRE_LINK = 0x00000015;    /** Command Id: Enquire link respinse */    public static final int ENQUIRE_LINK_RESP = 0x80000015;    /** Command Id: Submit multiple messages */    public static final int SUBMIT_MULTI = 0x00000021;    /** Command Id: Submit multi response */    public static final int SUBMIT_MULTI_RESP = 0x80000021;    /** Command Id: Parameter retrieve */    public static final int PARAM_RETRIEVE = 0x00000022;    /** Command Id: Paramater retrieve response */    public static final int PARAM_RETRIEVE_RESP = 0x80000022;    /** Command Id: Query last messages */    public static final int QUERY_LAST_MSGS = 0x00000023;    /** Command Id: Query last messages response */    public static final int QUERY_LAST_MSGS_RESP = 0x80000023;    /** Command Id: Query message details */    public static final int QUERY_MSG_DETAILS = 0x00000024;    /** Command Id: Query message details response */    public static final int QUERY_MSG_DETAILS_RESP = 0x80000024;    /** Command Id: alert notification. */    public static final int ALERT_NOTIFICATION = 0x00000102;    /** Command Id: Data message. */    public static final int DATA_SM = 0x00000103;    /** Command Id: Data message response. */    public static final int DATA_SM_RESP = 0x80000103;    /** Message state at Smsc: En route */    public static final int SM_STATE_EN_ROUTE = 1;    /** Message state at Smsc: Delivered (final) */    public static final int SM_STATE_DELIVERED = 2;    /** Message state at Smsc: Expired (final) */    public static final int SM_STATE_EXPIRED = 3;    /** Message state at Smsc: Deleted (final) */    public static final int SM_STATE_DELETED = 4;    /** Message state at Smsc: Undeliverable (final) */    public static final int SM_STATE_UNDELIVERABLE = 5;    /** Message state at Smsc: Accepted */    public static final int SM_STATE_ACCEPTED = 6;    /** Message state at Smsc: Invalid message (final) */    public static final int SM_STATE_INVALID = 7;    /** Esm class: Mobile Terminated; Normal delivery, no address swapping */    public static final int SMC_MT = 1;    /** Esm class: Mobile originated */    public static final int SMC_MO = 2;    /** Esm class: Mobile Originated / Terminated */    public static final int SMC_MOMT = 3;    /** Esm class: Delivery receipt, no address swapping */    public static final int SMC_RECEIPT = 4;    /** Esm class: Predefined message */    public static final int SMC_DEFMSG = 8;    /** Esm class: Normal delivery , address swapping on */    public static final int SMC_LOOPBACK_RECEIPT = 16;    /** Esm class: Delivery receipt, address swapping on */    public static final int SMC_RECEIPT_SWAP = 20;    /** Esm class: Store message, do not send to Kernel */    public static final int SMC_STORE = 32;    /** Esm class: Store message and send to kernel */    public static final int SMC_STORE_FORWARD = 36;    /** Esm class: Distribution submission */    public static final int SMC_DLIST = 64;    /** Esm class: Multiple recipient submission */    public static final int SMC_MULTI = 128;    /** Esm class: Distribution list and multiple recipient submission */    public static final int SMC_CAS_DL = 256;    /** Esm class: Escalated message FFU */    public static final int SMC_ESCALATED = 512;    /** Esm class: Submit with replace message */    public static final int SMC_SUBMIT_REPLACE = 1024;    /** Esm class: Memory capacity error */    public static final int SMC_MCE = 2048;    /** Esme error code: No error */    public static final int ESME_ROK = 0;    /**     * Version of this packet. This object controls valid settings for field     * values.     */    protected SMPPVersion version = SMPPVersion.getDefaultVersion();    /** Command ID. */    protected int commandId;    /** Command status. */    protected int commandStatus;    /** Packet sequence number. */    protected int sequenceNum;    /*     * Almost all packets use one or more of these. These attributes were all     * stuck in here for easier maintenance... instead of altering 5 different     * packets, just alter it here!! Special cases like SubmitMulti and     * QueryMsgDetailsResp maintain their own destination tables. Any packets     * that wish to use these attribs should override the appropriate methods     * defined below to be public and just call super.method()     */    /** Source address */    protected Address source;    /** Destination address */    protected Address destination;    /** The short message data */    protected byte[] message;    /** Service type for this msg */    protected String serviceType;    /** Scheduled delivery time */    protected SMPPDate deliveryTime;    /** Scheduled expiry time */    protected SMPPDate expiryTime;    /** Date of reaching final state */    protected SMPPDate finalDate;    /** Smsc allocated message Id */    protected String messageId;    /** Status of message */    protected int messageStatus;    /** Error associated with message */    protected int errorCode;    /** Message priority. */    protected int priority;    /** Registered delivery. */    protected int registered;    /** Replace if present. */    protected int replaceIfPresent;    /** ESM class. */    protected int esmClass;    /** GSM protocol ID. */    protected int protocolID;    /** Alphabet to use to encode this message's text. */    private MessageEncoding encoding = EncodingFactory.getInstance().getDefaultAlphabet();    /** GSM data coding (see GSM 03.38). */    protected int dataCoding = encoding.getDataCoding();    /** Default message number. */    protected int defaultMsg;    /** Optional parameter table. */    protected TLVTable tlvTable = new TLVTable();    /**     * Create a new SMPPPacket with specified Id.     *      * @param id     *            Command Id value     */    protected SMPPPacket(int id) {        this(id, 0);    }    /**     * Create a new SMPPPacket with specified Id and sequence number.     *      * @param id     *            Command Id value     * @param seqNum     *            Command Sequence number     */    protected SMPPPacket(int id, int seqNum) {        this.commandId = id;        this.sequenceNum = seqNum;    }    protected SMPPPacket(int id, SMPPVersion version) {        this.commandId = id;        this.version = version;    }    protected SMPPPacket(int id, int seqNum, SMPPVersion version) {        this.commandId = id;        this.sequenceNum = seqNum;        this.version = version;    }    /**     * Get the version handler in use for this packet.     *      * @see ie.omk.smpp.version.SMPPVersion     */    public SMPPVersion getVersion() {        return version;    }    /**     * Is this command a request packet.     * @return <code>true</code> if this packet is an SMPP request, <code>     * false</code> if it is a response.     */    public boolean isRequest() {        return false;    }        /**     * Set the version handler for this packet. If <code>null</code> is passed     * in as the version, the default version will be used.     *      * @param version     *            the version handler to use.     * @see ie.omk.smpp.version.SMPPVersion#getDefaultVersion     */    public void setVersion(SMPPVersion version) {        if (version == null) {            this.version = SMPPVersion.getDefaultVersion();        } else {            this.version = version;        }    }    /**     * Return the number of bytes this packet would be encoded as to an     * OutputStream.     *      * @return The size in bytes of the packet     * @deprecated     */    public final int getCommandLen() {        // TODO stop overriding this deprecated method.        return getLength();    }    /**     * Get the number of bytes this packet would be encoded as. This returns the     * sum of the size of the header (always 16), the packet's body and all     * optional parameters.     *      * @return the number of bytes this packet would encode as.     */    public final int getLength() {        return 16 + getBodyLength() + tlvTable.getLength();    }    /**     * Get the number of bytes the body of this packet would encode as. This     * method should only return the number of bytes the fields in the mandatory     * parameters section of the packet would encode as. The total size of the     * packet then is 16 (header length) + getBodyLength() + SUM(foreach     * optionalParameter: getLength()).     */    public abstract int getBodyLength();    /**     * Get the Command Id of this SMPP packet.     *      * @return The Command Id of this packet     */    public int getCommandId() {        return commandId;    }    /**     * Get the status of this packet.     *      * @return The error status of this packet (only relevent to Response     *         packets)     */    public int getCommandStatus() {        return this.commandStatus;    }    /**     * Get the sequence number of this packet.     *      * @return The sequence number of this SMPP packet     */    public int getSequenceNum() {        return this.sequenceNum;    }    /**     * Set the sequence number of this packet.     */    public void setSequenceNum(int sequenceNum) {        this.sequenceNum = sequenceNum;    }    /**     * Set the source address..     */    public void setSource(Address s) throws InvalidParameterValueException {        if (s != null) {            if (version.validateAddress(s)) {                this.source = s;            } else {                throw new InvalidParameterValueException("Bad source address.",                        s);            }        } else {            this.source = null;        }    }    /**     * Get the source address.     * @return The source address or null if it is not set.     */    public Address getSource() {        return source;    }    /**     * Set the destination address.     */    public void setDestination(Address s) {        if (s != null) {            if (version.validateAddress(s)) {                this.destination = s;            } else {                throw new InvalidParameterValueException(                        "Bad destination address.", s);            }        } else {            this.destination = null;        }    }    /**     * Get the destination address.     * @return The destination address or null if it is not set.     */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -