Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tran"></param>
        /// <param name="Recipient">接收短信前缀语,用于拼接短信公共部分</param>
        /// <param name="recipientNo">接收人在系统中的编号[可为空]</param>
        /// <param name="mobile">接受人手机号码</param>
        /// <param name="primaryKey">短信关联外键[可为空]</param>
        /// <param name="smsCategory">发送类型</param>
        /// <returns></returns>
        public static bool SendMsgTo(SqlTransaction tran, string PreMsg, string recipientNo, string mobile, string primaryKey, Model.SMSCategory smsCategory)
        {
            string    ExSql = "select DefaultContent from configSMS where isOpen=1 and configCode=" + (int)smsCategory;
            string    info  = string.Empty;
            string    msg   = string.Empty;
            bool      flag  = false;
            DataTable dt    = DAL.DBHelper.ExecuteDataTable(tran, ExSql);

            if (dt != null && dt.Rows.Count > 0)
            {
                msg = dt.Rows[0]["DefaultContent"].ToString();
            }
            if (msg != "")
            {
                msg  = PreMsg + msg;
                flag = SendMsgTo(tran, recipientNo, primaryKey, mobile, msg, out info, smsCategory);
            }
            return(flag);
        }
Exemple #2
0
        /// <summary>
        /// 匹配模式发送短信内容,用于收款,发货,注册的短信通知——ds2012——tianfeng
        /// </summary>
        /// <param name="tran"></param>
        /// <param name="PreName">接收短信称呼</param>
        /// <param name="SuffixMsg">个人信息</param>
        /// <param name="recipientNo">接收人在系统中的编号[可为空]</param>
        /// <param name="mobile">接受人手机号码</param>
        /// <param name="primaryKey">>短信关联外键[可为空]</param>
        /// <param name="smsCategory">发送类型</param>
        /// <returns></returns>
        public static bool SendMsgMode(SqlTransaction tran, string PreName, string Profile, string recipientNo, string mobile, string primaryKey, Model.SMSCategory smsCategory)
        {
            string    ExSql = "select DefaultContent from configSMS where isOpen=1 and configCode=" + (int)smsCategory;
            string    info  = string.Empty;
            string    msg   = string.Empty;
            bool      flag  = false;
            DataTable dt    = DAL.DBHelper.ExecuteDataTable(tran, ExSql);

            if (dt != null && dt.Rows.Count > 0)
            {
                msg = dt.Rows[0]["DefaultContent"].ToString();
            }
            if (msg != "")
            {
                Regex rxName    = new Regex(@"(\[Name\])", RegexOptions.IgnoreCase);
                Regex rxProfile = new Regex(@"(\[Profile\])", RegexOptions.IgnoreCase);

                msg = rxName.Replace(msg, PreName);       //替换称呼部分rxProfile
                msg = rxProfile.Replace(msg, Profile);    //替换个人信息

                flag = SendMsgTo(tran, recipientNo, primaryKey, mobile, msg, out info, smsCategory);
            }
            return(flag);
        }
Exemple #3
0
        /// <summary>
        /// [带事务,7参数]发送短信并记录历史记录
        /// </summary>
        /// <param name="tran"></param>
        /// <param name="recipientNo">接收人在系统中的编号[可为空]</param>
        /// <param name="primaryKey">关联主键[可为空]</param>
        /// <param name="mobile">接收人手机号码</param>
        /// <param name="msg">发送内容</param>
        /// <param name="info">返回信息[out参数]</param>
        /// <param name="category">短信类型</param>
        /// <returns></returns>
        public static bool SendMsgTo(SqlTransaction tran, string recipientNo, string primaryKey, string mobile, string msg, out string info, Model.SMSCategory category)
        {
            info = "";
            bool   flag  = false;
            bool   flag2 = false;
            string mRtv  = "";

            if (mobile != "")
            {
                if (msg.Length <= 256)
                {
                    MobileSMS sm = new MobileSMS();

                    string    tempMsg = msg;
                    string    temp    = "";
                    ArrayList msgAr   = new ArrayList();
                    while (tempMsg.Length > 65)
                    {
                        temp    = tempMsg.Substring(0, 65).Trim(); //前65个字符
                        tempMsg = tempMsg.Substring(65);           //65以后的字符
                        msgAr.Add(temp);
                    }
                    if (tempMsg.Length > 0)
                    {
                        msgAr.Add(tempMsg);
                    }

                    int    maxID       = int.Parse(DAL.DBHelper.ExecuteScalar(tran, "select isnull(max(id),0)  from h_mobilemsg", new SqlParameter[0], CommandType.Text).ToString());
                    string SendNo      = maxID.ToString().PadLeft(8, '0');
                    int    SendSmallNo = 1; //分条序号
                    foreach (string str in msgAr)
                    {                       //短信分条发送
                        flag = sm.SendMobile(tran, new string[] { mobile }, str, out mRtv);
                        string smallNo = SendSmallNo.ToString() + "/" + msgAr.Count.ToString();
                        flag2 = sm.SaveSendMsgRecord(tran, recipientNo, primaryKey, mobile, flag, mRtv, str, SendNo, smallNo, (int)category);
                        if (flag && flag2)
                        {
                            SendSmallNo++;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else
                {
                    info = BLL.Translation.Translate("007140", "短信内容过长");
                    return(false);
                }
            }
            if (flag && flag2)
            {
                info = BLL.Translation.Translate("005615", "发送成功!");
                return(true);
            }
            else
            {
                if (!flag)
                {
                    info = BLL.Translation.Translate("007141", "短信发送失败,返回信息:") + mRtv.Replace("'", "");
                }
                if (!flag2)
                {
                    info = BLL.Translation.Translate("007142", "短信发送记录失败,请与管理员联系!");
                }
                return(false);
            }
        }