/// <summary>
        /// 载入某场景下的本地对象标签列表
        /// </summary>
        private void LoadCurrentLocalTmplTags()
        {
            HQEnums.SmsSceneOptions     sence        = (HQEnums.SmsSceneOptions)Convert.ToInt32(dllSceneType.SelectedValue);
            Dictionary <string, string> dicPropertys = ShortMessageContext.Intance.GetMessagePropertys(sence);

            this.SenceMsgDataPropertys = dicPropertys;
        }
Пример #2
0
 /// <summary>
 /// 得到本地用于发送消息的类型
 /// </summary>
 /// <param name="scene">场景</param>
 /// <returns></returns>
 public Type GetMessageType(HQEnums.SmsSceneOptions scene)
 {
     if (this.dicTypes.ContainsKey(scene))
     {
         return(dicTypes[scene]);
     }
     return(null);
 }
Пример #3
0
        /// <summary>
        /// 给指定会员发送短消息
        /// </summary>
        /// <param name="toMobile">发送的手机号码</param>
        /// <param name="data">消息内容</param>
        /// <param name="errmsg">错误信息</param>
        /// <returns>是否成功</returns>
        public static bool Send(string toMobile, ShortMessageBase data, out string errmsg)
        {
            errmsg = "";
            try
            {
                //1、场景获得
                HQEnums.SmsSceneOptions scene = data.GetFitedScene();

                //2、获取对应的模板消息
                ShortMessageTemplateModel configInfo = ShortMessageTemplateBLL.Instance.GetModelBySceneType((int)scene);
                if (configInfo == null)
                {
                    errmsg = "没有找到对应的配置";
                    return(false);
                }

                if (configInfo.Status != 1)
                {
                    errmsg = "配置未启用";
                    return(false);
                }

                string msgContent = configInfo.Template;
                if (msgContent.Trim() == "")
                {
                    errmsg = "模板为空";
                    return(false);
                }

                //3、反射读取当前对象的所有属性的值,替换模板
                System.Reflection.PropertyInfo[] propertys = data.GetType().GetProperties();
                foreach (System.Reflection.PropertyInfo p in propertys)
                {
                    string name   = p.Name;
                    object objval = p.GetValue(data, null);
                    msgContent = msgContent.Replace("{" + name + "}", objval == null ? "" : objval.ToString());
                }

                //4、发送
                SmsProviderFactory.GetSmsProvider().SendSms(toMobile, msgContent, out errmsg);
                LogHelper.Write(string.Format("SendSms-->手机:{0},发送内容:{1} {2}", toMobile, msgContent, errmsg));
                return(true);
            }
            catch (Exception ex)
            {
                errmsg = string.Format("发送短信异常(ShortMessageDispatcher->Send):{0}", ex.Message);
                return(false);
            }
        }
Пример #4
0
        /// <summary>
        /// 根据场景和字典,生成对象
        /// </summary>
        /// <param name="scene">场景</param>
        /// <param name="dicDatas"></param>
        /// <returns></returns>
        public ShortMessageBase SetMessagePropertys(HQEnums.SmsSceneOptions scene, Dictionary <string, string> dicDatas)
        {
            Type msgType = GetMessageType(scene);

            if (msgType == null)
            {
                throw new Exception(string.Format("没有找到场景[{0}]对应的数据", scene));
            }
            object msgInstance = Activator.CreateInstance(msgType);

            System.Reflection.PropertyInfo[] properties = msgType.GetProperties();
            foreach (PropertyInfo pro in properties)
            {
                if (dicDatas.ContainsKey(pro.Name))
                {
                    pro.SetValue(msgInstance, dicDatas[pro.Name], null);
                }
            }
            return((ShortMessageBase)msgInstance);
        }
Пример #5
0
        /// <summary>
        /// 获取本地用于发送模板消息的属性描述
        /// </summary>
        /// <param name="scene">场景</param>
        /// <returns></returns>
        public Dictionary <string, string> GetMessagePropertys(HQEnums.SmsSceneOptions scene)
        {
            Type msgType = GetMessageType(scene);

            Dictionary <string, string> dicPropertys = new Dictionary <string, string>();

            if (msgType != null)
            {
                System.Reflection.PropertyInfo[] properties = msgType.GetProperties();
                foreach (PropertyInfo pro in properties)
                {
                    foreach (object arr in pro.GetCustomAttributes(typeof(ShortMessagePropertyAttribute), true))
                    {
                        ShortMessagePropertyAttribute pi = (ShortMessagePropertyAttribute)arr;
                        if (!dicPropertys.ContainsKey(pro.Name))
                        {
                            dicPropertys.Add(pro.Name, pi.Desc);
                        }
                    }
                }
            }
            return(dicPropertys);
        }