📄 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 + -