Esempio n. 1
0
        private string SendMessage(string destination, string text, string speed = "0")
        {
            string str;

            if (string.IsNullOrWhiteSpace(destination))
            {
                str = "发送目标不能为空!";
            }
            else
            {
                MessageSMSConfig config = SMSCore.GetConfig();
                SortedDictionary <string, string> strs = new SortedDictionary <string, string>()
                {
                    { "mobiles", destination },
                    { "text", text },
                    { "appkey", config.AppKey },
                    { "sendtime", DateTime.Now.ToString() },
                    { "speed", speed }
                };
                Dictionary <string, string> strs1 = SMSAPiHelper.Parameterfilter(strs);
                string str1 = SMSAPiHelper.BuildSign(strs1, config.AppSecret, "MD5", "utf-8");
                strs1.Add("sign", str1);
                strs1.Add("sign_type", "MD5");
                str = SMSAPiHelper.PostData("http://sms.kuaidiantong.cn/SendMsg.aspx", SMSAPiHelper.CreateLinkstring(strs1));
            }
            return(str);
        }
Esempio n. 2
0
        public string GetSMSAmount()
        {
            MessageSMSConfig config = SMSCore.GetConfig();
            string           str    = string.Concat("method=getAmount&appkey=", config.AppKey);

            return(SMSAPiHelper.PostData("http://sms.kuaidiantong.cn/GetAmount.aspx", str));
        }
