
using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Edu.ThirdCore.Message
{
    /// <summary>
    /// 短信消息
    /// </summary>
    public class SMSService
    {
        /// <summary>
        /// 发送证码
        /// </summary>
        /// <param name="phoneNumber">电话号码</param>
        /// <param name="code">验证码</param>
        /// <param name="templateCode"></param>
        /// <param name="SignName"></param>
        /// <param name="Domain"></param>
        /// <param name="AccessKeyId"></param>
        /// <param name="AccessKeySecret"></param>
        /// <param name="RegionId"></param>
        /// <param name="OutId"></param>
        public static void SendCode(string phoneNumber, string code, string templateCode, string SignName, string Domain, string AccessKeyId, string AccessKeySecret, string RegionId, string OutId)
        {
            JObject obj = new JObject
            {
                ["cmd"] = "sms",
                ["phoneNumber"] = phoneNumber,
                ["templateCode"] = templateCode,
                ["SignName"] = SignName,
                ["Domain"] = Domain,
                ["AccessKeyId"] = AccessKeyId,
                ["AccessKeySecret"] = AccessKeySecret,
                ["RegionId"] = RegionId
            };
            var TemplateParam = new { code };
            obj["OutId"] = OutId;
            obj["templateParam"] = JsonConvert.SerializeObject(TemplateParam);
            QueueHelper.EnqueueTask(JsonConvert.SerializeObject(obj));
        }

        /// <summary>
        /// 发送短信通知
        /// </summary>
        /// <param name="phoneNumber"></param>
        /// <param name="content"></param>
        /// <param name="templateCode"></param>
        public static void SendMsg(string phoneNumber, string content, string templateCode, string SignName, string Domain, string AccessKeyId, string AccessKeySecret, string RegionId, string OutId)
        {
            JObject obj = new JObject
            {
                ["cmd"] = "sms",
                ["phoneNumber"] = phoneNumber,
                ["templateCode"] = templateCode,
                ["SignName"] = SignName,
                ["Domain"] = Domain,
                ["AccessKeyId"] = AccessKeyId,
                ["RegionId"] = RegionId,
                ["AccessKeySecret"] = AccessKeySecret
            };
            var TemplateParam = new { content };
            obj["OutId"] = OutId;
            obj["templateParam"] = JsonConvert.SerializeObject(TemplateParam);
            QueueHelper.EnqueueTask(JsonConvert.SerializeObject(obj));
        }

        /// <summary>
        /// 发送短信通知
        /// </summary>
        /// <param name="phoneNumber"></param>
        /// <param name="templateParam">通知参数</param>
        /// <param name="templateCode"></param>
        public static void SendMsg(string phoneNumber, object templateParam, string templateCode, string SignName, string Domain, string AccessKeyId, string AccessKeySecret, string RegionId,string OutId)
        {
            JObject obj = new JObject
            {
                ["cmd"] = "sms",
                ["phoneNumber"] = phoneNumber,
                ["templateCode"] = templateCode
            };
            var TemplateParam = templateParam;
            obj["SignName"] = SignName;
            obj["Domain"] = Domain;
            obj["RegionId"] = RegionId;
            obj["AccessKeyId"] = AccessKeyId;
            obj["AccessKeySecret"] = AccessKeySecret;
            obj["OutId"] = OutId;
            obj["templateParam"] = JsonConvert.SerializeObject(TemplateParam);
            QueueHelper.EnqueueTask(JsonConvert.SerializeObject(obj));
        }
    }
}
