public MessageController( IArticleInfoService objServiceArticle, IAttachmentsItemService attachmentsItemService, ISysWechatConfigService SysWechatConfigService, IWechatMPUserService WechatMPUserService, IMessageLogService messageLogService, IAddressBookService addressBookService, IWeChatUserRequestMessageLogHandler WeChatUserRequestMessageLogHandler) : base(objServiceArticle) { // _objService = objService; //_messageService = objService; _objServiceArticle = objServiceArticle; _attachmentsItemService = attachmentsItemService; _WechatMPUserService = WechatMPUserService; _SysWechatConfigService = SysWechatConfigService; _WeChatUserRequestMessageLogHandler = WeChatUserRequestMessageLogHandler; _MessageLogService = messageLogService; _addressBookService = addressBookService; // _previewMessageLogService = previewMessageLogService; // AppId = (int)CategoryType.Undefined; ViewBag.AppId = AppId; ViewBag.KeywordTypes = new Dictionary <string, string>() { { WechatMessageLogType.file.ToString(), "文件" }, { WechatMessageLogType.image.ToString(), "图片" }, { WechatMessageLogType.news.ToString(), "图文" }, { WechatMessageLogType.text.ToString(), "文本" }, { WechatMessageLogType.video.ToString(), "视频" }, { WechatMessageLogType.voice.ToString(), "语音" } }; }
public static SendResult SendMsgMP(List <ArticleInfoView> lstContent, SearchUserMPView searchCondition, string[] PreviewOpenids /*Preview use*/, bool isKefu = false) { string strTags = ""; //ToAll string[] userOpenIds = null; if (searchCondition.Group == null) { searchCondition.Group = -2; } if (searchCondition.Sex < 0 && searchCondition.Province == "-1") { if (searchCondition.Group == -2) { // ToAll strTags = "-1"; } else { // Send By Tag strTags = searchCondition.Group.ToString(); } } else { // Send By OpenId IWechatMPUserService _WechatMPUserService = EngineContext.Current.Resolve <IWechatMPUserService>(); var objConfig = WeChatCommonService.GetWeChatConfigByID(lstContent[0].AppId.Value); userOpenIds = _WechatMPUserService.GetUserBySearchCondition(searchCondition, objConfig.AccountManageId.Value).Select(u => u.OpenId).ToArray(); } string strType = ((WechatMessageLogType)lstContent[0].ContentType).ToString(); return(SendMsg(strType, "", lstContent, strTags, userOpenIds, PreviewOpenids, isKefu)); }
public WentangAPIController(IWechatMPUserService addressBookServiceService, IWechatMPUserService WechatMPUserService, IFocusHistoryService FocusHistoryService, IQrCodeService QrCodeService) : base(addressBookServiceService) { _WechatMPUserService = WechatMPUserService; _QrCodeService = QrCodeService; _FocusHistoryService = FocusHistoryService; }
public WechatUserRequestMessageLogController(IWechatUserRequestMessageLogService objService, IAddressBookService addressBookService, IWechatUserRequestMessageTagService requestMessageTagService, IWechatMPUserService wechatMPUserService) : base(objService) { _requestMessageLogService = objService; _addressBookService = addressBookService; _requestMessageTagService = requestMessageTagService; _wechatMPUserService = wechatMPUserService; ViewBag.MessageTypes = GetCurrentSupportMsgTypes(); }
public ArticleCommentController(IArticleCommentService newsService, IArticleCommentThumbUpService articleCommentThumbUpService, IWechatMPUserService wechatMPUserService, IAddressBookService addressBookService, IArticleInfoService articleInfoService) : base(newsService) { this._articleCommentThumbUpService = articleCommentThumbUpService; this._articleCommentService = newsService; this._wechatMPUserService = wechatMPUserService; this._addressBookService = addressBookService; this._articleInfoService = articleInfoService; }
/// <summary> /// 同步微信用户 /// </summary> /// <param name="WeixinOpenId"></param> /// <param name="userInfo"></param> /// <param name="config"></param> public static void SycUserFromWeixinMP(string WeixinOpenId, ref WechatMPUser userInfo, SysWechatConfig config) { Logger.Debug("SycUserFromWeixin"); Innocellence.Weixin.MP.AdvancedAPIs.User.BatchGetUserInfoData user = new Innocellence.Weixin.MP.AdvancedAPIs.User.BatchGetUserInfoData { openid = WeixinOpenId, lang = Language.zh_CN.ToString() }; var result = Innocellence.Weixin.MP.AdvancedAPIs.UserApi.BatchGetUserInfo(config.WeixinAppId, config.WeixinCorpSecret, new List <Innocellence.Weixin.MP.AdvancedAPIs.User.BatchGetUserInfoData> { user }); Logger.Debug("SycUserFromWeixin result"); if (result != null && result.user_info_list != null) { Logger.Debug("result count :{0}", result.user_info_list.Count); var objuserInfo = result.user_info_list.Select(a => WechatMPUserView.ConvertWeChatUserToMpUser(a, config.AccountManageId.Value, config.Id)).ToList().FirstOrDefault(); if (userInfo == null) { userInfo = objuserInfo; } if (objuserInfo != null) { Logger.Debug("SycUserFromWeixin userInfo: " + userInfo.OpenId + userInfo.NickName); objuserInfo.AccountManageId = config.AccountManageId; if (objuserInfo.SubScribe == 0) //未关注 { objuserInfo.Id = userInfo.Id; objuserInfo.IsCanceled = true; userInfo = objuserInfo; } else { objuserInfo.Id = userInfo.Id; } Logger.Debug("SycUserFromWeixin userInfo id: {0}, SubScribe: {1}", objuserInfo.Id, objuserInfo.SubScribe); IWechatMPUserService wechatMPUserService = EngineContext.Current.Resolve <IWechatMPUserService>(); wechatMPUserService.RegistToWeiXin(objuserInfo); Logger.Debug("SycUserFromWeixin userInfo updated."); } else { Logger.Debug("SycUserFromWeixin Error objuserInfo=null.{0}", WeixinOpenId); } } }
//记录用户行为 //Innocellence.WeChat.Domain.Common.WebRequestPost wr = new Innocellence.WeChat.Domain.Common.WebRequestPost(); public ArticleInfoController(IArticleInfoService objService, IArticleThumbsUpService articleThumbsUpService, IMessageService messageService, IWechatMessageLogService messageLogService, IAutoReplyService autoReplyService, IWechatPreviewMessageLogService previewMessageLogService, IWechatMPUserService wechatMPUserService, IArticleInfoReadHistoryService articleInfoReadHistoryService ) : base(objService) { _objService = objService; _messageService = messageService; _articleThumbsUpService = articleThumbsUpService; _messageLogService = messageLogService; _autoReplyService = autoReplyService; _previewMessageLogService = previewMessageLogService; _wechatMPUserService = wechatMPUserService; _articleInfoReadHistoryService = articleInfoReadHistoryService; }
public async Task <ActionResult> BackLogin() { string returnUrl = Session["ReturnUrl"] as string; try { log.Error("Entering BackLogin, returnUrl=" + returnUrl); //ViewBag.ReturnUrl = returnUrl; if (Request["code"] != null) { string code = Request["code"].ToString(); string wechatid = Request["wechatid"].ToString(); log.Debug("code:" + code + " wechatid:" + wechatid); SysUser user = null; var weChatConfig = WeChatCommonService.GetWeChatConfigByID(int.Parse(wechatid)); if (weChatConfig.IsCorp.HasValue && !weChatConfig.IsCorp.Value) { var code1 = Innocellence.Weixin.MP.AdvancedAPIs.OAuthApi.GetAccessToken(weChatConfig.WeixinCorpId, weChatConfig.WeixinCorpSecret, code); IWechatMPUserService ser = EngineContext.Current.Resolve <IWechatMPUserService>(); WechatMPUser objUser = null; objUser = ser.Repository.Entities.Where(a => a.OpenId == code1.openid).FirstOrDefault(); log.Debug("MP objUser:"******"N" : "U") + " OpenID:" + code1.openid); //如果用户不存在就添加用户 if (objUser == null) { // var userinfo = Innocellence.Weixin.MP.AdvancedAPIs.UserApi.Info(weChatConfig.WeixinCorpId, weChatConfig.WeixinCorpSecret, code1.openid); // objUser = WechatMPUserView.ConvertWeChatUserToMpUser(userinfo, weChatConfig.AccountManageId.Value, weChatConfig.Id); // ser.Repository.Insert(objUser); lock (StaticLockObj) //防止插入多条数据 { objUser = ser.Repository.Entities.Where(a => a.OpenId == code1.openid).FirstOrDefault(); //为什么要重新查一次??因为有lock if (objUser == null) { WeChatCommonService.SycUserFromWeixinMP(code1.openid, ref objUser, weChatConfig); } } } if (objUser == null || objUser.IsCanceled == true || objUser.SubScribe == 0) //未关注 { log.Debug("未关注 OpenID:{0}", code1.openid); user = new SysUser() { UserName = code1.openid, WeChatUserID = "", Id = 0, Apps = new System.Collections.Generic.List <int>() { int.Parse(wechatid) } }; } else //已关注 { user = new SysUser() { UserName = objUser.NickName, WeChatUserID = objUser.OpenId, Id = objUser.Id, Apps = new System.Collections.Generic.List <int>() { int.Parse(wechatid) } }; } //var user = UserManager.Entities.FirstOrDefault(a => a.UserName == code1.UserId); } else { var Token = AccessTokenContainer.TryGetToken(weChatConfig.WeixinCorpId, weChatConfig.WeixinCorpSecret); log.Error("Token:" + Token); var code1 = OAuth2Api.GetUserId(Token, code); // BaseService<SysAddressBookMember> ser = new BaseService<SysAddressBookMember>(); IAddressBookService ser = EngineContext.Current.Resolve <IAddressBookService>(); if (string.IsNullOrEmpty(code1.UserId)) //没关注 { user = new SysUser() { UserName = code1.OpenId, WeChatUserID = "", Id = 0, Apps = new System.Collections.Generic.List <int>() { int.Parse(wechatid) } }; } else //已经关注 { var objUser = ser.Repository.Entities.Where(a => a.UserId == code1.UserId && a.DeleteFlag != 1).FirstOrDefault(); log.Debug("objUser:{1} UserID:{0} Status:{2}", code1.UserId, (objUser == null ? "N" : "U"), objUser == null ? "" : objUser.EmployeeStatus); if (objUser != null && (objUser.EmployeeStatus == "D" || objUser.EmployeeStatus == "U")) //离职或状态不明 { user = new SysUser() { UserName = objUser.UserId, WeChatUserID = "", Id = 0, Apps = new System.Collections.Generic.List <int>() { int.Parse(wechatid) } }; } else //已经关注 { //objUser = new SysAddressBookMember() { UserId = code1.UserId, Id = 0 }; if (objUser == null) { lock (StaticLockObjMP) //防止插入多条数据 { if (objUser == null) //lock后,重新查一次 { objUser = ser.Repository.Entities.Where(a => a.UserId == code1.UserId).FirstOrDefault(); } WeChatCommonService.SyncUserFromWechat(code1.UserId, ref objUser, weChatConfig); } } user = new SysUser() { UserName = objUser.UserName, WeChatUserID = objUser.UserId, Id = objUser.Id, Apps = new System.Collections.Generic.List <int>() { int.Parse(wechatid) } }; } } //var user = UserManager.Entities.FirstOrDefault(a => a.UserName == code1.UserId); } log.Debug("SignInNoDB UserID:{0} User:{1}", user.Id, user.UserName); await _authenticationService.SignInNoDB(user, true); //return Redirect(returnUrl); ////////登录日志 //////BaseService<Logs> objServLogs = new BaseService<Logs>(); //////objServLogs.Insert(new Logs() { LogCate = "WechatLogin", LogContent = "登录成功", CreatedUserID = objUser.WeChatUserID, CreatedUserName = objUser.WeChatUserID }); } //LogManager.GetLogger(this.GetType()).Error("strUrl:" + strUrl); var Ret = returnUrl + (returnUrl.IndexOf("?") > 0 ? "&_Callback=1" : "?_Callback=1"); log.Debug("Ret URL:{0}", Ret); return(Redirect(Ret)); } catch (Exception ex) { LogManager.GetLogger(this.GetType()).Error(ex, ex.Message); return(Redirect("/noCropPermission.html")); } // View(); }
public APIController(IWechatMPUserService addressBookServiceService) : base(addressBookServiceService) { }