Esempio n. 3
0
        public void CheckCanEnable()
        {
            MessageSMSConfig config = SMSCore.GetConfig();

            if (string.IsNullOrWhiteSpace(config.AppKey))
            {
                throw new PluginConfigException("未设置AppKey");
            }
            if (string.IsNullOrWhiteSpace(config.AppSecret))
            {
                throw new PluginConfigException("未设置AppSecret");
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 获取配置
        /// </summary>
        /// <returns></returns>
        public static MessageSMSConfig GetConfig()
        {
            MessageSMSConfig config     = new MessageSMSConfig();
            string           sDirectory = Himall.Core.Helper.IOHelper.urlToVirtual(WorkDirectory) + "/Data/SMS.config";

            if (HimallIO.ExistFile(sDirectory))
            {
                XmlSerializer xs  = new XmlSerializer(typeof(MessageSMSConfig));
                byte[]        b   = Himall.Core.HimallIO.GetFileContent(sDirectory);
                string        str = System.Text.Encoding.Default.GetString(b);
                MemoryStream  fs  = new MemoryStream(b);
                config = (MessageSMSConfig)xs.Deserialize(fs);
            }
            return(config);
        }
Esempio n. 5
0
        public static void SaveConfig(MessageSMSConfig config)
        {
            FileStream fileStream = new FileStream(string.Concat(SMSCore.WorkDirectory, "\\Data\\SMS.config"), FileMode.Create);

            try
            {
                (new XmlSerializer(typeof(MessageSMSConfig))).Serialize(fileStream, config);
            }
            finally
            {
                if (fileStream != null)
                {
                    ((IDisposable)fileStream).Dispose();
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 保存配置
        /// </summary>
        /// <param name="config"></param>
        public static void SaveConfig(MessageSMSConfig config)
        {
            //using (FileStream fs = new FileStream(WorkDirectory + "\\Data\\SMS.config", FileMode.Create))
            //{
            //    XmlSerializer xs = new XmlSerializer(typeof(MessageSMSConfig));
            //    xs.Serialize(fs, config);
            //}

            string        sDirectory = Himall.Core.Helper.IOHelper.urlToVirtual(WorkDirectory) + "/Data/SMS.config";
            XmlSerializer xml        = new XmlSerializer(typeof(MessageSMSConfig));
            MemoryStream  Stream     = new MemoryStream();

            xml.Serialize(Stream, config);

            byte[]       b       = Stream.ToArray();
            MemoryStream stream2 = new MemoryStream(b);

            Himall.Core.HimallIO.CreateFile(sDirectory, stream2, Core.FileCreateType.Create);
        }
Esempio n. 7
0
        public void SetFormValues(IEnumerable <KeyValuePair <string, string> > values)
        {
            var appKeyItem = values.FirstOrDefault(item => item.Key == "AppKey");

            if (string.IsNullOrWhiteSpace(appKeyItem.Value))
            {
                throw new Himall.Core.PluginConfigException("AppKey不能为空");
            }
            var appSecretItem = values.FirstOrDefault(item => item.Key == "AppSecret");

            if (string.IsNullOrWhiteSpace(appSecretItem.Value))
            {
                throw new Himall.Core.PluginConfigException("AppSecret不能为空");
            }
            MessageSMSConfig oldConfig = SMSCore.GetConfig();

            oldConfig.AppKey    = appKeyItem.Value;
            oldConfig.AppSecret = appSecretItem.Value;
            SMSCore.SaveConfig(oldConfig);
        }
Esempio n. 8
0
 private void BatchSendMessage(string[] destination, string text)
 {
     if (destination.Length > 0)
     {
         MessageSMSConfig config = SMSCore.GetConfig();
         SortedDictionary <string, string> strs = new SortedDictionary <string, string>()
         {
             { "mobiles", string.Join(",", destination) },
             { "text", text },
             { "appkey", config.AppKey },
             { "sendtime", DateTime.Now.ToString() },
             { "speed", "1" }
         };
         Dictionary <string, string> strs1 = SMSAPiHelper.Parameterfilter(strs);
         string str = SMSAPiHelper.BuildSign(strs1, config.AppSecret, "MD5", "utf-8");
         strs1.Add("sign", str);
         strs1.Add("sign_type", "MD5");
         SMSAPiHelper.PostData("http://sms.kuaidiantong.cn/SendMsg.aspx", SMSAPiHelper.CreateLinkstring(strs1));
     }
 }
Esempio n. 9
0
        public void SetFormValues(IEnumerable <KeyValuePair <string, string> > values)
        {
            KeyValuePair <string, string> keyValuePair = values.FirstOrDefault((KeyValuePair <string, string> item) => item.Key == "AppKey");

            if (string.IsNullOrWhiteSpace(keyValuePair.Value))
            {
                throw new PluginConfigException("AppKey不能为空");
            }
            KeyValuePair <string, string> keyValuePair1 = values.FirstOrDefault((KeyValuePair <string, string> item) => item.Key == "AppSecret");

            if (string.IsNullOrWhiteSpace(keyValuePair1.Value))
            {
                throw new PluginConfigException("AppSecret不能为空");
            }
            MessageSMSConfig config = SMSCore.GetConfig();

            config.AppKey    = keyValuePair.Value;
            config.AppSecret = keyValuePair1.Value;
            SMSCore.SaveConfig(config);
        }
Esempio n. 10
0
        public FormData GetFormData()
        {
            MessageSMSConfig config    = SMSCore.GetConfig();
            FormData         formDatum = new FormData();

            FormData.FormItem[] formItemArray = new FormData.FormItem[2];
            FormData.FormItem   formItem      = new FormData.FormItem();
            formItem.DisplayName = "AppKey";
            formItem.Name        = "AppKey";
            formItem.IsRequired  = true;
            formItem.Type        = (FormData.FormItemType) 1;
            formItem.Value       = config.AppKey;
            formItemArray[0]     = formItem;
            FormData.FormItem formItem1 = new FormData.FormItem();
            formItem1.DisplayName = "AppSecret";
            formItem1.Name        = "AppSecret";
            formItem1.IsRequired  = true;
            formItem1.Type        = (FormData.FormItemType) 1;
            formItem1.Value       = config.AppSecret;
            formItemArray[1]      = formItem1;
            formDatum.Items       = formItemArray;
            return(formDatum);
        }