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

📄 outboundmessage.java

📁 发送短信 接收短信 多种接口com/net/modem 开发库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// SMSLib for Java v3
// A Java API library for sending and receiving SMS via a GSM modem
// or other supported gateways.
// Web Site: http://www.smslib.org
//
// Copyright (C) 2002-2009, Thanasis Delenikas, Athens/GREECE.
// SMSLib is distributed under the terms of the Apache License version 2.0
//
// 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.smslib;

import java.util.*;
import org.ajwcc.pduUtils.gsm3040.*;
import org.ajwcc.pduUtils.gsm3040.ie.*;

/**
 * Class representing an outbound sms message.
 */
public class OutboundMessage extends Message
{
	private static final long serialVersionUID = 6449191177648891554L;

	/**
	 * Enumeration representing the failure reasons of a failed outbound
	 * message.
	 */
	public enum FailureCauses
	{
		/**
		 * No error, everything OK.
		 */
		NO_ERROR,
		/**
		 * Bad destination number - fatal error.
		 */
		BAD_NUMBER,
		/**
		 * Bad message format - fatal error.
		 */
		BAD_FORMAT,
		/**
		 * Generic gateway failure - transient error, retry later.
		 */
		GATEWAY_FAILURE,
		/**
		 * No credit left - fatal error.
		 */
		NO_CREDIT,
		/**
		 * Authentication problem (pin, passwords, etc) - fatal error.
		 */
		GATEWAY_AUTH,
		/**
		 * Unable to route message - transient error.
		 */
		NO_ROUTE,
		/**
		 * Unknown generic problems encountered.
		 */
		UNKNOWN
	}

	/**
	 * Class representing the status of an outbound message.
	 */
	public enum MessageStatuses
	{
		/**
		 * A not-yet-sent outbound message.
		 */
		UNSENT,
		/**
		 * An already-sent outbound message.
		 */
		SENT,
		/**
		 * A sent-but-failed outbound message.
		 */
		FAILED
	}

	protected String recipient;

	private Date dispatchDate;

	private int validityPeriod;

	private boolean statusReport;

	private String from;

	private MessageStatuses messageStatus;

	private FailureCauses failureCause;

	private int retryCount;

	private int priority;

	private String refNo;

	/**
	 * Outbound message constructor. This parameterless constructor creates an
	 * empty outbound message.
	 * 
	 * @see #OutboundMessage(String, String)
	 */
	public OutboundMessage()
	{
		super(MessageTypes.OUTBOUND, null, null);
		setRecipient("");
		setValidityPeriod(-1);
		setStatusReport(false);
		setDCSMessageClass(MessageClasses.MSGCLASS_NONE);
		setFrom("");
		setDispatchDate(null);
		setDate(new Date());
		setEncoding(MessageEncodings.ENC7BIT);
		setMessageStatus(MessageStatuses.UNSENT);
		setFailureCause(FailureCauses.NO_ERROR);
		setPriority(0);
		setRefNo("");
		setGatewayId("*");
		setRetryCount(0);
	}

	/**
	 * Outbound message constructor.
	 * 
	 * @param myRecipient
	 *            The recipient of the message.
	 * @param text
	 *            The text of the message.
	 */
	public OutboundMessage(String myRecipient, String text)
	{
		super(MessageTypes.OUTBOUND, new Date(), text);
		setRecipient(myRecipient);
		setValidityPeriod(-1);
		setStatusReport(false);
		setDCSMessageClass(MessageClasses.MSGCLASS_NONE);
		setFrom("");
		setDispatchDate(null);
		setDate(new Date());
		setEncoding(MessageEncodings.ENC7BIT);
		setMessageStatus(MessageStatuses.UNSENT);
		setFailureCause(FailureCauses.NO_ERROR);
		setPriority(0);
		setRefNo("");
		setGatewayId("*");
		setRetryCount(0);
	}

	/**
	 * Returns the recipient of this outbound message.
	 * 
	 * @return The recipient of the message.
	 * @see #setRecipient(String)
	 */
	public String getRecipient()
	{
		return this.recipient;
	}

