
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>
        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();
            obj["cmd"] = "sms";
            obj["phoneNumber"] = phoneNumber;
            obj["templateCode"] = templateCode;
            obj["SignName"] = SignName;
            obj["Domain"] = Domain;
            obj["AccessKeyId"] = AccessKeyId;
            obj["AccessKeySecret"] = AccessKeySecret;
            obj["RegionId"] = RegionId;
            var TemplateParam = new { code = 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();
            obj["cmd"] = "sms";
            obj["phoneNumber"] = phoneNumber;
            obj["templateCode"] = templateCode;
            obj["SignName"] = SignName;
            obj["Domain"] = Domain;
            obj["AccessKeyId"] = AccessKeyId;
            obj["RegionId"] = RegionId;
            obj["AccessKeySecret"] = AccessKeySecret;
            var TemplateParam = new { content };
            obj["OutId"] = OutId;
            obj["templateParam"] = JsonConvert.SerializeObject(TemplateParam);
//LogHelper.WriteInfo("发送短信信息");
            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();
            obj["cmd"] = "sms";
            obj["phoneNumber"] = phoneNumber;
            obj["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));
        }
    }
}
