public void SendNotice(Model.NoticeModel model, List <Model.NoticeTargetModel> TargetModelList, decimal MerId) { Dictionary <string, string> MerConfig = BLL.StaticBLL.MerConfigCache(MerId, 2000); DAL.NoticeTargetDAL tarDal = new DAL.NoticeTargetDAL(); DAL.NoticeDAL dal = new DAL.NoticeDAL(); dal.Add(model); foreach (Model.NoticeTargetModel TargetModel in TargetModelList) { TargetModel.NoticeId = model.NoticeId; string reJson = RongCloudServer.PublishMessage(MerConfig["RongAppKey"], MerConfig["RongAppSecret"], "messager", TargetModel.TargetId, "RC:TxtMsg", //消息类型 " {\"content\":\"" + model.NoticeContent + "\",\"extra\":" + model.Extra + "}" //消息内容 , model.NoticeTitle); TargetModel.NoticeStatus = 10; //已发送 tarDal.Add(TargetModel); } }
static void Main(string[] args) { String retstr = null; String appKey = "uwd1c0sxdlx91"; String appSecret = "hhetmryhVm"; retstr = RongCloudServer.GetToken(appKey, appSecret, "232424", "xugang", "http://www.qqw21.com/article/UploadPic/2012-11/201211259378560.jpg"); Console.WriteLine("getToken: " + retstr); Console.ReadKey(); retstr = RongCloudServer.JoinGroup(appKey, appSecret, "232424", "group001", "wsw"); Console.WriteLine("joinGroup: " + retstr); Console.ReadKey(); string[] arrId = { "group001", "group002", "group003" }; string[] arrName = { "测试 01", "测试 02", "测试 03" }; retstr = RongCloudServer.syncGroup(appKey, appSecret, "42424", arrId, arrName); Console.WriteLine("syncGroup: " + retstr); Console.ReadKey(); retstr = RongCloudServer.DismissGroup(appKey, appSecret, "42424", "group001"); Console.WriteLine("dismissgroup: " + retstr); Console.ReadKey(); retstr = RongCloudServer.PublishMessage(appKey, appSecret, "2191", "2191", "RC:TxtMsg", "{\"content\":\"c#hello\"}"); Console.WriteLine("PublishMsg: " + retstr); Console.ReadKey(); retstr = RongCloudServer.BroadcastMessage(appKey, appSecret, "2191", "RC:TxtMsg", "{\"content\":\"c#hello\"}"); Console.WriteLine("Broad: " + retstr); Console.ReadKey(); retstr = RongCloudServer.JoinGroup(appKey, appSecret, "423424", "dwef", "dwef"); Console.WriteLine("JoinGroup: " + retstr); Console.ReadKey(); retstr = RongCloudServer.CreateChatroom(appKey, appSecret, arrId, arrName); Console.WriteLine("createChat: " + retstr); Console.ReadKey(); retstr = RongCloudServer.DestroyChatroom(appKey, appSecret, new String[] { "001", "002" }); Console.WriteLine("Destroy: " + retstr); Console.ReadKey(); string[] aaa = { "group002", "group003" }; retstr = RongCloudServer.queryChatroom(appKey, appSecret, aaa); Console.WriteLine("queryChatroom: " + retstr); Console.ReadKey(); Console.WriteLine("接口测试结束!"); Console.ReadKey(); }
public void GetTokenTest() { RongCloudServer server = new RongCloudServer( new ApiFilter( new RongCloudConfig { AppKey = "pvxdm17jpv1or", AppSecret = "I8a4qFGzFe8" })); var tokenResult = server.GetToken("123456").Result; Assert.NotEqual(tokenResult, null); Assert.Equal(tokenResult.code, 200); }
/// <summary> /// 创建用户,创建成功返回token /// </summary> /// <param name="model"></param> /// <returns>用户token</returns> public string CreateUser(UserModel model) { if (IsExists(model.userName)) { return("Repeat UserName"); } string guid = Guid.NewGuid().ToString(); string userName = model.userName; string email = model.email; string phoneNumber = model.phoneNumber; string password = EncriyptHelper.ToMd5(model.password); //获取用户token string appKey = ConfigurationManager.AppSettings["rongYunAppkey"].ToString(); string secret = ConfigurationManager.AppSettings["rongYunSecret"].ToString(); string token_response = RongCloudServer.GetToken(appKey, secret, guid, userName, "https://mycontainner.blob.core.chinacloudapi.cn/container/defaultAvator"); string token = string.Empty; try { JObject jsonObject = JObject.Parse(token_response); if (jsonObject["code"].ToString() == "200") { token = jsonObject["token"].ToString(); } } catch { } string strSql = "INSERT INTO dbo.Users VALUES(@id,@userName,@email,@phoneNumber,@password,@token,@avatorUri,@sex,@resident,@signature)"; SqlParameter[] parameters = { new SqlParameter("@id", System.Data.SqlDbType.VarChar, 50), new SqlParameter("@userName", System.Data.SqlDbType.NVarChar, 50), new SqlParameter("@email", System.Data.SqlDbType.VarChar, 50), new SqlParameter("@phoneNumber", System.Data.SqlDbType.VarChar, 50), new SqlParameter("@password", System.Data.SqlDbType.VarChar, 50), new SqlParameter("@token", System.Data.SqlDbType.VarChar, 200), new SqlParameter("@avatorUri", System.Data.SqlDbType.VarChar, 100), new SqlParameter("@sex", System.Data.SqlDbType.NChar, 10), new SqlParameter("@resident", System.Data.SqlDbType.NVarChar, 50), new SqlParameter("@signature", System.Data.SqlDbType.NVarChar, 50) }; parameters[0].Value = guid; parameters[1].Value = userName; parameters[2].Value = email; parameters[3].Value = phoneNumber; parameters[4].Value = password; parameters[5].Value = token; parameters[6].Value = "https://mycontainner.blob.core.chinacloudapi.cn/container/defaultAvator"; parameters[7].Value = "男"; parameters[8].Value = "无"; parameters[9].Value = "空空如也~"; if (DBHelper.ExecuteNonQuery(strSql, parameters) > 0) { return(token); } else { return(string.Empty); } }
public void SendMsgToDevice(List <string> DeviceList, Model.MsgTextModel MsgTextModel, string SendDeviceId, decimal MerId) { Dictionary <string, string> MerConfig = BLL.StaticBLL.MerConfigCache(MerId, 2000); DAL.MsgTextDAL dal = new DAL.MsgTextDAL(); if (MsgTextModel.MsgClassId == 0) { throw new Exception("消息类型(MsgClassId)不能为0"); } dal.Add(MsgTextModel); Model.MsgModel model = new Model.MsgModel(); model.MsgTextId = MsgTextModel.MsgTextId; model.SendDeviceId = SendDeviceId; model.ZoneId = "1"; model.MsgStatusId = 10; string reJson = ""; DAL.MsgDAL MsgDal = new DAL.MsgDAL(); foreach (string DeviceId in DeviceList) { model.TargetDeviceId = DeviceId; SaveMsg(model); StringBuilder s = new StringBuilder(); s.Append(" DECLARE @MsgNum AS INT = (SELECT COUNT(0) FROM DBMSG.dbo.Msg WHERE TargetDeviceId='" + DeviceId + "' AND MsgStatusId=10) "); s.Append(" DECLARE @MsgTypeName AS VARCHAR(50) =(SELECT MsgTypeName FROM DBMSG.dbo.MsgType WHERE MsgTypeId='" + MsgTextModel.MsgType + "') "); s.Append(" UPDATE DBMSG.dbo.Device SET MsgNum=@MsgNum where DeviceId='" + DeviceId + "' "); s.Append(" SELECT @MsgNum as MsgNum, @MsgTypeName as MsgTypeName "); JObject Extra = new JObject(); try { Extra = JObject.Parse(MsgTextModel.Extra); } catch (Exception) { } finally { DataSet ds = CountMsg(DeviceId); //统计消息数量 DataTable dt = ds.Tables[0]; DataRow dr = dt.Rows[0]; Extra["MsgTypeId"] = MsgTextModel.MsgType; Extra["MsgNum"] = int.Parse(dr["MsgNum"].ToString()); // Extra["MsgTypeName"] = dr["MsgTypeName"].ToString(); } reJson = RongCloudServer.PublishMessage(MerConfig["RongAppKey"], MerConfig["RongAppSecret"], SendDeviceId, DeviceId, "RC:TxtMsg", //消息类型 " {\"content\":\"" + MsgTextModel.MsgTitle + "\",\"extra\":" + Extra.ToString() + "}" //消息内容 , ""); } //BLL.WxBLL wxBll = new WxBLL(); //try //{ // wxBll.SendQyTextMsg(DeviceList, MsgTextModel.MsgTitle, 7); //这个地方, 以后必须改为配置,这个7是写死的数字 //} //catch (Exception) //{ // //如果微信推送不成功就算完吧.可能因为网络问题 //} }