	/**
	 * Set the recipient of the message.
	 * 
	 * @param myRecipient
	 *            The recipient of the message.
	 * @see #getRecipient()
	 */
	public void setRecipient(String myRecipient)
	{
		this.recipient = myRecipient;
	}

	/**
	 * Returns the dispatch date of this message. If the message has not been
	 * sent yet, the dispatch date is null.
	 * 
	 * @return The message dispatch date.
	 */
	public Date getDispatchDate()
	{
		if (this.dispatchDate != null) return new java.util.Date(this.dispatchDate.getTime());
		return null;
	}

	public void setDispatchDate(Date myDispatchDate)
	{
		this.dispatchDate = myDispatchDate;
	}

	/**
	 * Returns true if this message is to be sent out as a flash SMS. Otherwise,
	 * it returns false.
	 * 
	 * @return True for a Flash message.
	 * @see #setFlashSms(boolean)
	 */
	public boolean getFlashSms()
	{
		if (getDCSMessageClass() == MessageClasses.MSGCLASS_FLASH) return true;
		return false;
	}

	/**
	 * Set the flash message indication. Set this to true for this message to be
	 * sent as a flash message. Flash messages appear directly on the handset,
	 * so use this feature with care, because it may be a bit annoying.
	 * Furthermore, keep in mind that flash messaging is not supported on all
	 * phones.
	 * <p>
	 * The default is non-flash (false).
	 * 
	 * @param flashSms
	 *            True for a flash sms.
	 */
	public void setFlashSms(boolean flashSms)
	{
		if (flashSms) setDCSMessageClass(MessageClasses.MSGCLASS_FLASH);
		else setDCSMessageClass(MessageClasses.MSGCLASS_NONE);
	}

	/**
	 * Returns true if a status/delivery report will be asked for this message.
	 * 
	 * @return True if a status report will be generated.
	 */
	public boolean getStatusReport()
	{
		return this.statusReport;
	}

	/**
	 * Sets the status report request. If you set it to true, a status report
	 * message will be generated, otherwise no status report message will be
	 * generated.
	 * <p>
	 * The default is (false).
	 * 
	 * @param myStatusReport
	 *            The status report request status.
	 */
	public void setStatusReport(boolean myStatusReport)
	{
		this.statusReport = myStatusReport;
	}

	/**
	 * Returns the message validity period (in hours).
	 * 
	 * @return The message validity period.
	 * @see #setValidityPeriod(int)
	 */
	public int getValidityPeriod()
	{
		return this.validityPeriod;
	}

	/**
	 * Sets the message validity period.
	 * 
	 * @param myValidityPeriod
	 *            The message validity period in hours.
	 * @see #getValidityPeriod()
	 */
	public void setValidityPeriod(int myValidityPeriod)
	{
		this.validityPeriod = myValidityPeriod;
	}

	/**
	 * Receives the custom originator string. Set it to empty string to leave
	 * the default behavior.
	 * 
	 * @return The custom originator string.
	 * @see #setFrom(String)
	 */
	public String getFrom()
	{
		return this.from;
	}

	/**
	 * Sets the custom originator string. Some gateways allow you to define a
	 * custom string as the originator. When the message arrives at the
	 * recipient, the latter will not see your number but this string.
	 * <p>
	 * Note that this functionality is not supported on GSM modems / phones. It
	 * is supported on most bulk sms operators.
	 * 
	 * @param myFrom
	 *            The custom originator string.
	 * @see #getFrom()
	 */
	public void setFrom(String myFrom)
	{
		this.from = myFrom;
	}

	/**
	 * Returns the message status.
	 * 
	 * @return The message status.
	 * @see MessageStatuses
	 */
	public MessageStatuses getMessageStatus()
	{
		return this.messageStatus;
	}

	public void setMessageStatus(MessageStatuses myMessageStatus)
	{

⌨️ 快捷键说明

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