コード例 #1
0
        public async Task SendMessage(PushModel pushModel, string groupName)
        {
            try
            {
                var message = JsonConvert.SerializeObject(pushModel);
                var model   = new PushRequestModel()
                {
                    Message   = message,
                    GroupName = groupName
                };
                var requestBody = JsonConvert.SerializeObject(model);
                using (var client = new HttpClient())
                {
                    string url = pusherUrl + "websocket/sendMessage";


                    var result = await client.PostAsync(new Uri(url), new StringContent(requestBody, Encoding.UTF8, "application/json"));

                    if (result.StatusCode == HttpStatusCode.OK)
                    {
                        string resultContent = await result.Content.ReadAsStringAsync();

                        Console.WriteLine(resultContent);
                    }
                    else
                    {
                        Console.WriteLine("Send FCM Error,Status Code:" + result.StatusCode);
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message, "Error on Push On Web ");
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            WebSocketService webSocketService = new WebSocketService();
            //  webSocketService.Connect();
            var body = Console.ReadLine();

            while (body != "exit")
            {
                var link      = "https://crm.iranian.cards/IranCardDEV/main.aspx?etc=10041&id=6572F425-F263-E811-8431-005056A81EBC&pagetype=entityrecord";
                var userId    = "cdf10765-8926-e811-8416-005056871d68";
                var pushModel = new PushModel
                {
                    Code       = 100,
                    Message    = body,
                    Data       = new { },
                    Link       = HttpUtility.UrlEncode(link),
                    ReceiverId = userId,
                    Title      = "ایران کارت"
                };
                webSocketService.SendMessage(pushModel, userId).Wait();
                body = Console.ReadLine();
            }
        }