Esempio n. 1
0
        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);
                }
            }