?? sendsmspacket.java
字號:
/*
* LumaQQ - Java QQ Client
*
* Copyright (C) 2004 luma <stubma@163.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package edu.tsinghua.lumaqq.qq.packets.out;
import java.nio.ByteBuffer;
import edu.tsinghua.lumaqq.qq.PacketParseException;
import edu.tsinghua.lumaqq.qq.QQ;
import edu.tsinghua.lumaqq.qq.Utils;
import edu.tsinghua.lumaqq.qq.packets.OutPacket;
/**
* <pre>
* 發送短消息的請求包,格式為:
* 1. 包頭
* 2. 消息序號,從0開始,用在拆分發送中
* 3. 未知2字節,全0
* 4. 未知4字節,全0
* 5. 發送者昵稱,最長13個字節,如果不足,則后面為0
* 6. 分隔符,1字節,0x01
* 7. 如果是免提短信,0x20,其他情況,0x00
* 8. 短消息內容類型,1字節
* 9. 短消息內容類型編號,4字節
* 10. 分隔符,1字節,0x01
* 11. 未知的1字節,一般是0x00
* 12. 分隔符,1字節,0x01
* 13. 接受者QQ號,4字節
* 14. 未知1字節,為0x03
* 15. 短消息字節長度,2字節,QQ的短信和發送者昵稱加起來不能超過58個字符(英文和漢字都算是一個字符,
* 但是漢字是兩個字節,要分清楚了),如果不是普通短消息,則為0x0000
* 16. 短消息字節數組,消息的格式如下:
* 如果是普通的消息,則就是平常的字節數組而已
* 如果有些字符有閃爍,則那些字節要用0x01括起來
* 如果這條消息是一條長消息拆分而成的部分,則在消息字節數組前面要加4個字節,這4個字節分別是
* [消息序號的字符串形式,從1開始] [0x2F] [總消息條數的字符串形式] [0x0A]
* 17. 尾部
* </pre>
*
* 調用這個包時,message的內容必須是已經組裝好的
*
* @author 馬若劼
*/
public class SendSMSPacket extends OutPacket {
private static final byte DELIMIT = 0x01;
private char messageSequence;
private byte[] message;
private byte contentType;
private int contentId;
private byte sendMode;
private String senderName;
private int receiver;
/**
* 創建SendSMSPacket
*/
public SendSMSPacket() {
super(QQ.QQ_CMD_SEND_SMS, true);
messageSequence = 0;
contentType = QQ.QQ_SMS_CONTENT_NORMAL;
contentId = 0;
sendMode = QQ.QQ_SMS_NORMAL;
}
/**
* @param buf
* @param length
* @throws PacketParseException
*/
public SendSMSPacket(ByteBuffer buf, int length)
throws PacketParseException {
super(buf, length);
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.qq.packets.OutPacket#parseBody(java.nio.ByteBuffer)
*/
protected void parseBody(ByteBuffer buf) throws PacketParseException {
messageSequence = buf.getChar();
buf.getChar();
buf.getInt();
senderName = Utils.getString(buf, (byte)0, QQ.QQ_SMS_SENDER_NAME_MAX_LENGTH);
buf.get();
sendMode = buf.get();
contentType = buf.get();
contentId = buf.getInt();
buf.get();
buf.get();
buf.get();
receiver = buf.getInt();
buf.get();
message = new byte[buf.getChar()];
buf.get(message);
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.qq.packets.OutPacket#putBody(java.nio.ByteBuffer)
*/
protected void putBody(ByteBuffer buf) {
// 短消息序號
buf.putChar(messageSequence);
// 未知2字節
buf.putChar((char)0);
// 未知4字節
buf.putInt(0);
// 發送者昵稱
byte[] b = senderName.getBytes();
if(b.length > QQ.QQ_SMS_SENDER_NAME_MAX_LENGTH) {
buf.put(b, 0, QQ.QQ_SMS_SENDER_NAME_MAX_LENGTH);
} else {
buf.put(b);
int stuff = QQ.QQ_SMS_SENDER_NAME_MAX_LENGTH - b.length;
while(stuff-- > 0)
buf.put((byte)0);
}
// 分隔符
buf.put(DELIMIT);
// 發送模式
buf.put(sendMode);
// 內容類型
buf.put(contentType);
// 內容編號
buf.putInt(contentId);
// 分隔符
buf.put(DELIMIT);
// 未知1字節
buf.put((byte)0);
// 分隔符
buf.put(DELIMIT);
// receiver
buf.putInt(receiver);
// 未知1字節
buf.put((byte)0x03);
// 消息字節長度
buf.putChar((char)message.length);
// 消息
buf.put(message);
}
/**
* @return Returns the contentId.
*/
public int getContentId() {
return contentId;
}
/**
* @param contentId The contentId to set.
*/
public void setContentId(int contentId) {
this.contentId = contentId;
}
/**
* @return Returns the contentType.
*/
public byte getContentType() {
return contentType;
}
/**
* @param contentType The contentType to set.
*/
public void setContentType(byte contentType) {
this.contentType = contentType;
}
/**
* @return Returns the message.
*/
public byte[] getMessage() {
return message;
}
/**
* @param message The message to set.
*/
public void setMessage(byte[] message) {
this.message = message;
}
/**
* @return Returns the messageSequence.
*/
public char getMessageSequence() {
return messageSequence;
}
/**
* @param messageSequence The messageSequence to set.
*/
public void setMessageSequence(char messageSequence) {
this.messageSequence = messageSequence;
}
/**
* @return Returns the receiver.
*/
public int getReceiver() {
return receiver;
}
/**
* @param receiver The receiver to set.
*/
public void setReceiver(int receiver) {
this.receiver = receiver;
}
/**
* @return Returns the senderName.
*/
public String getSenderName() {
return senderName;
}
/**
* @param senderName The senderName to set.
*/
public void setSenderName(String senderName) {
this.senderName = senderName;
}
/**
* @return Returns the sendMode.
*/
public byte getSendMode() {
return sendMode;
}
/**
* @param sendMode The sendMode to set.
*/
public void setSendMode(byte sendMode) {
this.sendMode = sendMode;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -