using CallCenter.Utility;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace CallCenterApi.Interface.Controllers
{
    public class ReceiveMsg
    {
        /// <summary>
        /// 生成回复的消息（发送被动响应消息）
        /// </summary>
        /// <param name="data"></param>
        /// <param name="receiver_id"></param>
        /// <param name="sender_id"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static string pushMsg(string data, long receiver_id, long sender_id, string type)
        {
            data = HttpUtility.UrlEncode(data, Encoding.UTF8);
            string jsonData = "{\"result\":true,\"receiver_id\":" + receiver_id + ",\"sender_id\":" + sender_id + ",\"type\":\"" + type + "\",\"data\":\"" + data + "\"}";
            return jsonData.ToString();
        }
        /// <summary>
        /// 纯文本类型私信消息：text
        /// </summary>
        /// <returns></returns>
        public static string textMsg(string postString)
        {
            string textMsg = string.Empty;
            //根据业务对消息进行处理
            JObject resultJson = null;
            resultJson = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(postString);
            string msgType = resultJson["type"].ToString();
            long sender_id = long.Parse(resultJson["receiver_id"].ToString());
            long receiver_id = long.Parse(resultJson["sender_id"].ToString());
            string msgContent = resultJson["text"].ToString();
            //查询判断
            if (msgContent == "你好")
            {
                textMsg = "您好，欢迎光临";
            }
            else
            {
                textMsg = "您好，没有查到你要的信息，可以输入[新闻]关键词";
            }
            Dictionary<string, object> dics1 = new Dictionary<string, object>();
            dics1.Add("text", textMsg);
            return JsonConvert.SerializeObject(dics1);
        }
        /// <summary>
        /// 图文类型私信消息data字段
        /// </summary>
        /// <returns></returns>
        public static string articlesMsg(string postString)
        {
            //根据业务对消息进行处理
            JObject resultJson = null;
            resultJson = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(postString);
            string msgType = resultJson["type"].ToString();
            long sender_id = long.Parse(resultJson["receiver_id"].ToString());
            long receiver_id = long.Parse(resultJson["sender_id"].ToString());
            string msgContent = resultJson["text"].ToString();

            List<articlesModel> list = new List<articlesModel>();
            list.Add(new articlesModel()
            {
                display_name = "职工之家建设工程询价公告",
                summary = "今天讲两个故事，分享给你。谁是公司？谁又是中国人？​",
                image = "http://zwfwzx.shangqiu.gov.cn/icity/project/shangqiu/default/public/assets/img/3_411400000000.jpg",
                url = "http://zwfwzx.shangqiu.gov.cn/icity/govservice/pub/contentDetail?id=abe3804ce7704f4fb25b3f4cd2aa5e28",
            });
            list.Add(new articlesModel()
            {
                display_name = "网上政务大厅，为您提供一站式的互联网体验",
                summary = "商丘市行政服务中心·网上政务大厅？​",
                image = "http://zwfwzx.shangqiu.gov.cn/icity/project/shangqiu/default/public/assets/img/logo_411400000000.png",
                url = "http://zwfwzx.shangqiu.gov.cn/icity/public/index",
            });
            list.Add(new articlesModel()
            {
                display_name = "市12345政府服务热线举办话务员培训班",
                summary = "市12345政府服务热线举办话务员培训班​",
                image = "http://zwfwzx.shangqiu.gov.cn/Inspur.Dzzw.WebSite/static/data/15021543618551716.jpg",
                url = "http://zwfwzx.shangqiu.gov.cn/icity/govservice/pub/contentDetail?id=8ba112313e1d44bf8c7f98987caf6ced&lastColumn=xwdt&column=%E4%B8%AD%E5%BF%83%E6%96%B0%E9%97%BB",
            });
            list.Add(new articlesModel()
            {
                display_name = "实施三十五证合一 切实便民利企",
                summary = "实施三十五证合一 切实便民利企​",
                image = "http://zwfwzx.shangqiu.gov.cn/Inspur.Dzzw.WebSite/static/data/15016655655792572.png",
                url = "http://zwfwzx.shangqiu.gov.cn/icity/govservice/pub/contentDetail?id=f5183dfd78674ea5b307c8d1a001caaa&lastColumn=xwdt&column=%E4%B8%AD%E5%BF%83%E6%96%B0%E9%97%BB",
            });
            var person = new
            {
                articles = list,
            };
            return JsonConvert.SerializeObject(person);
        }
        /// <summary>
        /// 图文类型私信消息
        /// </summary>
        public class articlesModel
        {
            public string display_name { get; set; }
            public string summary { get; set; }
            public string image { get; set; }
            public string url { get; set; }
        }

        
    }
}