• C#后台利用正则表达式查找匹配字符


    /// <summary>
            /// 发送短信 系统固化短信
            /// </summary>
            /// <param name="memberId"></param>
            /// <param name="mobile"></param>
            /// <param name="subType"></param>
            /// <param name="groupId"></param>
            /// <returns></returns>
            public static Result SendMsgBySysInit(string memberId, string mobile, string subType, int groupId)
            {
                using (CRMEntities db = new CRMEntities())
                {
                    var qTemp = db.TM_Act_CommunicationTemplet.Where(o => o.IsSysInit == true && o.Type == "SMS" && o.SubType == subType && o.DataGroupID == groupId).FirstOrDefault();
                    string sendMsg = "";
                    int templateId = 0;
                    if (qTemp != null)
                    {
                        sendMsg = qTemp.BasicContent;
                        templateId = qTemp.TempletID;
                    }
                    Regex reg = new Regex(@"{[a-zA-Z u4e00-u9fa5]+}");
                    MatchCollection mc = reg.Matches(sendMsg);
                    List<Dictionary<string, string>> lstDict = new List<Dictionary<string, string>>();
                    for (int i = 0; i < mc.Count; i++)
                    {
                        string strRgx = mc[i].Value.ToString().TrimStart('{').TrimEnd('}');
                        Dictionary<string, string> dict = new Dictionary<string, string>();
                        var qAlias = db.TD_SYS_FieldAlias.Where(o => o.FieldDesc == strRgx).FirstOrDefault();
                        if (qAlias != null)
                        {
                            dict["name"] = qAlias.FieldAlias;
                            if (qAlias.ControlType == "date")
                            {
                                DateTime qSqlRet = db.Database.SqlQuery<DateTime>(string.Format("select {2} from {0} where memberId='{1}'", qAlias.TableName, memberId, qAlias.FieldName)).FirstOrDefault();
                                dict["value"] = qSqlRet.ToShortDateString();
                            }
                            else
                            {
                                string qSql = db.Database.SqlQuery<string>(string.Format("select Convert(varchar,{2}) from {0} where memberId='{1}'", qAlias.TableName, memberId, qAlias.FieldName)).FirstOrDefault();
                                dict["value"] = qSql;
                            }
                            lstDict.Add(dict);
                        }
                    }
                    if (lstDict != null && lstDict.Count > 0)
                    {
                        Result ret = SendSms(memberId, mobile, templateId, lstDict, sendMsg);
                        return ret;
                    }
                    else
                        return new Result(false, "参数不正确,不能发送短信!");
                }
            }

    internal static Result SendSms(string memberId, string mobile, int templateId, object para, string message)
            {
                string defaultUser = "sys";
                try
                {
                    using (CRMEntities db = new CRMEntities())
                    {
                        StringBuilder sb = new StringBuilder();
                        List<Dictionary<string, string>> lstPara = (List<Dictionary<string, string>>)para;
                        sb.Append("{");
                        for (int i = 0; i < lstPara.Count; i++)
                        {
                            Dictionary<string, string> dict = lstPara[i];
                            sb.AppendFormat(""{0"}:"{1}"", dict["name"], dict["value"]);
                            if (i < lstPara.Count - 1)
                                sb.AppendFormat(",");
                        }
                        sb.Append("}");
                        var ent = new TM_Sys_SMSSendingQueue
                        {
                            Mobile = mobile,
                            Message = message,
                            MemberID = memberId,
                            AddedDate = DateTime.Now,
                            AddedUser = defaultUser,
                            Remark = "sys",
                            MsgPara = sb.ToString(),//JsonHelper.Serialize(para),
                            TempletID = templateId,
                            IsSent = false,
                        };
                        db.TM_Sys_SMSSendingQueue.Add(ent);
                        db.SaveChanges();

                        return new Result(true, "发送成功!");
                    }
                }
                catch (Exception ex)
                {
                    return new Result(false, ex.Message);
                }
            }

  • 相关阅读:
    1.LOAM安装
    查看memcached运行状态
    (转)服务器故障排查,侵删
    百度地图tilesloaded只触发一次
    Linux 安装NVIDIA显卡
    Oracle常用sql(持续更新)
    jetBrain idea 常用插件整理
    关于swiper4 一个页面多个轮播的问题
    linux 日常工作常用软件(持续更新)
    WPS for Linux ,Linux平台最好的文档编辑软件,没有之一
  • 原文地址:https://www.cnblogs.com/itjeff/p/5124645.html
Copyright © 2020-2023  润新知