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

📄 outboundmessage.java

📁 发送短信 接收短信 多种接口com/net/modem 开发库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		this.messageStatus = myMessageStatus;
	}

	public FailureCauses getFailureCause()
	{
		return this.failureCause;
	}

	/**
	 * Mark message as failed and set cause of failure.
	 * 
	 * @param myFailureCause
	 *            Cause of failure
	 */
	public void setFailureCause(FailureCauses myFailureCause)
	{
		if (myFailureCause != FailureCauses.NO_ERROR) this.messageStatus = MessageStatuses.FAILED;
		this.failureCause = myFailureCause;
	}

	/**
	 * Return value of internal sending retry counter.
	 * 
	 * @return Number of sending message retries
	 */
	public int getRetryCount()
	{
		return this.retryCount;
	}

	public void setRetryCount(int myRetryCount)
	{
		this.retryCount = myRetryCount;
	}

	void incrementRetryCount()
	{
		this.retryCount++;
	}

	/**
	 * Returns the priority of the message.
	 * 
	 * @return The priority of the message.
	 */
	public int getPriority()
	{
		return this.priority;
	}

	/**
	 * Sets the priority of the message.
	 * 
	 * @param myPriority
	 *            The new priority.
	 */
	public void setPriority(int myPriority)
	{
		this.priority = myPriority;
	}

	/**
	 * Returns the message Reference Number. The Reference Number comes into
	 * existence when the message is sent. Its format depends on the gateway:
	 * For modems, its a number. For bulk sms operators, this is a hex string.
	 * If the message has not been sent yet, the Reference number is blank.
	 * 
	 * @return The message reference number.
	 */
	public String getRefNo()
	{
		return this.refNo;
	}

	public void setRefNo(String myRefNo)
	{
		this.refNo = myRefNo;
	}

	@Override
	public String toString()
	{
		String str = "";
		str += "===============================================================================";
		str += "\n";
		str += "<< " + getClass().getSimpleName() + " >>";
		str += "\n";
		str += "-------------------------------------------------------------------------------";
		str += "\n";
		str += " Gateway Id: " + getGatewayId();
		str += "\n";
		str += " Encoding: " + (getEncoding() == MessageEncodings.ENC7BIT ? "7-bit" : (getEncoding() == MessageEncodings.ENC8BIT ? "8-bit" : "UCS2 (Unicode)"));
		str += "\n";
		str += " Date: " + getDate();
		str += "\n";
		str += " SMSC Ref No: " + getRefNo();
		str += "\n";
		str += " Recipient: " + getRecipient();
		str += "\n";
		str += " Dispatch Date: " + getDispatchDate();
		str += "\n";
		str += " Message Status: " + getMessageStatus();
		str += "\n";
		str += " Validity Period (Hours): " + getValidityPeriod();
		str += "\n";
		str += " Status Report: " + getStatusReport();
		str += "\n";
		str += " Source / Destination Ports: " + getSrcPort() + " / " + getDstPort();
		str += "\n";
		str += " Flash SMS: " + getFlashSms();
		str += "\n";
		if (this instanceof OutboundBinaryMessage)
		{
			OutboundBinaryMessage binaryMessage = (OutboundBinaryMessage) this;
			if (binaryMessage.getDataBytes() != null)
			{
				String binaryString = PduUtils.bytesToPdu((binaryMessage).getDataBytes());
				str += " Binary: " + binaryString;
				str += "\n";
			}
			else
			{
				str += " Binary: null";
				str += "\n";
			}
		}
		else
		{
			str += " Text: " + getText();
			str += "\n";
			try
			{
				str += " PDU data: " + getPduUserData();
				str += "\n";
			}
			catch (Exception e)
			{
				str += " PDU data: <cannot extract properly, udh present>";
				str += "\n";
			}
		}
		str += "===============================================================================";
		str += "\n";
		return str;
	}

	public List<String> getPdus(String smscNumber, int mpRefNo)
	{
		PduGenerator pduGenerator = new PduGenerator();
		SmsSubmitPdu pdu = createPduObject();
		initPduObject(pdu, smscNumber);
		return pduGenerator.generatePduList(pdu, mpRefNo);
	}

	protected SmsSubmitPdu createPduObject()
	{
		// if you want to be able to change some other parts of the first octet
		// do it here
		SmsSubmitPdu pdu;
		if (this.statusReport)
		{
			pdu = PduFactory.newSmsSubmitPdu(PduUtils.TP_SRR_REPORT | PduUtils.TP_VPF_INTEGER);
		}
		else
		{
			pdu = PduFactory.newSmsSubmitPdu();
		}
		return pdu;
	}

	protected void initPduObject(SmsSubmitPdu pdu, String smscNumber)
	{
		if ((getDstPort() > -1) && (getSrcPort() > -1))
		{
			// port info
			pdu.addInformationElement(InformationElementFactory.generatePortInfo(getDstPort(), getSrcPort()));
		}
		// smscInfo
		// address type field + #octets for smscNumber
		// NOTE: make sure the + is not present when computing the smscInfoLength
		String smscNumberForLengthCheck = smscNumber;
		if (smscNumber.startsWith("+"))
		{
			smscNumberForLengthCheck = smscNumber.substring(1);
		}
		pdu.setSmscInfoLength(1 + (smscNumberForLengthCheck.length() / 2) + ((smscNumberForLengthCheck.length() % 2 == 1) ? 1 : 0));
		// set address
		pdu.setSmscAddress(smscNumber);
		// set address type using the address (+ needs to be passed with it, if present)
		pdu.setSmscAddressType(PduUtils.getAddressTypeFor(smscNumber));
		// message reference
		// just use 0 since this is not tracked by the ModemGateway
		pdu.setMessageReference(0);
		// destination address info
		pdu.setAddress(getRecipient());
		// protocol id
		pdu.setProtocolIdentifier(0);
		// data coding scheme
		if (!pdu.isBinary())
		{
			int dcs = 0;
			if (getEncoding() == MessageEncodings.ENC7BIT)
			{
				dcs = PduUtils.DCS_ENCODING_7BIT;
			}
			else if (getEncoding() == MessageEncodings.ENC8BIT)
			{
				dcs = PduUtils.DCS_ENCODING_8BIT;
			}
			else if (getEncoding() == MessageEncodings.ENCUCS2)
			{
				dcs = PduUtils.DCS_ENCODING_UCS2;
			}
			else if (getEncoding() == MessageEncodings.ENCCUSTOM)
			{
				// just use this
				dcs = PduUtils.DCS_ENCODING_7BIT;
			}
			if (getDCSMessageClass() == MessageClasses.MSGCLASS_FLASH)
			{
				dcs = dcs | PduUtils.DCS_MESSAGE_CLASS_FLASH;
			}
			else if (getDCSMessageClass() == MessageClasses.MSGCLASS_ME)
			{
				dcs = dcs | PduUtils.DCS_MESSAGE_CLASS_ME;
			}
			else if (getDCSMessageClass() == MessageClasses.MSGCLASS_SIM)
			{
				dcs = dcs | PduUtils.DCS_MESSAGE_CLASS_SIM;
			}
			else if (getDCSMessageClass() == MessageClasses.MSGCLASS_TE)
			{
				dcs = dcs | PduUtils.DCS_MESSAGE_CLASS_TE;
			}
			pdu.setDataCodingScheme(dcs);
		}
		// validity period
		pdu.setValidityPeriod(this.validityPeriod);
		// add payload
		setPduPayload(pdu);
	}

	protected void setPduPayload(SmsSubmitPdu pdu)
	{
		pdu.setDecodedText(getText());
	}

	@Override
	public String getPduUserData()
	{
		// generate
		PduGenerator pduGenerator = new PduGenerator();
		SmsSubmitPdu pdu = createPduObject();
		initPduObject(pdu, "");
		// NOTE: - the mpRefNo is arbitrarily set to 1
		// - this won't matter since we aren't looking at the UDH in this method
		// - this method is not allowed for 7-bit messages with UDH
		// since it is probable that the returned value will not be
		// correct due to the encoding's dependence on the UDH
		// - if the user wishes to extract the UD per part, he would need to get all pduStrings
		// using getPdus(String smscNumber, int mpRefNo), use a
		// PduParser on each pduString in the returned list, then access the UD via the Pdu object
		List<String> pdus = pduGenerator.generatePduList(pdu, 1);
		// my this point, pdu will be updated with concat info (in udhi), if present
		if ((pdu.hasTpUdhi()) && (getEncoding() == MessageEncodings.ENC7BIT)) { throw new RuntimeException("getPduUserData() not supported for 7-bit messages with UDH"); }
		// sum up the ud parts
		StringBuffer ud = new StringBuffer();
		for (String pduString : pdus)
		{
			Pdu newPdu = new PduParser().parsePdu(pduString);
			ud.append(PduUtils.bytesToPdu(newPdu.getUserDataAsBytes()));
		}
		return ud.toString();
	}

	@Override
	public String getPduUserDataHeader()
	{
		// generate
		PduGenerator pduGenerator = new PduGenerator();
		SmsSubmitPdu pdu = createPduObject();
		initPduObject(pdu, "");
		// NOTE: - the mpRefNo is arbitrarily set to 1
		// - if the user wishes to extract the UDH per part, he would need to get all pduStrings
		// using getPdus(String smscNumber, int mpRefNo), use a
		// PduParser on each pduString in the returned list, then access the UDH via the Pdu object
		List<String> pdus = pduGenerator.generatePduList(pdu, 1);
		Pdu newPdu = new PduParser().parsePdu(pdus.get(0));
		byte[] udh = newPdu.getUDHData();
		if (udh != null) return PduUtils.bytesToPdu(udh);
		return null;
	}

	@Override
	public void setEncoding(MessageEncodings encoding)
	{
		if (encoding == MessageEncodings.ENC8BIT)
		{
			if (this instanceof OutboundBinaryMessage) super.setEncoding(encoding);
			else throw new RuntimeException("Cannot use 8-bit encoding with OutgoingMessage, use OutgoingBinaryMessage instead");
		}
		else
		{
			// 7-bit / ucs2
			super.setEncoding(encoding);
		}
	}

	protected void copyTo(OutboundMessage msg)
	{
		super.copyTo(msg);
		msg.setRecipient(getRecipient());
		msg.setDispatchDate(getDispatchDate());
		msg.setValidityPeriod(getValidityPeriod());
		msg.setStatusReport(getStatusReport());
		msg.setFlashSms(getFlashSms());
		msg.setFrom(getFrom());
		msg.setMessageStatus(getMessageStatus());
		msg.setFailureCause(getFailureCause());
		msg.retryCount = getRetryCount();
		msg.setPriority(getPriority());
		msg.setRefNo(getRefNo());
	}
}

⌨️ 快捷键说明

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