C#关于HttpClient的应用(二):融云IM集成
public class RcHttpClient:BaseHttpClient
{
private String appKey;
private String appSecret; public RcHttpClient()
{
this.appKey = BaseHelper.GetValue("RongCloudAppKey");
this.appSecret = BaseHelper.GetValue("RongCloudSecret");
this.contentType = "application/x-www-form-urlencoded";
} public RcHttpClient(String appKey, String masterSecret)
{
this.appKey = appKey;
this.appSecret = masterSecret;
this.contentType = "application/x-www-form-urlencoded";
} /// <summary>
/// HTTP 验证
/// </summary>
/// <returns></returns>
public override Dictionary<string,string> Authorization()
{
Random rd = new Random();
String nonce = Convert.ToString(rd.Next());
string timestamp = Convert.ToString(BaseHelper.ConvertDateTimeInt(DateTime.Now));
string signature = Sha1.GetHash(this.appSecret + nonce + timestamp); return new Dictionary<string, string>
{
{"App-Key", this.appKey},
{"Nonce", nonce},
{"Timestamp", timestamp},
{"Signature", signature}
};
}
Server层:
public class RcClientServer
{
#region 请求地址
private const String HOST_PATH = "http://api.cn.ronghub.com";
private const String GET_TOKEN_PATH = HOST_PATH + "/user/getToken.json";
private const String CREATE_GROUP_PATH = HOST_PATH + "/group/create.json";
private const String JOIN_GROUP_PATH = HOST_PATH + "/group/join.json";
private const String QUIT_GROUP_PATH = HOST_PATH + "/group/quit.json";
private const String DISMISS_PATH = HOST_PATH + "/group/dismiss.json";
private const String SYNC_GROUP_PATH = HOST_PATH + "/group/sync.json";
private const String SEND_MSG_PATH = HOST_PATH + "/message/publish.json";
private const String BROADCAST_PATH = HOST_PATH + "/message/broadcast.json";
private const String CREATE_CHATROOM_PATH = HOST_PATH + "/chatroom/create.json";
private const String DESTORY_CHATROOM_PATH = HOST_PATH + "/chatroom/destroy.json";
private const String QUERY_CHATROOM_PATH = HOST_PATH + "/chatroom/query.json";
#endregion /// <summary>
/// 获取Token
/// </summary>
/// <param name="userId"></param>
/// <param name="name"></param>
/// <param name="portraitUri"></param>
/// <returns></returns>
public static ResultDTO GetToken(String userId, String name, String portraitUri)
{
var reqParams = new Dictionary<String, String>
{
{"userId", userId},
{"name", name},
{"portraitUri", portraitUri}
};
RcHttpClient client=new RcHttpClient();
var result = client.SendRequest(Method.Post, GET_TOKEN_PATH, client.BuildQueryStr(reqParams));
if (result.status)
{
return WebApi.Success(JsonHelper.ToObject(result.info.ToString())["token"].ToString());
}
return WebApi.Error(result.info);
} /// <summary>
/// 创建群组
/// </summary>
/// <param name="userId"></param>
/// <param name="groupId"></param>
/// <param name="groupName"></param>
/// <remarks>同一用户最多可加入 3000 个群,每个群最大至 3000 人</remarks>
/// <returns></returns>
public static bool CreateGroup(String userId, String groupId, String groupName)
{
var reqParams = new Dictionary<String, String>
{
{"userId", userId},
{"groupId", groupId},
{"groupName", groupName}
};
RcHttpClient client = new RcHttpClient();
var result = client.SendRequest(Method.Post, CREATE_GROUP_PATH, client.BuildQueryStr(reqParams));
return result.status;
} /// <summary>
/// 加入群组
/// </summary>
/// <param name="userId"></param>
/// <param name="groupId"></param>
/// <param name="groupName"></param>
/// <remarks>同一用户最多可加入 3000 个群,每个群最大至 3000 人</remarks>
/// <returns></returns>
public static bool JoinGroup(String userId, String groupId, String groupName)
{
var reqParams = new Dictionary<String, String>
{
{"userId", userId},
{"groupId", groupId},
{"groupName", groupName}
};
RcHttpClient client = new RcHttpClient();
var result = client.SendRequest(Method.Post, JOIN_GROUP_PATH, client.BuildQueryStr(reqParams));
return result.status;
} /// <summary>
/// 退出群组
/// </summary>
/// <param name="userId"></param>
/// <param name="groupId"></param>
/// <returns></returns>
public static bool QuitGroup(String userId, String groupId)
{
var reqParams = new Dictionary<String, String>
{
{"userId", userId},
{"groupId", groupId}
}; RcHttpClient client = new RcHttpClient();
var result = client.SendRequest(Method.Post, QUIT_GROUP_PATH, client.BuildQueryStr(reqParams));
return result.status;
} /// <summary>
/// 解散群组
/// </summary>
/// <param name="userId"></param>
/// <param name="groupId"></param>
/// <returns></returns>
public static bool DismissGroup(String userId, String groupId)
{
var reqParams = new Dictionary<String, String>
{
{"userId", userId},
{"groupId", groupId}
}; RcHttpClient client = new RcHttpClient();
var result = client.SendRequest(Method.Post, DISMISS_PATH, client.BuildQueryStr(reqParams));
return result.status;
} /// <summary>
/// 同步群组
/// </summary>
/// <param name="userId"></param>
/// <param name="groupId"></param>
/// <param name="groupName"></param>
/// <returns></returns>
public static bool SyncGroup(String userId, String[] groupId, String[] groupName)
{
String postStr = "userId=" + userId + "&";
for (int i = ; i < groupId.Length; i++)
{
var id=HttpUtility.UrlEncode(groupId[i], Encoding.UTF8);
var name = HttpUtility.UrlEncode(groupName[i], Encoding.UTF8);
postStr += "group[" + id + "]=" + name + "&";
}
postStr = postStr.Substring(, postStr.LastIndexOf('&')); RcHttpClient client = new RcHttpClient();
var result = client.SendRequest(Method.Post, SYNC_GROUP_PATH, postStr);
return result.status;
} /// <summary>
/// 发送文本消息
/// </summary>
/// <param name="fromUserId"></param>
/// <param name="toUserId"></param>
/// <param name="content"></param>
/// <returns></returns>
public static bool SendTextMessage(string fromUserId,string toUserId,string content)
{
var reqParams = new Dictionary<String, String>
{
{"fromUserId", fromUserId},
{"toUserId", toUserId},
{"objectName", "RC:TxtMsg"},
{"content", content}
};
RcHttpClient client = new RcHttpClient();
var result = client.SendRequest(Method.Post, SYNC_GROUP_PATH, client.BuildQueryStr(reqParams));
return result.status;
}
}
C#关于HttpClient的应用(二):融云IM集成的更多相关文章
- iOS:融云即时通讯快速集成
一.介绍 即时通讯在众多社交软件.生活软件以及教育软件中已经是必备的功能了,在当前国内,即时通讯SDK做的比较不错的有那么几家,例如环信SDK.融云SDK...,这两家做的都很不错,各有千秋吧,要是真 ...
- APICloud平台的融云2.0集成
融云2.0的官方文档地址:http://docs.apicloud.com/端API/开放SDK/rongCloud2 项目须要IM模块,最后还是选择了融云.在iOS原生开发中,融云sdk集成了聊天界 ...
- web 直播&即时聊天------阿里云、融云(二)
上一篇简要主要介绍了融云制作聊天室的基本方法,这次基本属于对上一篇的补充以及进阶...^_^... (ps:吐槽一下,加了三个融云的线下qq群,全部没人解决问题,也不知道建此群的意义,若是民间的话就当 ...
- 融云官方cordova示例使用指南
最近公司要在App里加IM功能,用融云IM.于是下载其cordova版示例:https://github.com/rongcloud/cordova-plugin-rongcloud-im-demo ...
- apicloud+融云实现即时通讯
请尊重作者的辛勤劳动!!! 使用apicloud开发已经快2个月了,起初的目的就是为了实现安卓和苹果的兼容,属于一个试验项目,究竟apicloud是否能够满足公司的要求?最 终看来还是不错的,使用ap ...
- 融云(找到“每个App都有沟通的需求”的细分市场)
近日,国内著名App驾考宝典和融云达成合作,为应用增加IM功能,实现亿级用户之间聊天.消息一出,IM(即时通讯)领域的大佬,同时也是个上线不到两岁的新生力量,再次引发了行业的关注. 对业内人士而言,即 ...
- web 直播&即时聊天------阿里云、融云
随着直播越来越火,所在公司也打算制作自己的直播,所以去了解了这方面,使用后发现还是有些问题需要记录的. 经过分析,制作直播应该是分为两块来做,即直播与实时评论.这里先去制作实时评论,等直播ok后,也会 ...
- web 直播&即时聊天------阿里云、融云(三)
经过前面的知识,基本已经把聊天室的功能搞定了,剩下的就是直播的问题了... 一如既往,阿里云的web demo也是少的可怜,只有一个web播放器(Prismplayer),所以这里主要就此播放器踩的坑 ...
- 融云亮相GDG谷歌女性开发者大会 揭秘IMSDK网络优化策略
4 月 20 日,冷雨阻碍不了天津GDG谷歌女性开发者大会的热烈召开,一众开发者.架构师和科技公司创业者云集一堂,就女性开发者的技术.职场.人生多方面话题展开深入探讨.活动由GDG (谷歌开发者社区) ...
随机推荐
- 每天努力一点之SQL
今天工作当中遇到一个问题:统计信息并导出EXcel 报表. 刚开始只做了统计信息: 如下图 请看最后一列的数据. 我当时想都从数据库里取出来,但是由于我能力有限没有做出来.先贴下后来写的SQL 语句. ...
- UVA - 12338 Anti-Rhyme Pairs (哈希)
Description D Anti-Rhyme Pairs Input: Standard Input Output: Standard Output Often two words that rh ...
- Effective C++ Item 32 确保你的 public 继承模子里出来 is-a 关联
本文senlie原版的,转载请保留此地址:http://blog.csdn.net/zhengsenlie 经验:"public继承"意味 is-a.适用于 base classe ...
- DS-5/RVDS4.0变量初始化错误
最近总是有各种调试时的错误,内存错误一般,我无意中发现的所有全局变量失败,也就是说,全局变量声明之后,颂值早期值误. 初值明明是0x12345674,最后变为了0xBA141234,出现了移位现象 測 ...
- yum 安装时错误 Errno 14 Couldn't resolve host 解决办法(转)
在安装mlocate的时候发现一直报错,错误内容大致如下 Downloading Packages:http://mirrors.163.com/centos/6.5/os/i386/Packages ...
- OnWndMsg处理功能
于MFC于, OnWndMsg功能,如以下处理步骤: 1)首先.被推断消息有一个消息响应函数.例如OnLButtonDown()处理"左新闻"新闻. 2)数.这里以MFC 的pro ...
- C++该函数隐藏
只有基类成员函数的定义已声明virtualkeyword,当在派生类中的时间,以支付功能实现,virtualkeyword可以从时间被添加以增加.它不影响多状态. easy混淆视听,掩盖: ,规则例如 ...
- SystemTrayDemo
遗留问题:win7 java.awt.TrayIcon的displayMessage方法没有生效,通知消息不能正常弹出. 许多桌面环境都有一个区域用于放置在后台运行的程序的图标,这些程序偶尔会将某些 ...
- 单元测试React
React单元测试——十八般兵器齐上阵,环境构建篇 一个完整.优秀的项目往往离不开单元测试的环节,就 github 上的主流前端项目而言,基本都有相应的单元测试模块. 就 React 的项目来说,一套 ...
- Chapter 1 Securing Your Server and Network(12):保护链接server
原文出处:http://blog.csdn.net/dba_huangzj/article/details/38438363.专题文件夹:http://blog.csdn.net/dba_huangz ...