예제 #1
0
 string defaultpassword = "******"; //默认显示密码
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         ChkAdminLevel("sms_config", HTEnums.ActionEnum.View.ToString()); //检查权限
         ht_sms_config sms = db.ht_sms_config.FirstOrDefault();
         txtLink.Text = sms.smsurl;
         txtName.Text = sms.smsuser;
         txtPwd.Attributes["value"] = txtPwd.Attributes["value"] = defaultpassword;
         txtPwd.Text = EncryptUtil.DesDecrypt(sms.smspwd, "haitao");
     }
 }
예제 #2
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            ChkAdminLevel("sms_config", HTEnums.ActionEnum.Edit.ToString()); //检查权限
            ht_sms_config sms = db.ht_sms_config.FirstOrDefault();

            sms.smsurl  = txtLink.Text;
            sms.smsuser = txtName.Text;
            if (txtPwd.Text.Trim() != defaultpassword)
            {
                sms.smspwd = EncryptUtil.DesEncrypt(txtPwd.Text, "haitao");
            }
            db.SaveChanges();
            JscriptMsg("保存成功", "");
        }
예제 #3
0
        /// <summary>
        /// 发送短信
        /// </summary>
        /// <param name="mobile"></param>
        /// <param name="content"></param>
        /// <param name="callname"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static bool SendMsg(string mobile, string code, string callname, int expire, out string msg)
        {
            msg = "发送成功";
            //检查是否过期
            string cookie = Utils.GetCookie(Keys.Cookie_SMS_Mobile);

            if (cookie == mobile)
            {
                msg = "已发送过短信,请" + expire + "分钟后再试!";
                return(false);
            }
            string template = GetTemplate(callname); //取得短信内容

            if (template == null)
            {
                msg = "发送失败,短信模板不存在,请联系管理员!";
                return(false);
            }
            //替换标签
            template = template.Replace("{code}", code);
            template = template.Replace("{expire}", "2");
            ht_sms_config smsConfig = GetSMSConfig();

            if (string.IsNullOrEmpty(smsConfig.smsurl) || string.IsNullOrEmpty(smsConfig.smsuser) || string.IsNullOrEmpty(smsConfig.smspwd))
            {
                msg = "短信配置参数有误,请完善后再提交!";
                return(false);
            }
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("account", smsConfig.smsuser);
            dic.Add("pswd", smsConfig.smspwd);
            dic.Add("mobile", mobile);
            dic.Add("msg", template);
            dic.Add("needstatus", "true");
            string result = "";

            try
            {
                result = RequestUtil.HttpPost(smsConfig.smsurl, dic);

                var      rArr   = result.Split(Environment.NewLine.ToCharArray());
                string[] strArr = rArr[0].Split(',');
                if (strArr.Length < 2)
                {
                    msg = "返回值错误";
                    return(false);
                }
                if (strArr[1] != "0")
                {
                    msg = errDic[strArr[1]];
                    return(false);
                }
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                return(false);
            }

            Utils.WriteCookie(Keys.Cookie_SMS_Mobile, mobile, expire); //规定时间内无重复发送
            return(true);
        }