Beispiel #1
0
        /// <summary>
        /// 同步微信用户数据,并且重新读取本地数据
        /// </summary>
        /// <param name="returnResult"></param>
        /// <returns></returns>
        public List <WeChatUser> ReLoadAllWeChatUser(bool returnResult)
        {
            List <UserInfoJson> pList       = new List <UserInfoJson>();
            List <WeChatUser>   pListResult = new List <WeChatUser>();

            this.ExecuteTryCatch(() =>
            {
                //同步微信用户数据
                ReLoadAllWeChatUser();

                WCUserServiceLocal <WeChatUser> pServiceLocal2 = new WCUserServiceLocal <WeChatUser>();
                //由于有备注名称信息,需要重新从数据库读取,以后升级至缓存机制
                pListResult = pServiceLocal2.GetWXUsersFromDB();
            });
            return(pListResult);
        }
Beispiel #2
0
        /// <summary>
        /// 查询微信用户本地数据,来源自缓存
        /// </summary>
        /// <param name="paramQue"></param>
        /// <returns></returns>
        public List <WeChatUser> QueryWCUserList_Cache(Queue <QueryEntity> paramQue)
        {
            //从缓存中获取所有微信用户数据集合
            WCUserServiceLocal <WeChatUser> pUserService = new WCUserServiceLocal <WeChatUser>();
            List <WeChatUser> pList = pUserService.GetWXUsersCache();

            if (paramQue == null || paramQue.Count == 0)
            {
                return(pList);
            }

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

            pList = pQueryable.ToList <WeChatUser>();
            return(pList);
        }
Beispiel #3
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);
            });
        }
Beispiel #4
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();
            });
        }
Beispiel #5
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);
            });
        }