예제 #1
0
        public static readonly string msgHubServer = "https://msghub.rupeng.com/";//"http://*****:*****@888_6xx!aa");

            ViewBag.token = token;
            return(View());
        }
예제 #2
0
        public async Task <bool> SendGroupMessage([FromBody] SendGroupMessageRequest req)
        {
            string       token      = req.token;
            var          httpClient = httpClientFactory.CreateClient();
            MsgHubClient client     = new MsgHubClient(msgHubServer, httpClientFactory);
            await client.SendGroupMessageAsync(token, req.toGroupId, req.objectName, req.content);

            return(true);
        }
예제 #3
0
        public async Task <IActionResult> Index()
        {
            var          httpClient = httpClientFactory.CreateClient();
            MsgHubClient client     = new MsgHubClient(msgHubServer, httpClientFactory);
            var          token      = await client.GetTokenAsync("1", "yzk", "rupenggongkaike", DateTime.Now.ToFileTime(), "wpstt@999_6xx!aa");

            ViewBag.token = token;
            return(View());
        }
예제 #4
0
        public async Task <bool> JoinGroup([FromBody] JoinGroupRequest req)
        {
            string token = req.token;
            //todo:要根据业务系统的要求,判断这个用户是否能加入这个Group
            MsgHubClient client = new MsgHubClient(msgHubServer);
            await client.JoinGroupAsync(token, req.groupId);

            return(true);
        }
예제 #5
0
파일: Program.cs 프로젝트: ricer20045523/-
        static async Task StartOneClientAsync(int taskId)
        {
            var token      = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBcHBLZXkiOiJydXBlbmdnb25na2Fpa2UiLCJEaXNwbGF5TmFtZSI6IuadqOS4reenkSIsIlVzZXJJZCI6IjI4IiwiZXhwIjoxNTU3NjcxMDI5LCJpc3MiOiJtZSIsImF1ZCI6InlvdSJ9.Xa9hmoMbCRzwIyGvnUX7L4GSAXhVPUsi2jLz4Kvj2mk";
            var chatRoomId = "Activity_72";


            var connection = new HubConnectionBuilder()
                             .WithUrl("https://msghub.rupeng.com/messageHub", options =>
            {
                options.AccessTokenProvider = () => Task.FromResult(token);
            })
                             .Build();

            connection.Closed += async(error) =>
            {
                Console.WriteLine("连接断开,尝试重连");
                await Task.Delay(2000);

                await connection.StartAsync();
            };

            try
            {
                await connection.StartAsync();

                await connection.InvokeAsync("GetGroupMessages", chatRoomId);

                MsgHubClient client   = new MsgHubClient("https://msghub.rupeng.com/", httpClientFactory);
                string       sdkToken = await client.GetTokenAsync("28", "yzk", appkey, DateTime.Now.ToFileTime(), appsecret);

                Random rand = new Random();
                for (; ;)
                {
                    try
                    {
                        await client.SendGroupMessageAsync(token, chatRoomId, "txtMsg", "[" + Dns.GetHostName() + "]-" + Guid.NewGuid());

                        Console.WriteLine("发送消息完成,taskId=" + taskId);
                        await Task.Delay(rand.Next(20000, 50000));//不能用Thread.Sleep
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("发送消息失败, taskId = " + taskId + "," + ex);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"启动任务失败,taskId=${taskId},${ex}");
            }
        }