using System.Net;
using System.Text;
using System;
using XYY.Api.WarningNotice.WarningNoticeService;

namespace XYY.Service.Standard.First.DB
{
    public class MessageHelper
    {
        public static void SendWXMsg(string title, string msg)
        {
            string url = @"http://120.24.149.148:9505/WarningNotice/NoticeText";
            WebClient client = new WebClient();
            TextMessageNoticeTarget warningNoticeTarget = new TextMessageNoticeTarget();
            warningNoticeTarget.TargetName = title;
            warningNoticeTarget.Content = msg;
            warningNoticeTarget.ServiceType = "微信";
            client.Headers.Add("Content-Type", "application/json");
            string json = Newtonsoft.Json.JsonConvert.SerializeObject(warningNoticeTarget);
            byte[] data = Encoding.UTF8.GetBytes(json);
            try
            {
                client.UploadData(url, data);

            }
            catch (Exception ex)
            {
            }
        }


        public static void SendWXMsg(string title, string msg, string[] UserId)
        {
            string url = @"http://120.24.149.148:9505/WarningNotice/NoticeTextToUser";
            WebClient client = new WebClient();
            TextMessageNoticeTarget warningNoticeTarget = new TextMessageNoticeTarget();
            warningNoticeTarget.TargetName = title;
            warningNoticeTarget.Content = msg;
            warningNoticeTarget.ServiceType = "微信";
            warningNoticeTarget.UserId = UserId;
            client.Headers.Add("Content-Type", "application/json");
            string json = Newtonsoft.Json.JsonConvert.SerializeObject(warningNoticeTarget);
            byte[] data = Encoding.UTF8.GetBytes(json);
            try
            {
                client.UploadData(url, data);

            }
            catch (WebException ex)
            {
                string error = ex.Message;
            }
        }
    }
}