using System;
using System.Threading;
using System.Linq;
using System.Data;
using Library;
using MySystem.Models;
using LitJson;
using System.Collections.Generic;
using System.Security.Cryptography;

namespace MySystem
{
    public class MqLinksHelper
    {
        public readonly static MqLinksHelper Instance = new MqLinksHelper();
        private MqLinksHelper()
        {
        }

        string reqUrl = "http://cs.mqlinks.com/txmsgpush";

        public string doSomething(string DeviceId, string Amount)
        {
            string result = "";
            try
            {
                Dictionary<string, object> data = new Dictionary<string, object>();
                data.Add("cmd", "voice");
                data.Add("msg", "来客八收款" + Amount + "元");
                data.Add("msgid", DateTime.Now.ToString("yyyyMMddHHmmssfff"));
                Dictionary<string, object> map = new Dictionary<string, object>();
                map.Add("sbx_id", DeviceId);
                map.Add("agent_id", data);
                result = post(map);
            }
            catch (Exception ex)
            {
                LogHelper.Instance.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "云音响播报异常");
            }
            return result;
        }

        private string post(Dictionary<string, object> data)
        {
            string req = Newtonsoft.Json.JsonConvert.SerializeObject(data);
            function.WriteLog("请求地址：" + reqUrl, "云音响播报日志");
            function.WriteLog("请求参数：" + req, "云音响播报日志");
            string result = function.PostWebRequest(reqUrl, req, "application/json");
            function.WriteLog("响应数据：" + result, "云音响播报日志");
            return result;
        }
    }
}