CMPP

public void sendSubmitMessage(CmppSubmit submit) {
MessageRunBean msgBean = MessageRunBean.getInstance();
try {
String message = submit.getMsg_Content();
byte[] msgUCS2 = message.getBytes("UnicodeBigUnmarked");
int msgUCS2Len = msgUCS2.length;// 长短信长度
int maxMsgLen = 140;
int msgLen = maxMsgLen - 6;
if (msgUCS2Len > (msgLen - 12)) {// 长短信发送
submit.setTP_udhi((byte) 0x01);
int msgUCS2Count = msgUCS2Len / msgLen + 1;// 长短信分为多少条发送
int endLen = msgUCS2Len - (msgUCS2Count - 1) * msgLen;
boolean isEnd = endLen > (msgLen - 12) && endLen < msgLen;
if (isEnd) {
msgUCS2Count = msgUCS2Count + 1;
} else {
isEnd = msgUCS2Len % msgLen == 0;
}
byte[] tp_udhiHead = new byte[6];
tp_udhiHead[0] = 0x05;
tp_udhiHead[1] = 0x00;
tp_udhiHead[2] = 0x03;
tp_udhiHead[3] = 0x0A;
tp_udhiHead[4] = (byte) msgUCS2Count;
tp_udhiHead[5] = 0x01;// 默认为第一条
for (int i = 0; i < msgUCS2Count; i++) {
tp_udhiHead[5] = (byte) (i + 1);
byte[] msgContent;
int start = i * msgLen;
int end = (i + 1) * msgLen;
if (!isEnd) {// 当最后一条的消息长度小于128时(msgLen-12):
// 在最后一条移动会加上‘【金泽物流】’字样,会挤掉一些文字。
if (i != msgUCS2Count - 1) {// 不为最后一条
msgContent = CMPPUtilits.byteAdd(tp_udhiHead,
msgUCS2, start, end);
} else {// 最后一条
msgContent = CMPPUtilits.byteAdd(tp_udhiHead,
msgUCS2, start, msgUCS2Len);
}
} else {// 当最后一条的消息长度大於128时(msgLen - 12),再分解.
if (i != msgUCS2Count - 2 && i != msgUCS2Count - 1) {// 不为最后两条时
msgContent = CMPPUtilits.byteAdd(tp_udhiHead,
msgUCS2, start, end);
} else if (i == msgUCS2Count - 2) {// 倒数第二条时
end = i * msgLen + (msgLen - 12);
msgContent = CMPPUtilits.byteAdd(tp_udhiHead,
msgUCS2, start, end);
} else {
// 最后一条
start = (i - 1) * msgLen + (msgLen - 12);
msgContent = CMPPUtilits.byteAdd(tp_udhiHead,
msgUCS2, start, msgUCS2Len);
}
}
submit.setMsgContent(msgContent);
submit.setMsg_Length((byte) msgContent.length);
submit.setTotal_Length(submit.getSubmitPackLen());
logger.info(isEnd + " tp_udhiHead:" + tp_udhiHead[5]
+ " start:" + start + " end:" + end
+ " end-start+6:" + (end - start + 6) + " MSGLen:"
+ msgContent.length + "  totalLen:"
+ submit.getTotal_Length());
sendMsg(submit);
}
} else {
submit.setMsgContent(msgUCS2);
submit.setMsg_Length((byte) msgUCS2Len);
submit.setTotal_Length(submit.getSubmitPackLen());
sendMsg(submit);
}
} catch (Exception e) {
logger.error(e);
msgBean.setException(e);
}
}

你可能感兴趣的:(物流)