package com.wondertek.ctmp.protocol.smgp;
import com.wondertek.ctmp.protocol.util.ByteUtil;
public class SMGPSubmitMessage extends SMGPBaseMessage {
public SMGPSubmitMessage() {
this.commandId = SMGPConstants.SMGP_SUBMIT;
}
private byte msgType=(byte)6; // 1
private byte needReport=1; // 1
private byte priority; // 1
private String serviceId=""; // 10
private String feeType="00"; // 2
private String feeCode="000000"; // 6
private String fixedFee="000000"; // 6
private byte msgFmt; // 1
private String validTime=""; // 17
private String atTime=""; // 17
private String srcTermId=""; // 21
private String chargeTermId=""; // 21
private byte destTermIdCount; // 1
private String[] destTermIdArray; // 21*destTermIdCount
private int msgLength; // 1
private String msgContent;
private byte[] bMsgContent; // msgLength
private String reserve=""; // 8
@Override
protected void setBody(byte[] bodyBytes) throws Exception {
int offset = 0;
byte[] tmp = null;
msgType = bodyBytes[offset];
offset += 1;
needReport = bodyBytes[offset];
offset += 1;
priority = bodyBytes[offset];
offset += 1;
tmp = new byte[10];
System.arraycopy(bodyBytes, offset, tmp, 0, 10);
serviceId = new String(ByteUtil.rtrimBytes(tmp));
offset += 10;
tmp = new byte[2];
System.arraycopy(bodyBytes, offset, tmp, 0, 2);
feeType = new String(ByteUtil.rtrimBytes(tmp));
offset += 2;
tmp = new byte[6];
System.arraycopy(bodyBytes, offset, tmp, 0, 6);
feeCode = new String(ByteUtil.rtrimBytes(tmp));
offset += 6;
tmp = new byte[6];
System.arraycopy(bodyBytes, offset, tmp, 0, 6);
fixedFee = new String(ByteUtil.rtrimBytes(tmp));
offset += 6;
msgFmt = bodyBytes[offset];
offset += 1;
tmp = new byte[17];
System.arraycopy(bodyBytes, offset, tmp, 0, 17);
validTime = new String(ByteUtil.rtrimBytes(tmp));
offset += 17;
tmp = new byte[17];
System.arraycopy(bodyBytes, offset, tmp, 0, 17);
atTime = new String(ByteUtil.rtrimBytes(tmp));
offset += 17;
tmp = new byte[21];
System.arraycopy(bodyBytes, offset, tmp, 0, 21);
srcTermId = new String(ByteUtil.rtrimBytes(tmp));
offset += 21;
tmp = new byte[21];
System.arraycopy(bodyBytes, offset, tmp, 0, 21);
chargeTermId = new String(ByteUtil.rtrimBytes(tmp));
offset += 21;
destTermIdCount = bodyBytes[offset];
offset += 1;
if (destTermIdCount >= 100 || destTermIdCount <= 0) {
throw new Exception("destTermIdCount must be in [1,99],but " + destTermIdCount);
}
destTermIdArray = new String[destTermIdCount];
for (int i = 0; i < destTermIdCount; i++) {
tmp = new byte[21];
System.arraycopy(bodyBytes, offset, tmp, 0, 21);
offset += 21;
destTermIdArray[i] = new String(ByteUtil.rtrimBytes(tmp));
}
byte b = bodyBytes[offset];
offset += 1;
msgLength = b >= 0 ? b : (256 + b); // byte 最大只有128,这种处理可以取得129-140的数据
if(msgLength>0){
tmp = new byte[msgLength];
System.arraycopy(bodyBytes, offset, tmp, 0, msgLength);
offset += msgLength;
bMsgContent = tmp;
try {
if (msgFmt == 8)
msgContent = new String(bMsgContent, "iso-10646-ucs-2");
else if (msgFmt == 15)
msgContent = new String(bMsgContent, "gb2312");
else
msgContent = new String(bMsgContent, "iso-8859-1");
msgContent=msgContent.trim();
} catch (Exception ex) {
throw ex;
}
}
tmp = new byte[8];
System.arraycopy(bodyBytes, offset, tmp, 0, 8);
reserve = new String(ByteUtil.rtrimBytes(tmp));
offset += 8;
}
@Override
protected byte[] getBody() throws Exception {
int len =0+1 + 1 + 1 + 10 + 2 + 6 + 6 + 1 + 17 + 17 + 21 + 21 + 1 + 21* destTermIdCount + 1 + msgLength + 8;
int offset = 0;
byte[] bodyBytes = new byte[len];
bodyBytes[offset] = msgType;
offset += 1;
bodyBytes[offset] = needReport;
offset += 1;
bodyBytes[offset] = priority;
offset += 1;
ByteUtil.rfillBytes(serviceId.getBytes(), 10, bodyBytes, offset);
offset += 10;
ByteUtil.rfillBytes(feeType.getBytes(), 2, bodyBytes, offset);
offset += 2;
ByteUtil.rfillBytes(feeCode.getBytes(), 6, bodyBytes, offset);
offset += 6;
ByteUtil.rfillBytes(fixedFee.getBytes(), 6, bodyBytes, offset);
offset += 6;
bodyBytes[offset] = msgFmt;
offset += 1;
ByteUtil.rfillBytes(validTime.getBytes(), 17, bodyBytes, offset);
offset += 17;
ByteUtil.rfillBytes(atTime.getBytes(), 17, bodyBytes, offset);
offset += 17;
ByteUtil.rfillBytes(srcTermId.getBytes(), 21, bodyBytes, offset);
offset += 21;
ByteUtil.rfillBytes(chargeTermId.getBytes(), 21, bodyBytes, offset);
offset += 21;
bodyBytes[offset] = destTermIdCount;
offset += 1;
for (int i = 0; i < destTermIdCount; i++) {
ByteUtil.rfillBytes(destTermIdArray[i].getBytes(), 21,
bodyBytes, offset);
offset += 21;
}
bodyBytes[offset] = (byte)msgLength;
offset += 1;
if (bMsgContent == null && msgContent!=null) {
try {
if (msgFmt == 8)
bMsgContent = msgContent.getBytes("iso-10646-ucs-2");
else if (msgFmt == 15)
bMsgContent = msgContent.getBytes("gb2312");
else
bMsgContent = msgContent.getBytes("iso-8859-1");
} catch (Exception ex) {
}
}
if (bMsgContent != null) {
ByteUtil.rfillBytes(bMsgContent, msgLength, bodyBytes, offset);
}
offset+=msgLength;
ByteUtil.rfillBytes(reserve.getBytes(), 8, bodyBytes, offset);
offset += 8;
return bodyBytes;
}
public byte getMsgType() {
return this.msgType;
}
public void setMsgType(byte msgType) {
this.msgType = msgType;
}
public byte getNeedReport() {
return this.needReport;
}
public void setNeedReport(byte needReport) {
this.needReport = needReport;
}
public byte getPriority() {
return this.priority;
}
public void setPriority(byte priority) {
this.priority = priority;
}
public String getServiceId() {
return this.serviceId;
}
public void setServiceId(String serviceId) {
this.serviceId = serviceId;
}
public String getFeeType() {
return this.feeType;
}
public void setFeeType(String feeType) {
this.feeType = feeType;
}
public String getFeeCode() {
return this.feeCode;
}
public void setFeeCode(String feeCode) {
this.feeCode = feeCode;
}
public String getFixedFee() {
return this.fixedFee;
}
public void setFixedFee(String fixedFee) {
this.fixedFee = fixedFee;
}
public byte getMsgFmt() {
return this.msgFmt;
}
public void setMsgFmt(byte msgFmt) {
this.msgFmt = msgFmt;
}
public String getValidTime() {
return this.validTime;
}
public void setValidTime(String validTime) {
this.validTime = validTime;
}
public String getAtTime() {
return this.atTime;
}
public void setAtTime(String atTime) {
this.atTime = atTime;
}
public String getSrcTermId() {
return this.srcTermId;
}
public void setSrcTermId(String srcTermId) {
this.srcTermId = srcTermId;
}
public String getChargeTermId() {
return this.chargeTermId;
}
public void setChargeTermId(String chargeTermId) {
this.chargeTermId = chargeTermId;
}
public byte getDestTermIdCount() {
return this.destTermIdCount;
}
public void setDestTermIdCount(byte destTermIdCount) {
this.destTermIdCount = destTermIdCount;
}
public String[] getDestTermIdArray() {
return destTermIdArray;
}
public void setDestTermIdArray(String[] destTermIdArray) {
this.destTermIdArray = destTermIdArray;
this.destTermIdCount=(byte)(destTermIdArray==null?0:destTermIdArray.length);
}
public String getMsgContent() {
if(msgContent!=null)
return msgContent;
if(bMsgContent!=null){
String msg=null;
try {
if (msgFmt == 8) {
msg = new S
中国电信SMGP示例程序
5星 · 超过95%的资源 需积分: 24 77 浏览量
2013-09-15
01:15:22
上传
评论
收藏 368KB RAR 举报
xjfxkook
- 粉丝: 0
- 资源: 4
最新资源
- IMG_20240425_120538.jpg
- My Complete Genome_6k Base-Pairs of Phenotype SNPs_Complete Raw Data.zip
- qt 的mqtt测试demo
- 移动应用开发教程-zip.zip
- mosquitto-2.018-install-windows-x64
- FTPServer FTP 服务器,绿色免安装,单文件
- 梦畅语音点名软件,上课点名
- 利用ADNI数据集和标签,在tensorflow框架上使用tensorlayer接口,通过架构u-net实现海马体的分割
- Kutools for Word v9.0 office word 插件
- 修复Windows 10 LTSC 2021资源占用率高
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
前往页