1: public void SendClusterIM(int clusterId, string message)
2: {
3: SendClusterIM(clusterId, message, new FontStyle());
4: }
5: /// <summary>发送群信息
6: /// Sends the cluster IM.
7: /// </summary>
8: /// <param name="clusterId">The cluster id.</param>
9: /// <param name="message">The message.</param>
10: /// <param name="totalFragments">The total fragments.</param>
11: /// <param name="fragmentSequence">The fragment sequence.</param>
12: public void SendClusterIM(int clusterId, string message, FontStyle fontStyle)
13: {
14: int MaxByte = 690;//群消息最长长度690
15:
16: //
17: //发送长信息的功能由 @蓝色的风之精灵 补充
18: //
19: if (Encoding.GetEncoding(QQGlobal.QQ_CHARSET_DEFAULT).GetBytes(message).Length > MaxByte)//判断是不是要分段发送
20: {
21: int MessageId = Utils.Util.Random.Next();//生成随即的MessageId
22: List<byte> messageBytes = new List<byte>();
23: messageBytes.AddRange(Utils.Util.GetBytes(message));
24: int messageSize = messageBytes.Count;
25:
26: int totalFragments = ((messageSize % MaxByte) > 0) ? (messageSize / MaxByte + 1) : (messageSize / MaxByte);//计算分片数
27: for (int fragementSequence = 0; fragementSequence < totalFragments; fragementSequence++)
28: {
29: int index = fragementSequence * MaxByte;
30: int BytesSize = ((messageSize - index) > MaxByte) ? MaxByte : (messageSize - index);//不能每次都申请最大长度的byte数组,不然字体会出问题
31: byte[] messageFragementBytes = new byte[BytesSize];
32:
33: messageBytes.CopyTo(index, messageFragementBytes, 0, BytesSize);
34: SendClusterIM(clusterId, messageFragementBytes,MessageId, totalFragments, fragementSequence, fontStyle);
35:
36: }
37: }
38: else
39: {
40: SendClusterIM(clusterId, Utils.Util.GetBytes(message),Utils.Util.Random.Next(), 1, 0, fontStyle);
41: }
42: }
43: /// <summary>发送群信息
44: /// Sends the cluster IM.
45: /// </summary>
46: /// <param name="clusterId">The cluster id.</param>
47: /// <param name="message">The message.</param>
48: /// <param name="totalFragments">The total fragments.</param>
49: /// <param name="fragmentSequence">The fragment sequence.</param>
50: /// <param name="fontStyle">The font style.</param>
51: public void SendClusterIM(int clusterId, byte[] messageByte,int MessageId, int totalFragments, int fragmentSequence, FontStyle fontStyle)
52: {
53: ClusterSendIMExPacket packet = new ClusterSendIMExPacket(QQUser);
54: packet.ClusterId = clusterId;
55: packet.Message = messageByte;
56: packet.MessageId = (ushort)MessageId;//指定MessageId
57: packet.TotalFragments = totalFragments;
58: packet.FragmentSequence = fragmentSequence;
59: packet.FontStyle = fontStyle;
60: QQClient.PacketManager.SendPacket(packet, QQPort.Main.Name);
61: }