目录

C#应用配置修改

1、可先下载demo,并更新demo项目依赖,建议采用最新版本,然后运行demo;
2、在项目中添加sdk目录中最新的dll包:mimc-csharp-sdk.dll,您可以直接添加本地dll,或者通过       Nuget安装;
3、项目采用Visual Studio 2017开发,已开放源码;
4、日志采用log4net组件,项目中已经做了简单配置,可以按照需要自行修改;
5、目前因为语法问题,C#SDK 代码存在两个大版本NET Framework2.0/3.5 和NET Framework4.5/NET     Core 2.0/NET Standard 2.0以上两个版本,demo亦是;

用户初始化

/// 默认支持多设备登录
/// <param name="appAccount">用户在APP帐号系统内的唯一帐号ID</param>
/// <param name="appAccount">用户在APP帐号系统内的唯一帐号ID</param>
/// <param name="path">自定义用户缓存目录,用于存放resource信息,如果不设置,默认放在项目运行目录</param>
User user = new User(string appAccount);
User user = new User(string appAccount,string path);

安全认证

参考 安全认证

user.RegisterTokenFetcher(IMIMCTokenFetcher fetcher);

实现接口:

interface IMIMCTokenFetcher {

   /// <summary>
   ///  FetchToken()访问APP应用方自行实现的AppProxyService服务,
   ///  该服务实现以下功能:
   ///1. 存储appId/appKey/appSecret(appKey/appSecret不可存储在APP客户端,以防泄漏)
   ///2. 用户在APP系统内的合法鉴权
   ///3. 调用小米TokenService服务,将小米TokenService服务返回结果通过fetchToken()返回
   /// </summary>
   /// <returns>小米TokenService服务下发的原始数据</returns>

   /// MIMCUser如果采用Login()方式登录 则必须实现该接口
   string FetchToken();

   /// MIMCUser如果采用LoginAsync()方式登录 则必须实现该接口
   Task<string> FetchTokenAsync();
}

登录

/**
 * @note: 用户登录接口,除在APP初始化时调用,APP从后台切换到前台时也建议调用一次
 */
user.Login();
user.LoginAsync();

发送单聊消息

/// <summary>
/// 发送单聊消息
/// </summary>
/// <param name="toAppAccount">消息接收者在APP帐号系统内的唯一帐号ID</param>
/// <param name="msg">开发者自定义消息体,二级制数组格式</param>
/// <param name="isStore">是否保存历史记录,true:保存,false:不存</param>
/// <returns>packetId客户端生成的消息ID</returns>
String packetId = user.SendMessage(string toAppAccount, byte[] msg)
String packetId = user.SendMessageAsync(string toAppAccount, byte[] msg)
String packetId = user.SendMessage(string toAppAccount, byte[] msg, bool isStore)
String packetId = user.SendMessageAsync(string toAppAccount, byte[] msg, bool isStore)

发送群聊消息

/// <summary>
/// 发送群聊消息
/// </summary>
/// <param name="topicId">群ID</param>
/// <param name="msg">开发者自定义消息体,二级制数组格式</param>
/// <param name="isStore">是否保存历史记录,true:保存,false:不存</param>
/// <returns>packetId客户端生成的消息ID</returns>
String packetId = user.SendGroupMessage(long topicId, byte[] msg)
String packetId = user.SendGroupMessageAsync(long topicId, byte[] msg)
String packetId = user.SendGroupMessage(long topicId, byte[] msg, bool isStore)
String packetId = user.SendGroupMessageAsync(long topicId, byte[] msg, bool isStore)

无限大群

创建无限大群

/// <summary>
/// 创建无限大群
/// </summary>
/// <returns></returns>
public string CreateUnlimitedGroup(String topicName)

解散无限大群

/// <summary>
/// 解散无限大群
/// </summary>
/// <param name="topicId"></param>
/// <returns></returns>
public bool DismissUnlimitedGroup(long topicId)

加入无限大群

/// <summary>
/// 加入无限大群
/// </summary>
/// <param name="topicId"></param>
/// <returns></returns>
public string JoinUnlimitedGroup(long topicId)

退出无限大群

/// <summary>
/// 离开无限大群
/// </summary>
/// <param name="topicId"></param>
/// <returns></returns>
public string QuitUnlimitedGroup(long topicId)

发送无限大群消息

/// <summary>
/// 发送无限大群消息
/// </summary>
/// <param name="topicId">群ID</param>
/// <param name="msg">开发者自定义消息体,二级制数组格式</param>
/// <returns></returns>
public string SendUnlimitedGroupMessage(long topicId, byte[] msg)

接收消息回调

///添加事件,注册事件,实现回调方法

//发送单聊消息回调
user.MessageEvent += HandleMessage;
//发送单聊消息超时回调
user.MessageTimeOutEvent += HandleMessageTimeout;
//发送群聊消息回调
user.GroupMessageEvent += HandleGroupMessage;
//发送群聊消息超时回调
user.GroupMessageTimeoutEvent += HandleGroupMessageTimeout;
//ServerACK回调
user.ServerACKEvent += HandleServerACK;
//发送无限大群消息回调
user.unlimitedGroupMessageEvent += HandleUnlimitedGroupMessage;
//发送无限大群消息超时回调
user.unlimitedGroupMessageTimeoutEvent += HandleUnlimitedGroupMessageTimeout;
//加入无限大群回调
user.joinUnlimitedGroupEvent += HandleJoinUnlimitedGroup;
//退出无限大群回调
user.quitUnlimitedGroupEvent += HandleQuitUnlimitedGroup;
//解散无限大群回调
user.dismissUnlimitedGroupEvent += HandleDismissUnlimitedGroup;


void HandleMessageTimeout(object source, SendMessageTimeoutEventArgs e)
void HandleGroupMessage(object source, GroupMessageEventArgs e)
void HandleGroupMessageTimeout(object source, SendGroupMessageTimeoutEventArgs e)
void HandleServerACK(object source, ServerACKEventArgs e)
void HandleUnlimitedGroupMessage(UCPacket ucPacket)
void HandleJoinUnlimitedGroup(UCPacket ucPacket)
void HandleQuitUnlimitedGroup(UCPacket ucPacket)
void HandleDismissUnlimitedGroup(UCPacket ucPacket)
void HandleSendUnlimitedGroupMessageTimeout(UCPacket message)

注销

user.Logout();
user.LogoutAsync();

回到顶部

results matching ""

    No results matching ""