Let's talk about how lumaqq. Net sends Group messages.

Source: Internet
Author: User

The QQ Group has two IDs: internal ID and external ID. The external ID is a common ID, which is used for searching and viewing.

The internal ID is not common. It should be said that QQ users never know the ID. However, this ID is the focus of this article. This ID is required for sending group information.

People who have used lumaqq. NET and tried to send Group messages with group numbers visible on QQ. I believe they all failed to send out. Why? Because the internal group ID should be used to send Group messages
How can we get the group internal ID? What is the relationship between it and the group's external ID?

Unfortunately, there is no connection between the two ......

However, there is a way to link the two, that is, manually Save the corresponding table at login:

Define a dictionary first:

   1: public static Dictionary<int, int> ClusterDict { get; private set; }

Then add the code to get the group information in the logon success event:

   1: void LoginManager_LoginSuccessed(object sender, LumaQQ.NET.Events.QQEventArgs<LumaQQ.NET.Packets.In.LoginReplyPacket, LoginPacket> e)
   2: {
3: writeerror ("Logon successful ");
4: writeerror ("start to read friend information ");
   5:     e.QQClient.FriendManager.GetFriendList();
   6:     e.QQClient.FriendManager.GetUserInfo(e.QQClient.QQUser.QQ);
7: E. qqclient. friendmanager. downloadgroupfriends (0); // download the group information to obtain the internal number of the group.
   8:  
9: // change the status to exit
  10:     e.QQClient.FriendManager.ChangeStatus(QQStatus.AWAY, false);
11: // read the weather forecast
  12:     e.QQClient.PrivateManager.GetWeather();
  13: }

 

After successfully downloading the group information, determine whether it is a group or not. If it is a group, obtain the group information. (Actually, the friend. QQ here is the internal ID of the group, but we don't know what its external ID is)

   1: void FriendManager_DownloadGroupFriendSuccessed(object sender, QQEventArgs<DownloadGroupFriendReplyPacket, DownloadGroupFriendPacket> e)
   2: {
   3:     foreach (DownloadFriendEntry friend in e.InPacket.Friends)
   4:     {
   5:         if (friend.Type == FriendType.IS_CLUSTER)
   6:         {
   7:             e.QQClient.ClusterManager.GetClusterInfo((int)friend.QQ);
   8:         }
   9:     }
  10: }

Finally, we can get the external ID in the event that the group information is successfully obtained.

   1: void ClusterManager_GetClusterInfoSuccessed(object sender, QQEventArgs<ClusterCommandReplyPacket, ClusterGetInfoPacket> e)
   2: {
   3:     if (!ClusterDict.ContainsKey((int)e.InPacket.Info.ExternalId))
   4:         ClusterDict.Add((int)e.InPacket.Info.ExternalId, (int)e.InPacket.Info.ClusterId);
   5:     else
   6:         ClusterDict[(int)e.InPacket.Info.ExternalId] = (int)e.InPacket.Info.ClusterId;
7: writeerror ("obtain the external ID of Group {0}: {1}, internal ID: {2}", E. inpacket. info. name, E. inpacket. info. externalid, E. inpacket. info. clusterid );
   8: }

 

In this way, when we send Group messages in the future, we can obtain the corresponding internal ID from the dictionary based on the external group ID to send information.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.