Exemplo n.º 1
0
        /// <summary>
        /// 检查ODS账户信息
        /// </summary>
        /// <param name="strAccount"></param>
        /// <param name="strTemplateID"></param>
        /// <param name="strURL"></param>
        /// <param name="strTemData"></param>
        /// <param name="pDlg"></param>
        /// <returns></returns>
        private string CheckAccountInfo(string strAccount, string strTemplateID, string strURL, string strTemData, DlgCommonString pDlgGetOpenIDByAccount)
        {
            if (string.IsNullOrEmpty(strAccount))
            {
                EGExceptionOperator.ThrowX <Exception>("缺少ODS账户", EGActionCode.缺少必要参数);
            }

            if (string.IsNullOrEmpty(strTemplateID))
            {
                EGExceptionOperator.ThrowX <Exception>("缺少模板消息ID", EGActionCode.缺少必要参数);
            }

            if (string.IsNullOrEmpty(strURL))
            {
                EGExceptionOperator.ThrowX <Exception>("缺少模板消息回调地址ID", EGActionCode.缺少必要参数);
            }

            //EG.WeChat.Business.JR.BL.AccountBL pBL = new EG.WeChat.Business.JR.BL.AccountBL();
            //string strOpenID = pBL.GetOpenIDByAccountName(strAccount);
            string strOpenID = pDlgGetOpenIDByAccount.Invoke(strAccount);

            if (string.IsNullOrEmpty(strOpenID))
            {
                EGExceptionOperator.ThrowX <Exception>("缺少账户对应微信用户信息", EGActionCode.缺少目标数据);
            }

            return(strOpenID);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 创建微信分组并同步
        /// </summary>
        /// <param name="strGroupName"></param>
        /// <returns></returns>
        public List <GroupsJson_Group> CreateWXGroupAndLoad(string strGroupName)
        {
            List <GroupsJson_Group> pList = new List <GroupsJson_Group>();

            this.ExecuteTryCatch(() =>
            {
                //通过sdk获取accessToken
                string strAccessToken = Senparc.Weixin.MP.CommonAPIs.WeiXinSDKExtension.GetCurrentAccessToken();

                WXGroupServiceWeChat pService = new WXGroupServiceWeChat();
                //首先创建分组
                pService.CreateWXGroup(strAccessToken, strGroupName);
                //再从微信API加载所有分组信息
                pList = pService.GetWCGroupList(strAccessToken);
                if (pList == null || pList.Count == 0)
                {
                    EGExceptionOperator.ThrowX <Exception>("没有微信端用户分组信息", EGActionCode.缺少目标数据);
                }

                WXGroupServiceLocal pServiceLocal = new WXGroupServiceLocal();
                //再更新至数据库并清空缓存
                if (!pServiceLocal.UpdateWCGroupList(pList))
                {
                    throw new Senparc.Weixin.Exceptions.WeixinException("微信限制接口");
                }
            });
            return(pList);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 創建縮略圖
        /// </summary>
        /// <typeparam name="T">IFileUploadResult</typeparam>
        /// <param name="pResults">文件集合</param>
        /// <param name="serverRPath">服務器存放相對路徑</param>
        /// <param name="thumbHeadName">縮略圖頭名稱</param>
        protected void ConvertAndCreateThumb <T>(List <T> pResults, string serverRPath, string thumbHeadName)
            where T : IFileUploadResult, new()
        {
            string strThumbFileName = string.Empty;
            string serverAPath      = serverRPath.Replace("/", @"\");
            //轉換操作
            FormatConverter pCon = new FormatConverter();

            foreach (T pT in pResults)
            {
                // 25487815728572_stb.mp4
                strThumbFileName = string.Format("{0}{1}", pT.FileName, thumbHeadName);
                //
                string err = pCon.Convert(pT.APath, serverAPath, strThumbFileName, FormatConverter.VideoType.MP4, true, true);
                if (!string.IsNullOrEmpty(err))
                {
                    EGExceptionOperator.ThrowX <Exception>(err, EGActionCode.文件上传失败);
                }
                else
                {
                    pT.APath      = pT.APath.Replace(pT.FileName, strThumbFileName);
                    pT.FileName   = strThumbFileName;
                    pT.RPath      = string.Format("{0}/{1}.{2}", serverRPath, strThumbFileName, pT.FormatName);
                    pT.RPathThumb = string.Format("{0}/{1}.{2}", serverRPath, strThumbFileName, "jpg");
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 传图文资源到微信服务器,并写入本地服务器配置文件
        /// </summary>
        /// <param name="ListNews"></param>
        public void UpdateResources(int?lcid, string lcname, string lcclassify, string ListNews, bool byLink)
        {
            this.ExecuteTryCatch(() =>
            {
                if (string.IsNullOrEmpty(ListNews))
                {
                    EGExceptionOperator.ThrowX <Exception>("请输入文章内容", EGActionCode.缺少必要参数);
                }

                WXArticleResultJson pResult = new WXArticleResultJson();
                pResult.lcId       = lcid;
                pResult.lcName     = lcname;
                pResult.lcClassify = lcclassify;
                pResult.byLink     = byLink;

                //将前端生成json串转为段落实体集合:save用于保存本地数据库,段落增加Rpath字段,用于显示图片;out用于上传数据库
                List <NewsModelX> pListNewsSave = CommonFunction.FromJsonTo <List <NewsModelX> >(ListNews);
                List <NewsModel> pListNewsOut   = CommonFunction.FromJsonTo <List <NewsModel> >(ListNews);
                //转换图文内容的HTML标签
                ConvertHTMLP(ref pListNewsSave);
                ConvertHTMLP(ref pListNewsOut);
                //段落实体集合受限赋值到ResultJson
                pResult.ListNews = pListNewsSave;
                //再将段落实体集合转换为数组
                NewsModel[] pArray = pListNewsOut.ToArray();
                //更新资源(上传至微信端,并写入本地配置)
                base.UpdateResources <WXArticleResultJson>(pResult, m_strTargetType, pArray);
            });
        }
Exemplo n.º 5
0
        /// <summary>
        /// 读取本地单个图文资源本地配置
        /// </summary>
        /// <param name="lcId"></param>
        /// <returns></returns>
        public List <object> LoadResources2News(object objlcId, string targetType = "")
        {
            var pResult = new List <object>();

            this.ExecuteTryCatch(() =>
            {
                if (!(objlcId is Int32))
                {
                    return;
                }
                var lcId = Convert.ToInt32(objlcId);

                targetType = targetType == "" ? m_strTargetType : targetType;

                //获取配置,并匹配实体集合
                List <WXArticleResultJson> pList = base.LoadResourcesX <WXArticleResultJson>(targetType);
                if (pList == null || pList.Count == 0)
                {
                    EGExceptionOperator.ThrowX <Exception>("没有编号对应图文消息", EGActionCode.缺少目标数据);
                }
                WXArticleResultJson pEn = pList.Single(p => p.lcId == lcId);
                if (pEn == null || pEn.ListNews == null || pEn.ListNews.Count == 0)
                {
                    EGExceptionOperator.ThrowX <Exception>("没有编号对应图文消息", EGActionCode.缺少目标数据);
                }
                if (this.ArticleConvertFunc == null)
                {
                    EGExceptionOperator.ThrowX <Exception>("请设置图文消息转换方法", EGActionCode.未知错误);
                }
                //var pSelectFunc = m_sdk.GetNewsConvertFunc(targetType);
                pResult = pEn.ListNews.Select(this.ArticleConvertFunc).ToList <object>();
            });
            return(pResult);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 读取本地单个图文资源本地配置
        /// </summary>
        /// <param name="pHost"></param>
        /// <param name="media_id"></param>
        /// <returns></returns>
        public List <Article> LoadResources2LocalArticles(string pHost, int lcId)
        {
            List <Article> pResult = new List <Article>();

            this.ExecuteTryCatch(() =>
            {
                //获取配置,并匹配实体集合
                List <WXArticleResultJson> pList = base.LoadResourcesX <WXArticleResultJson>("news");
                WXArticleResultJson pEn          = pList.Single(p => p.lcId == lcId);
                if (pEn == null || pEn.ListNews == null || pEn.ListNews.Count == 0)
                {
                    EGExceptionOperator.ThrowX <Exception>("没有编号对应图文消息", EGActionCode.缺少目标数据);
                }

                Article pArticle;
                int idx = 0;
                foreach (NewsModelX pNewsModel in pEn.ListNews)
                {
                    pArticle = new Article()
                    {
                        Description = pNewsModel.digest,
                        Title       = pNewsModel.title,
                        PicUrl      = string.Format("http://{0}{1}", pHost, pNewsModel.RPath),
                        Url         = string.Format("http://{0}/WXArticle/Index?mid={1}&idx={2}", pHost, pEn.media_id, idx)
                    };
                    pResult.Add(pArticle);
                    idx += 1;
                }
            });
            return(pResult);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 从缓存中获取微信分组数据
        /// </summary>
        /// <returns></returns>
        public List <GroupsJson_Group> GetWXGroupsCache()
        {
            List <GroupsJson_Group> pList = this.GetCacheList <GroupsJson_Group>(this.GetWXGroupsFromDB, m_WCGroupCacheConfig);

            if (pList == null || pList.Count == 0)
            {
                EGExceptionOperator.ThrowX <Exception>("缺少本地微信用户分组数据,请同步微信端用户分组信息", EGActionCode.缺少目标数据);
            }
            return(pList);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 从缓存中获取微信用户数据
        /// </summary>
        /// <returns></returns>
        public List <TUser> GetWXUsersCache()
        {
            List <TUser> pList = this.GetCacheList <TUser>(this.GetWXUsersFromDB, m_WCUserCacheConfig);

            if (pList == null || pList.Count == 0)
            {
                EGExceptionOperator.ThrowX <Exception>("缺少本地微信用户数据,请同步微信端用户分组信息", EGActionCode.缺少目标数据);
            }
            return(pList);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 通过部门集合获取这些部门拥有的用户ID
        /// </summary>
        /// <returns></returns>
        public List <int> GetUserIDsByDeps(List <int> depIds)
        {
            var orgM    = GetOrgM();
            var userIDs = orgM.Departments.Where(d => depIds.Contains(d.Did)).SelectMany(d => d.SysUserIDs).ToList();

            if (userIDs.IsNull())
            {
                EGExceptionOperator.ThrowX <Exception>("缺少用户数据", string.Empty);
            }
            return(userIDs);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 从缓存中,读取会员卡内容模板数据
        /// </summary>
        /// <param name="pListMediaID"></param>
        /// <returns></returns>
        public List <CardContent> GetCardContentCache(List <string> pListMediaID)
        {
            List <CardContent> pList = this.GetCacheList <CardContent>(LoadResourcesFromData, m_CacheConfig, this.CardCacheRemovedCallback);

            if (pList == null || pList.Count == 0)
            {
                EGExceptionOperator.ThrowX <Exception>("缺少本地会员卡内容模板数据,请配置相关资源", EGActionCode.缺少目标数据);
            }
            //根据条件过滤
            return(pList.Where(con => pListMediaID.Contains(con.MediaID)).ToList <CardContent>());
        }
Exemplo n.º 11
0
        /// <summary>
        /// 从请求中加载上传文件
        /// </summary>
        /// <param name="pRequest"></param>
        /// <param name="pInputFileName"></param>
        /// <param name="pServerPath"></param>
        /// <returns></returns>
        protected void LoadFileFromRequest(HttpRequestBase pRequest, string pInputFileName, string pServerPath, ref WXPictureResultJson pResult)
        {
            //定义错误消息
            string msg = "";
            //接受上传文件
            HttpPostedFileBase hp = pRequest.Files[pInputFileName];

            if (hp == null)
            {
                msg = "请选择文件";
                EGExceptionOperator.ThrowX <Exception>(msg, EGActionCode.缺少必要参数);
            }
            //获取上传目录 转换为物理路径
            string uploadPath = System.Web.HttpContext.Current.Server.MapPath(pServerPath);
            //获取文件名
            string fileName = DateTime.Now.Ticks.ToString() + System.IO.Path.GetExtension(hp.FileName);
            //获取文件大小
            long contentLength = hp.ContentLength;

            //文件不能大于1M
            if (contentLength > 1024 * 1024)
            {
                msg = "文件大小超过限制要求.";
                EGExceptionOperator.ThrowX <Exception>(msg, EGActionCode.输入参数错误);
            }
            if (!checkFileExtension(fileName))
            {
                msg = "文件为不可上传的类型.";
                EGExceptionOperator.ThrowX <Exception>(msg, EGActionCode.输入参数错误);
            }
            //保存文件的物理路径
            string saveFile = uploadPath + fileName;

            try
            {
                //保存文件
                hp.SaveAs(saveFile);
                //写入绝对路径
                pResult.APath = saveFile;
                //写入相对路径
                pResult.RPath = pServerPath + fileName;
                //写入文件名称
                pResult.FileName = fileName;
                //msg = saveFile;
                //msg = pServerPath + fileName;
            }
            catch
            {
                msg = "图片文件上传失败";
                EGExceptionOperator.ThrowX <Exception>(msg, EGActionCode.文件上传失败);
            }
            //return msg;
        }
Exemplo n.º 12
0
 /// <summary>
 /// 执行方法并捕获错误
 /// </summary>
 /// <param name="pInterface"></param>
 /// <param name="action"></param>
 public static void ExecuteTryCatch(this IServiceX pInterface, Action action)
 {
     try
     {
         action.Invoke();
         ActionResult = null;
     }
     catch (Exception ex)
     {
         ActionResult = EGExceptionOperator.ConvertException(ex);
     }
 }
Exemplo n.º 13
0
        /// <summary>
        /// 通过部门获取部门拥有的用户
        /// </summary>
        /// <returns></returns>
        public List <UserVM> GetUsersByDepId(int depId)
        {
            var orgM  = GetOrgM();
            var dep   = orgM.Departments.Single(d => d.Did == depId);
            var users = orgM.Users.Where(u => dep.SysUserIDs.Contains(u.SysUserId)).ToList();

            if (users.IsNull())
            {
                EGExceptionOperator.ThrowX <Exception>("缺少用户数据", string.Empty);
            }
            return(users);
        }
Exemplo n.º 14
0
        /// <summary>
        /// 发送企业消息
        /// </summary>
        /// <param name="lcId"></param>
        /// <param name="messageType"></param>
        /// <param name="toUser"></param>
        /// <param name="toParty"></param>
        /// <param name="toTag"></param>
        /// <param name="agentId"></param>
        public void SendQYMessage(string messageid, string userId, string keyW, string messageType, string toUser, string toParty, string toTag, string agentId, int safe = 0)
        {
            this.ExecuteTryCatch(() =>
            {
                #region
                //messageid = "11";
                //userId = "22";
                //keyW = "1dI_2UQ-kLaMBJ4boKzGopBnisZW2-yP4Z9UG3O00nYBrN9J_zyBX1pxMj9OLqtIo";
                //messageType = "video";
                //toUser = "******";
                //toParty = "@all";
                //toTag = "@all";
                //agentId = "47";
                #endregion

                int lcId;
                object objKeyW = null;
                if (messageType == "news" || messageType == "mpnews")
                {
                    if (int.TryParse(keyW, out lcId))
                    {
                        objKeyW = lcId;
                    }
                }
                else
                {
                    objKeyW = keyW;
                }
                if (objKeyW == null)
                {
                    EGExceptionOperator.ThrowX <Exception>("素材已失效", EGActionCode.未知错误);
                }

                ISdkETS_QY pSdk = QYSdkETS.Singleon;
                //获取素材数据方法并转换
                var resConvertFunc = pSdk.GetResConvert(messageType);
                var content        = resConvertFunc(objKeyW, messageType);
                //
                var sendMsFunc = pSdk.GetMediaSendFunc(messageType);
                //获取AToken
                var atoken = pSdk.GetAToken();
                //发送消息
                var pQYMessageApi = new WeixinMessageSenderQY();
                var pResult       = pQYMessageApi.SendQYMS(content, sendMsFunc, messageType, atoken, toUser, toParty, toTag, agentId, safe);
                if (!string.IsNullOrEmpty(pResult.errmsg) && pResult.errmsg != "send job submission success" && pResult.errmsg != "ok")
                {
                    EGExceptionOperator.ThrowX <Exception>(pResult.errmsg, pResult.errcode.ToString());
                }
                //发送完成后更新
                UpdateGsMessageAfterSend(messageid, userId, 1, string.Empty, pResult.errmsg);
            });
        }
Exemplo n.º 15
0
        /// <summary>
        /// 检查OpenID信息
        /// </summary>
        /// <param name="strOpenID"></param>
        /// <param name="strTemplateID"></param>
        /// <param name="strURL"></param>
        private void CheckOpenIDInfo(string strOpenID, string strTemplateID, string strURL)
        {
            if (string.IsNullOrEmpty(strOpenID))
            {
                EGExceptionOperator.ThrowX <Exception>("缺少微信用户公开编号", EGActionCode.缺少必要参数);
            }

            if (string.IsNullOrEmpty(strTemplateID))
            {
                EGExceptionOperator.ThrowX <Exception>("缺少模板消息ID", EGActionCode.缺少必要参数);
            }

            //if (string.IsNullOrEmpty(strURL))
            //    EGExceptionOperator.ThrowX<Exception>("缺少模板消息回调地址ID", EGActionCode.缺少必要参数);
        }
Exemplo n.º 16
0
        /// <summary>
        /// 执行方法并捕获错误
        /// </summary>
        /// <param name="pInterface"></param>
        /// <param name="action"></param>
        protected HttpResponseMessage ExecuteTryCatch <VModel>(Func <VModel> action)
        {
            CActionResult pActionResult;

            try
            {
#if DEBUG
                //调试模式下,自动注册
                var pUserBL = new TW.Platform.BL.UserBL();
                pUserBL.VerifyBCLoginUser("mark", "504");
#endif

                var vm = action.Invoke();
                pActionResult = new CActionResult()
                {
                    ok = true, message = "", data = vm
                };
                return(Request.CreateResponse(HttpStatusCode.OK, pActionResult));
            }
            catch (Exception ex)
            {
                //转换异常
                var pEGResult = EGExceptionOperator.ConvertException(ex);
                //转换Action结果
                pActionResult = new CActionResult()
                {
                    ok = false, message = pEGResult.Message, data = null
                };
                //写入日志
                if (pEGResult.IsLog)
                {
                    Logger.Log4Net.Info(string.Format("异常代码:{0};异常信息:{1}", pEGResult.ExCode, pEGResult.Message));
                }

                //消息不为空时,确保异常消息返回前端
                if (pEGResult.StCode == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, pActionResult));
                }
                else
                {
                    return(Request.CreateResponse((HttpStatusCode)pEGResult.StCode.Value, pActionResult));
                }
            }
        }
Exemplo n.º 17
0
 /// <summary>
 /// 更新企业号基础配置
 /// </summary>
 public void UpdateCorpConfiguration(int aid, string token, string aeskey)
 {
     this.ExecuteTryCatch(() =>
     {
         EG.WeChat.Platform.DA.WXConfigDA pDA = new Platform.DA.WXConfigDA();
         DataTable dt = pDA.GetWXConfig();
         if (dt == null || dt.Rows.Count == 0)
         {
             EGExceptionOperator.ThrowX <Exception>("缺少企業應用配置信息", EGActionCode.数据库表保存错误);
         }
         var plist = CommonFunction.GetEntitiesFromDataTable <WXConfigM>(dt);
         if (plist.Count == 0)
         {
             EGExceptionOperator.ThrowX <Exception>("缺少企業應用配置信息", EGActionCode.数据库表保存错误);
         }
         var pmodel = plist.Single(p => p.AID == aid && p.ACTYPE == 2);
         if (pmodel == null)
         {
             //Emperor.UtilityLib.CyberUtils.Decrypt("Aes", 256, base.TOKEN, WXConfigDA.FIELD_NAME_TOKEN);
         }
         else
         {
             pmodel.TOKEN  = Emperor.UtilityLib.CyberUtils.Encrypt("Aes", 256, token, WXConfigDA.FIELD_NAME_TOKEN);
             pmodel.AESKEY = Emperor.UtilityLib.CyberUtils.Encrypt("Aes", 256, aeskey, WXConfigDA.FIELD_NAME_AESKEY);
         }
         var ps = new List <WXConfigM>();
         ps.Add(pmodel);
         DataTable dto = CommonFunction.GetDataTableFromEntities <WXConfigM>(ps);
         if (pDA.SetWXConfig(dto))
         {
             WeiXinConfiguration.corpInfos.ForEach((p) =>
             {
                 if (p.aid == aid)
                 {
                     p.token  = token;
                     p.aeskey = aeskey;
                 }
             });
         }
         else
         {
             EGExceptionOperator.ThrowX <Exception>("缺少企業應用配置信息", EGActionCode.数据库表保存错误);
         }
     });
 }
Exemplo n.º 18
0
        /// <summary>
        /// 保存微信资源至DB
        /// </summary>
        /// <param name="strTargetType"></param>
        /// <param name="strValue"></param>
        /// <param name="media_ID"></param>
        private int SaveWXResource(int?lcid, string lcName, string lcClassify, string strTargetType, string strValue, string media_ID, int iSourceType)
        {
            m_CacheConfig = new WXResourceCacheConfig(strTargetType);
            //初始化数据访问DA
            m_DA = CastleAOPUtil.NewPxyByClass <WXResourceDA>(new DataWritingInterceptor(this.RemoveCache, this.m_CacheConfig));
            if (lcid == 0)
            {
                lcid = null;
            }

            //保存资源——暂时不能分类及命名
            lcid = m_DA.SaveResource(lcid, lcName, lcClassify, media_ID, strTargetType, strValue, DateTime.Now, iSourceType, m_sdk == null ? 0 : m_sdk.WXType);
            if (lcid == null)
            {
                EGExceptionOperator.ThrowX <Exception>("微信资源DataBase保存错误", EGActionCode.未知错误);
            }
            return(lcid.Value);
        }
Exemplo n.º 19
0
        /// <summary>
        /// 刪除資源
        /// </summary>
        /// <param name="strTargetType"></param>
        /// <param name="lcid"></param>
        public void DeleteResource(string strTargetType, int lcid)
        {
            if (string.IsNullOrEmpty(strTargetType) || lcid < 1)
            {
                return;
            }

            m_CacheConfig = new WXResourceCacheConfig(strTargetType);
            //初始化数据访问DA
            m_DA = CastleAOPUtil.NewPxyByClass <WXResourceDA>(new DataWritingInterceptor(this.RemoveCache, this.m_CacheConfig));

            int iRes = m_DA.DeleteResource(lcid);

            if (lcid == null)
            {
                EGExceptionOperator.ThrowX <Exception>("微信资源刪除错误", EGActionCode.未知错误);
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// 获取所有群发消息
        /// </summary>
        public List <T> GetAllGsMessage <T>()
        {
            List <T> pList = new List <T>();

            this.ExecuteTryCatch(() =>
            {
                WXGsMessageDA pDa = new WXGsMessageDA();
                //获取从服务器当天时间算起,的两个月时间内的群发消息,例如:当天为10月,即是获得9、10月的消息记录
                string strDateFilter = GetTargetDateFilter(WXGsMessageDA.FIELD_NAME_MTIME, 1);
                DataTable dt         = pDa.GetGsMessage(strDateFilter, m_sdk.WXType);
                if (dt == null || dt.Rows.Count == 0)
                {
                    EGExceptionOperator.ThrowX <Exception>("缺少群发消息数据", EGActionCode.缺少目标数据);
                }

                pList = CommonFunction.GetEntitiesFromDataTable <T>(dt);
            });
            return(pList);
        }
Exemplo n.º 21
0
        /// <summary>
        /// 创建群发消息,并加入到待审核队列
        /// </summary>
        /// <param name="pUserID">用戶編號</param>
        /// <param name="mediaId">媒體ID</param>
        /// <param name="sendType">發送對象類型</param>
        /// <param name="sendTarget">發送目標對象</param>
        /// <param name="content">內容</param>
        /// <param name="messageType">內容類型</param>
        public void CreateGsMessage(string pUserID, string mediaId, int sendType, string sendTarget, string content, string messageType, int wx_type, int agendid, int safe)
        {
            this.ExecuteTryCatch(() =>
            {
                bool iResult      = false;
                WXGsMessageDA pDa = new WXGsMessageDA();
                if (messageType == "text")
                {
                    iResult = pDa.InsertGsMessage(pUserID, DateTime.Now, sendType, sendTarget, messageType, content, 1, wx_type, agendid, safe);
                }
                else
                {
                    iResult = pDa.InsertGsMessage(pUserID, DateTime.Now, sendType, sendTarget, messageType, mediaId, 1, wx_type, agendid, safe);
                }

                if (!iResult)
                {
                    EGExceptionOperator.ThrowX <Exception>("群发消息加入队伍错误", EGActionCode.数据库表保存错误);
                }
            });
        }
Exemplo n.º 22
0
        /// <summary>
        /// 获取所有群发消息
        /// </summary>
        public List <T> GetGsMessage <T>(string pFilter)
        {
            List <T> pList = new List <T>();

            this.ExecuteTryCatch(() =>
            {
                WXGsMessageDA pDa = new WXGsMessageDA();
                //转换前端查询目标
                List <object> pQueryItems = CommonFunction.FromJsonTo <List <object> >(pFilter);
                //转换查询字典
                IDictionary <string, object> pDic = WXGsMessageDA.CreateDicItems(pQueryItems);
                //查询获取dATATABLE
                DataTable dt = pDa.GetGsMessage(pDic, m_sdk.WXType);
                if (dt == null || dt.Rows.Count == 0)
                {
                    EGExceptionOperator.ThrowX <Exception>("缺少群发消息数据", EGActionCode.缺少目标数据);
                }

                pList = CommonFunction.GetEntitiesFromDataTable <T>(dt);
            });
            return(pList);
        }
Exemplo n.º 23
0
        /// <summary>
        /// 根据用户OpenID进行群发消息
        /// </summary>
        /// <param name="messageid"></param>
        /// <param name="groupId"></param>
        /// <param name="mediaId"></param>
        /// <param name="content"></param>
        /// <param name="messageType"></param>
        public void SendGroupMessageByOpenID(string messageid, string userId, string mediaId, string content, string messageType, string sex)
        {
            this.ExecuteTryCatch(() =>
            {
                if (string.IsNullOrEmpty(mediaId) && string.IsNullOrEmpty(content))
                {
                    EGExceptionOperator.ThrowX <Exception>("請輸入發送內容", EGActionCode.缺少必要参数);
                }
                //从缓存中读取微信用户缓存
                WCUserServiceLocal <WeChatUser> pUserService = new WCUserServiceLocal <WeChatUser>();
                List <WeChatUser> pList   = pUserService.GetWXUsersCache();
                List <string> pListOpenID = new List <string>();
                //筛选条件——以后扩展为动态条件,暂时只支持性别
                if (sex == "1" || sex == "2")
                {
                    int iSex = Convert.ToInt16(sex);
                    pList    = pList.Where(pEn => pEn.sex == iSex).ToList();
                }
                //
                foreach (WeChatUser pUser in pList)
                {
                    if (!pListOpenID.Contains(pUser.openid))
                    {
                        pListOpenID.Add(pUser.openid);
                    }
                }
                //转换为数组
                string[] pArray = pListOpenID.ToArray();
                //发送群发消息
                SendResult pResult = WeixinMessageSender.SendGroupMessageByOpenId(mediaId, content, messageType, pArray);
                if (!string.IsNullOrEmpty(pResult.errmsg) && pResult.errmsg != "send job submission success")
                {
                    EGExceptionOperator.ThrowX <Exception>(pResult.errmsg, pResult.errcode.ToString());
                }

                //发送完成后更新
                UpdateGsMessageAfterSend(messageid, userId, 1, string.Empty, pResult.errmsg);
            });
        }
Exemplo n.º 24
0
        /// <summary>
        /// 移动用户分组
        /// </summary>
        /// <param name="strListOpenID"></param>
        /// <param name="strTargetGroupID"></param>
        public void ChangeWXGroup(string strListOpenID, string strTargetGroupID)
        {
            this.ExecuteTryCatch(() =>
            {
                if (string.IsNullOrEmpty(strListOpenID))
                {
                    EGExceptionOperator.ThrowX <Exception>("请選擇移動目標用戶", EGActionCode.缺少必要参数);
                }
                if (string.IsNullOrEmpty(strTargetGroupID))
                {
                    EGExceptionOperator.ThrowX <Exception>("请選擇移動目標分組", EGActionCode.缺少必要参数);
                }

                int iGroupID = Convert.ToInt16(strTargetGroupID);
                //通过sdk获取accessToken
                string strAccessToken = Senparc.Weixin.MP.CommonAPIs.WeiXinSDKExtension.GetCurrentAccessToken();
                //初始化服务
                WXGroupServiceWeChat pGroupServiceWX         = new WXGroupServiceWeChat();
                WXGroupServiceLocal pGroupServiceLocal       = new WXGroupServiceLocal();
                WCUserServiceLocal <WeChatUser> pUserService = new WCUserServiceLocal <WeChatUser>();

                //将前端生成json串转为openID集合
                List <string> pListOpenID = CommonFunction.FromJsonTo <List <string> >(strListOpenID);
                //遍历更新微信端移动用户分组
                foreach (string openID in pListOpenID)
                {
                    Senparc.Weixin.MP.Entities.WxJsonResult pResult = pGroupServiceWX.MemberUpdate(strAccessToken, openID, iGroupID);
                    if (pResult.errcode != Senparc.Weixin.ReturnCode.请求成功)
                    {
                        EGExceptionOperator.ThrowX <Exception>(pResult.errmsg, EGActionCode.未知错误);
                    }
                }
                //更新用户新分组信息至数据库,并清空缓存
                pUserService.UpdateWCUserForGroupID(pListOpenID, iGroupID);
                //根据用户新分组信息,同步分组表信息,并清空缓存
                pGroupServiceLocal.ReloadWCGroupFromUser();
            });
        }
Exemplo n.º 25
0
        /// <summary>
        /// 同步微信用户数据
        /// </summary>
        public void ReLoadAllWeChatUser()
        {
            List <UserInfoJson> pList = new List <UserInfoJson>();

            this.ExecuteTryCatch(() =>
            {
                //通过sdk获取accessToken
                string strAccessToken = Senparc.Weixin.MP.CommonAPIs.WeiXinSDKExtension.GetCurrentAccessToken();
                //初始化服務
                WCUserServiceWeChat <UserInfoJson> pServiceWechat = new WCUserServiceWeChat <UserInfoJson>();
                WCUserServiceLocal <UserInfoJson> pServiceLocal   = new WCUserServiceLocal <UserInfoJson>();

                //首先从微信API加载所有用于信息
                pList = pServiceWechat.GetWCUserList(strAccessToken);
                if (pList == null || pList.Count == 0)
                {
                    EGExceptionOperator.ThrowX <Exception>("公众号缺少微信關注用戶", EGActionCode.缺少目标数据);
                }

                //再更新至数据库——由于可能无更新,所以受影响行数为0
                pServiceLocal.UpdateWCUserList <WeChatUser, UserInfoJson>(pList);
            });
        }
Exemplo n.º 26
0
        /// <summary>
        /// 根据分组进行群发消息
        /// </summary>
        /// <param name="messageid"></param>
        /// <param name="groupId"></param>
        /// <param name="mediaId"></param>
        /// <param name="content"></param>
        /// <param name="messageType"></param>
        public void SendGroupMessageByGroupID(string messageid, string userId, string groupId, string mediaId, string content, string messageType)
        {
            this.ExecuteTryCatch(() =>
            {
                if (string.IsNullOrEmpty(groupId))
                {
                    EGExceptionOperator.ThrowX <Exception>("請選中目標發送微信用戶組", EGActionCode.缺少必要参数);
                }
                if (string.IsNullOrEmpty(mediaId) && string.IsNullOrEmpty(content))
                {
                    EGExceptionOperator.ThrowX <Exception>("請輸入發送內容", EGActionCode.缺少必要参数);
                }
                //
                SendResult pResult = WeixinMessageSender.SendGroupMessageByGroupId(groupId, mediaId, content, messageType);
                if (!string.IsNullOrEmpty(pResult.errmsg) && pResult.errmsg != "send job submission success")
                {
                    EGExceptionOperator.ThrowX <Exception>(pResult.errmsg, pResult.errcode.ToString());
                }

                //发送完成后更新
                UpdateGsMessageAfterSend(messageid, userId, 2, groupId, pResult.errmsg);
            });
        }
Exemplo n.º 27
0
        ///// <summary>
        ///// 获取微信用户本地数据,来源自缓存
        ///// </summary>
        ///// <param name="iGroupID"></param>
        ///// <returns></returns>
        //public List<WeChatUser> GetWCUserList_Cache(int iGroupID)
        //{
        //    List<WeChatUser> pList = new List<WeChatUser>();
        //    this.ExecuteTryCatch(() =>
        //   {
        //       //从缓存中获取所有微信用户数据集合
        //       WCUserServiceLocal<WeChatUser> pUserService = new WCUserServiceLocal<WeChatUser>();
        //       pList = pUserService.GetWXUsersCache();

        //       //当GroupID为-1时,即加载全部用户
        //       if (iGroupID != -1)
        //       {
        //           //生成查询参数队列
        //           Queue<QueryEntity> paramQue = new Queue<QueryEntity>();
        //           paramQue.Enqueue(new QueryEntity("groupid", iGroupID, true, false));

        //           //查询目标分组下的用户数据
        //           IQueryable<WeChatUser> pQueryable = CommonFunction.QueryEnumerable<WeChatUser>(pList, paramQue);
        //           pList = pQueryable.ToList<WeChatUser>();
        //       }

        //   });
        //    return pList;
        //}
        /// <summary>
        /// 查询微信用户本地数据,来源自缓存,并适合前端分页
        /// </summary>
        /// <param name="iPageIndex"></param>
        /// <param name="iRowCountInPage"></param>
        /// <param name="filterString"></param>
        /// <returns></returns>
        public List <WeChatUser> QueryWCUserList_Cache(int iPageIndex, int iRowCountInPage, string filterString, ref int iRecordCount)
        {
            List <WeChatUser> pList = new List <WeChatUser>();
            int iRcCount            = -1;

            this.ExecuteTryCatch(() =>
            {
                if (!string.IsNullOrEmpty(filterString))
                {
                    //转换前端查询目标
                    List <object> pQueryItems = CommonFunction.FromJsonTo <List <object> >(filterString);
                    //创建查询参数队列
                    Queue <QueryEntity> pQue = WeChatUser.Query2(pQueryItems);
                    //查询微信用户本地数据,来源自缓存
                    pList = QueryWCUserList_Cache(pQue);
                }
                else
                {
                    //查询微信用户本地数据,来源自缓存
                    pList = QueryWCUserList_Cache(null);
                }

                if (pList == null || pList.Count == 0)
                {
                    EGExceptionOperator.ThrowX <Exception>("缺少微信用戶數據", EGActionCode.缺少目标数据);
                }
                //查询目标总记录数
                iRcCount = pList.Count;

                ////受限总共显示记录数,由服务端控制,暂时写死2000条,现行最大记录可以去到1万条json记录,扩展jsonresult可以去到50万条
                //pList = CommonFunction.SubListForTable<WeChatUser>(pList, 2000);
                //筛选目标页记录数
                pList = CommonFunction.SubListForTable <WeChatUser>(pList, iPageIndex, iRowCountInPage);
            });
            iRecordCount = iRcCount;
            return(pList);
        }
Exemplo n.º 28
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="Request"></param>
        /// <param name="pServerPath"></param>
        /// <param name="pResult"></param>
        protected void LoadFileFromRequestMulti <T>(HttpRequestBase Request, string pServerPath, List <T> pResult, bool pUseRealName = false)
            where T : IFileUploadResult, new()
        {
            //if (pServerPath.StartsWith("/"))
            //    pServerPath = pServerPath.Substring(1, pServerPath.Length - 1);
            //   Images/WXResources/
            string pPathR = pServerPath;
            //   Images\WXResources\
            string pPathA = pServerPath.Replace("/", @"\");
            // xxx
            string pFileName = string.Empty;
            // mp4
            string pFormatName = string.Empty;

            T pT;

            foreach (string fileName in Request.Files)
            {
                //创建新对象
                pT = new T();

                HttpPostedFileBase file = Request.Files[fileName];
                if (file == null)
                {
                    continue;
                    //msg = "请选择文件";
                    //EGExceptionOperator.ThrowX<Exception>(msg, EGActionCode.缺少必要参数);
                }
                //Save file content goes here
                ////使用源名稱
                //if (pUseRealName)
                //{
                //    pT.FileName = file.FileName;
                //}
                //else
                //{
                //    pT.FileName = DateTime.Now.Ticks.ToString();
                //}
                if (file != null && file.ContentLength > 0)
                {
                    // D:\EM_Project\WeChat\Standard\trunk\EG.WeChat.Standard\EG.WeChat.Web\Images\WXResources
                    var originalDirectory = new DirectoryInfo(string.Format("{0}", System.Web.HttpContext.Current.Server.MapPath(pPathA)));

                    // D:\EM_Project\WeChat\Standard\trunk\EG.WeChat.Standard\EG.WeChat.Web\Images\WXResources
                    //string pathString = System.IO.Path.Combine(originalDirectory.ToString(), "WXResources");
                    string pathString = originalDirectory.ToString();

                    //xxxx.mp4
                    var fileName1 = Path.GetFileName(file.FileName);
                    // xxxx
                    pFileName = fileName1.Substring(fileName1.LastIndexOf("\\") + 1, (fileName1.LastIndexOf(".") - fileName1.LastIndexOf("\\") - 1));
                    // mp4
                    pFormatName = fileName1.Substring(fileName1.LastIndexOf(".") + 1, (fileName1.Length - fileName1.LastIndexOf(".") - 1));   //扩展名
                    // 234878234312.mp4 如果不使用源名稱,則使用datetime Ticks作為名稱
                    if (!pUseRealName)
                    {
                        pFileName = DateTime.Now.Ticks.ToString();
                        fileName1 = string.Format("{0}.{1}", pFileName, pFormatName);
                    }

                    bool isExists = System.IO.Directory.Exists(pathString);

                    if (!isExists)
                    {
                        System.IO.Directory.CreateDirectory(pathString);
                    }

                    var path = string.Format("{0}\\{1}", pathString, fileName1);

                    try
                    {
                        file.SaveAs(path);
                    }
                    catch
                    {
                        //msg = "文件上传失败";
                        //EGExceptionOperator.ThrowX<Exception>(msg, EGActionCode.文件上传失败);
                        continue;
                    }

                    pT.APath      = path;
                    pT.RPath      = string.Format("{0}/{1}", pPathR, fileName1);
                    pT.FileName   = pFileName;
                    pT.FormatName = pFormatName;

                    pResult.Add(pT);
                }
            }
            if (pResult == null || pResult.Count == 0)
            {
                string msg = "文件上传失败";
                EGExceptionOperator.ThrowX <Exception>(msg, EGActionCode.文件上传失败);
            }
        }