02/25/2025 15:42:56
Friend Module
I. Overview
The Friend module is a social function module of MSDK. Its main functions include:
- Query the Personal Information
- Add QQ friends
II. Guide on how to access the module
2.1 Register the callback
1) Functional description
For the callback of MSDK's Friend module, the game needs to register a callback function for processing. The information drawn from the platform side may have delays. It is delayed for about 1 hour from QQ and about 0-4 hours from WeChat.
2) Interface declaration
/// <summary>
/// Logout callback, app wakeup callback
/// </summary>
public static event OnMSDKRetEventHandler<MSDKBaseRet> LoginBaseRetEvent;
/// <summary>
//// Login callback, including login, bind, autologin, switchuser, etc.
/// </summary>
public static event OnMSDKRetEventHandler<MSDKLoginRet> LoginRetEvent;
/// Callback of the basic result
public static event OnMSDKRetEventHandler<MSDKBaseRet> FriendRetEvent;
/// Callback for finding friends
public static event OnMSDKRetEventHandler<MSDKFriendRet> QuereyFriendEvent;
class MSDKLoginObserver
{
public:
// Login callback, including login, bind, autologin, switchuser, etc.
virtual void OnLoginRetNotify(const MSDKLoginRet &loginRet) {};
// Logout callback, app wakeup callback
virtual void OnBaseRetNotify(const MSDKBaseRet &baseRet) {};
};
class MSDKFriendObserver
{
public:
/// Callback of the basic result
virtual void OnDeliverMessageNotify(const MSDKBaseRet &baseRet) {};
/// Callback for finding friends
virtual void OnQueryFriendNotify(const MSDKFriendRet &friendRet) {};
};
3) Demo code
MSDKLogin.LoginRetEvent += OnLoginRetEvent;
MSDKLogin.LoginBaseRetEvent += OnLoginBaseRetEvent;
MSDKFriend.FriendRetEvent += OnFriendRetEvent;
MSDKFriend.QuereyFriendEvent += OnQuereyFriendEvent;
private void OnLoginRetEvent(MSDKLoginRet loginRet)
{
Debug.Log ("OnLoginRetNotify in Ligin");
string methodTag = "";
if (loginRet.MethodNameId == (int)MSDKMethodNameID.MSDK_LOGIN_QUERYUSERINFO) {
methodTag = "QueryUserInfo";
}
else
{
// other things...
}
SampleInstance.showRetDialog(methodTag, loginRet);
}
private void OnLoginBaseRetEvent(MSDKBaseRet baseRet)
{
Debug.Log ("OnBaseRetNotify in Login");
// login things...
}
public void OnFriendRetEvent(MSDKBaseRet baseRet)
{
string methodTag = "";
if (baseRet.MethodNameId == (int)MSDKMethodNameID.MSDK_FRIEND_ADD_FRIEND) {
methodTag = "AddFriend";
}
else {
// other thing...
}
SampleInstance.showRetDialog(methodTag, baseRet);
}
public void OnQuereyFriendEvent(MSDKFriendRet friendRet)
{
string methodTag = "";
if (friendRet.MethodNameId == (int)MSDKMethodNameID.MSDK_FRIEND_QUERY_FRIEND) {
methodTag = "QueryFriends";
}
SampleInstance.showRetDialog(methodTag, friendRet);
}
// It is needed to remove the listener when destroying AccountEvent
private void OnDestroy()
{
MSDKLogin.LoginRetEvent -= OnLoginRetEvent;
MSDKLogin.LoginBaseRetEvent -= OnLoginBaseRetEvent;
MSDKFriend.FriendRetEvent -= OnFriendRetEvent;
MSDKFriend.QuereyFriendEvent -= OnQuereyFriendEvent;
}
MSDKLogin::SetLoginObserver(new MSDKDemoBaseLoginObserver());
MSDKFriend::SetFriendObserver(new MyFriendObserver());
class MSDKDemoBaseLoginObserver: public GCloud::MSDK::MSDKLoginObserver {
// Login callback, including queryUserInfo, login, bind, autologin, switchuser, etc.
public:
virtual void OnLoginRetNotify(const GCloud::MSDK::MSDKLoginRet &loginRet) {
String ret = MSDKUtils::FormatJson(MSDKJsonManager::ToJson(loginRet));
UMSDKDemoBase::showNormalAlert(ret);
};
// Logout callback, app wakeup callback
virtual void OnBaseRetNotify(const GCloud::MSDK::MSDKBaseRet &baseRet) {
String ret = MSDKUtils::FormatJson(MSDKJsonManager::ToJson(baseRet));
// other things...
UMSDKDemoBase::showNormalAlert(ret);
};
};
// The Friend module's listener
class MyFriendObserver : public MSDKFriendObserver {
public:
void OnDeliverMessageNotify(const MSDKBaseRet &baseRet) {
String ret = MSDKUtils::FormatJson(MSDKJsonManager::ToJson(baseRet));
UMSDKDemoBase::showNormalAlert(ret);
};
void OnQueryFriendNotify(const MSDKFriendRet &friendRet) {
String ret = MSDKUtils::FormatJson(MSDKJsonManager::ToJson(friendRet));
UMSDKDemoBase::showNormalAlert(ret);
};
};
4) Data structure
Details about MSDKLoginRet
It inherits MSDKBaseRet and contains basic information
Member variable name | Type | Description |
---|---|---|
openID | string | User ID |
token | string | User token |
tokenExpire | long | Expiration time |
firstLogin | int | Do you log in for the first time? Unknown -1; Yes-1, No-0 |
regChannelDis | string | Distribution channel registered for the first time |
userName | string | Nickname |
gender | int | Gender, undefined-0, male-1, female-2 WeChat and QQ channels always return 0 |
pictureUrl | string | Avatar link |
pf | string | pf value |
pfkey | string | pfkey |
realNameAuth | bool | Is real name authentication required? |
channelID | int | Channel ID |
channel | string | Channel name |
channelInfo | string | Third-party channel's login information |
confirmCode | string | Confirmation code, which is returned after binding fails |
confirmCodeExpireTime | string | Expiration timestamp of the confirmation code |
bindList | string | Information about the binding (JSON data, array type). For details of bindlist, please refer to [Query Binding Relationship] (../Server/bind.md) |
Details about MSDKFriendRet
It inherits MSDKBaseRet and contains basic information
Member variable name | Type | Description |
---|---|---|
friendInfoList | List<MSDKPersonInfo> | Friends list |
2.2 Query the Personal Account Information
1) Functional description
In the game, get the information of the account used by the user currently for logging into the channel, including third-party account information
2) Interface declaration
public static void QueryUserInfo()
public static void QueryUserInfo();
3) Demo code
MSDKLogin.QueryUserInfo();
MSDKLogin::QueryUserInfo();
If the game needs to modify the size of the QQ player's avatar, be careful not to change the original link field splicing structure
The following is the personal avatar return link style of the player on the QQ platform. It is used as a reference for game developers. What is finally returned by the platform shall prevail
- Normal identity: http://thirdqq.qlogo.cn/g?b=oidb&k=6AJZXGDES1gHgiaK9kbIJlA&s=100&t=1466475684
- Virtual account identity: http://thirdqq.qlogo.cn/qqopen/ZdvYp9s7k6o0mHZMOqNJ3Na28broRWwlTZtH7ZzuYrIibicBOy2ZNXMDlBricO1hh6G/100?v=ac9c
- Default callback: https://q.qlogo.cn/qqapp/1106977030/9C38601899722D920F157C8B510F3E36/100
What is a virtual account? Please click "View"
2.3 Add friends
1) Functional description
In the game, a player can directly add other game players as his or her QQ friends (by launching QQ) (multiple clicks will not send multiple applications for adding QQ friends). Currently, only QQ supports this function.
2) Interface declaration
public static void AddFriend(MSDKFriendReqInfo info, string channel = "")
public static void AddFriend(const MSDKFriendReqInfo &reqInfo, const string &channel = "");
3) Description of input parameters
Parameter name | Parameter type | Description |
---|---|---|
info | MSDKFriendReqInfo | The Friend module's request struct, which mainly contains important input parameters such as the request object and request information |
channel | string | Channel information, such as "QQ" |
4) Demo code
var reqInfo = new MSDKFriendReqInfo
{
Title = "title",
Desc = "desc",
Type = FriendReqType.Friend_REQ_TEXT,
User = "7446850278352354985",
};
MSDKFriend.AddFriend (reqInfo, "QQ");
MSDKFriendReqInfo info;
info.title = "title";
info.desc = "desc";
info.type = kMSDKFriendReqTypeText;
info.extraJson = "{\"media_tag_name\":\"MSG_INVITE\",\"message_action\":\"WECHAT_SNS_JUMP_SHOWRANK\",\"message_ext\":\"message_ext\"}";
info.user = "friendOpenId";
MSDKFriend::AddFriend (info, "QQ");
III. FAQ
3.1 Details about MSDKPersonInfo
Member variable name | Type | Description |
---|---|---|
openid | string | User ID |
userName | string | Nickname |
gender | int | Gender, undefined-0, male-1, female-2 WeChat and QQ channels always return 0 |
pictureUrl | string | Avatar link |
country | string | country |
province | string | province |
city | string | city |
language | string | language |
3.2 Details about MSDKFriendReqInfo
Member variable name | Type | Description |
---|---|---|
Type | int | Required when sharing a message, but not required when adding friends. [Friend request type] (#33- Detailed description of friends request types). The backend sends messages by the Silence mode or by launching the app |
User | string | The user, which can be id or openid. For example, when a player specifies a friend for sharing messages in WeChat, it is needed to fill in the openid of the specified friend |
Title | string | Required; the title of the shared content |
Desc | string | Optional; overview, which briefly describes the purpose of sharing |
ImagePath | string | Optional; the image path, which can be a local address or URL. It is recommended to use the local address |
ThumbPath | string | Optional; thumbnail, which is generally the game's icon and can be a local icon or an icon URL. It is recommended to use a local address. WeChat sharing supports up to 64k |
MediaPath | string | Optional; multimedia (music or video), which only supports the local address |
Link | string | Optional; sharing link, which can be an image, music or video link or a hoplink. This parameter is required when the QQ channel sends an app invitation. In WeChat channel, 'link' can be left blank, but extraJson, an extension field, needs to carry "game_data". Both cannot be left blank at the same time |
ExtraJson | string | Optional, extension field |
3.3 Detailed description of friends request types
public enum FriendReqType
{
Friend_REQ_TEXT = 10000, //text sharing
Friend_REQ_LINK, // link sharing
Friend_REQ_IMG, //image sharing
Friend_REQ_INVITE, //app invitation
Friend_REQ_MUSIC, //Music sharing
Friend_REQ_VIDEO, // video sharing
Friend_REQ_MINI_APP, //MiniApp sharing
FRIEND_REQ_PULL_UP_MINI_APP, //MiniApp launch
Friend_REQ_ARK, //ARKsharing
Friend_REQ_TEXT_SILENT = 20000, //text sharing ( Silence )
Friend_REQ_LINK_SILENT, // link sharing ( Silence )
Friend_REQ_IMG_SILENT, //image sharing (Silence)
Friend_REQ_INVITE_SILENT, //app invitation (Silence)
Friend_REQ_MUSIC_SILENT, //Music sharing (Silence)
Friend_REQ_VIDEO_SILENT, // video sharing (Silence)
Friend_REQ_MINI_APP_SILEN, //MiniApp sharing (Silence)
}
typedef enum MSDKFriendReqType
{
kMSDKFriendReqTypeText = 10000, //text sharing
kMSDKFriendReqTypeLink, //link sharing
kMSDKFriendReqTypeIMG, //image sharing
kMSDKFriendReqTypeInvite, //app invitation
kMSDKFriendReqTypeMusic, //Music sharing
kMSDKFriendReqTypeVideo, // video sharing
kMSDKFriendReqTypeMiniApp, //MiniApp sharing
kMSDKFriendReqTypePullUpMiniApp, //MiniApp launch
kMSDKFriendReqTypeArk, //ARKsharing
kMSDKFriendReqTypeTextSilent = 20000, //text sharing ( Silence )
kMSDKFriendReqTypeLinkSilent, //link sharing (Silence)
kMSDKFriendReqTypeIMGSilent, //image sharing (Silence)
kMSDKFriendReqTypeInviteSilent, //app invitation (Silence)
kMSDKFriendReqTypeMusicSilent, //Music sharing (Silence)
kMSDKFriendReqTypeVideoSilent, // video sharing (Silence)
kMSDKFriendReqTypeMiniAppSilent, //MiniApp sharing (Silence)
} MSDKFriendReqType;
All rights reserved.