/// <summary> /// 设置企业号应用 /// </summary> /// <param name="data"></param> //[AllowAnonymous] //[HttpPost] public ActionResult SetAppInfo(SetAppPostData data, string Id) { //更新SysWechatConfig数据库 //验证错误 if (!BeforeAddOrUpdate(data, Id) || !ModelState.IsValid) { return(Json(GetErrorJson(), JsonRequestBehavior.AllowGet)); } var objModel = sys.Repository.GetByKey(int.Parse(Request["ConfigID"])); objModel.WeixinCorpId = Request["CorpID"]; objModel.WeixinCorpSecret = Request["Secret"]; objModel.WelcomeMessage = Request["Welcome"]; sys.Repository.Update(objModel, new List <string>() { "WeixinCorpId", "WeixinCorpSecret", "WelcomeMessage" }); var strToken = rtntoken(int.Parse(data.agentid)); if (!string.IsNullOrEmpty(Request["MediaID"])) { data.logo_mediaid = Request["MediaID"]; } if (string.IsNullOrEmpty(data.redirect_domain)) { data.redirect_domain = string.Empty; } AppApi.SetApp(strToken, data); //清理缓存 if (WeChatCommonService.lstDepartment != null) { cacheManager.Remove("DepartmentList"); } if (WeChatCommonService.lstTag != null) { cacheManager.Remove("TagItem"); } if (WeChatCommonService.lstUser != null) { cacheManager.Remove("UserItem"); } if (CommonService.lstSysWeChatConfig != null) { cacheManager.Remove("SysWeChatConfig"); } return(Json(doJson(null))); }
public void SetAppTest() { var accessToken = AccessTokenContainer.GetToken(_corpId); SetAppPostData date = new SetAppPostData() { agentid = "1", description = "test", isreportenter = 0, isreportuser = 0, logo_mediaid = "1muvdK7W8cjLfNqj0hWP89-CEhZNOVsktCE1JHSTSNpzTf7cGOXyDin_ozluwNZqi", name = "Test", redirect_domain = "www.weiweihi.com" }; var result = AppApi.SetApp(accessToken, date); Assert.AreEqual(result.errcode, ReturnCode_QY.请求成功); }
public void SetAppTest() { var accessToken = AccessTokenContainer.GetToken(_corpId, base._corpSecret); SetAppPostData date = new SetAppPostData() { agentid = "2",//"100" + DateTime.Now.ToString("yyMMddHHMM"), report_location_flag = "1", //logo_mediaid = "1muvdK7W8cjLfNqj0hWP89-CEhZNOVsktCE1JHSTSNpzTf7cGOXyDin_ozluwNZqi", name = "单元测试添加" + DateTime.Now.ToString("yyMMddHHMM"), description = "test", redirect_domain = "https://sdk.weixin.senparc.com", //isreportenter = 0, isreportuser = 1, home_url = "weixin.senparc.com" }; var result = AppApi.SetApp(accessToken, date); Assert.AreEqual(result.errcode, ReturnCode_Work.请求成功); }
/// <summary> /// 设置企业号应用 /// </summary> /// <param name="data"></param> //[AllowAnonymous] //[HttpPost] public ActionResult SetAppInfo(SetAppPostData data, string Id) { //更新SysWechatConfig数据库 //验证错误 if (!BeforeAddOrUpdate(data, Id) || !ModelState.IsValid) { return(Json(GetErrorJson(), JsonRequestBehavior.AllowGet)); } #region 更新菜单 var loginUser = (SysUser)Session["UserInfo"]; var objModel = sys.Repository.GetByKey(int.Parse(Request["ConfigID"])); var menuModel = _sysMenuService.GetMenusByUserID(loginUser, null).Where(a => a.AppId == int.Parse(Request["ConfigID"]) && a.NavigateUrl.Equals("/")).FirstOrDefault(); if (menuModel != null) { menuModel.MenuName = data.name; menuModel.MenuTitle = data.name; _sysMenuService.Repository.Update(menuModel); } #endregion var Config = WeChatCommonService.GetWeChatConfigByID(int.Parse(Request["ConfigID"])); #region 步到微信 //var strToken = Rtntoken(int.Parse(data.agentid)); var strToken = WeChatCommonService.GetWeiXinToken(Config.Id); if (!string.IsNullOrEmpty(Request["MediaID"])) { data.logo_mediaid = Request["MediaID"]; } if (string.IsNullOrEmpty(data.redirect_domain)) { data.redirect_domain = string.Empty; } AppApi.SetApp(strToken, data); #endregion #region 存DB var objNewModel = new SysWechatConfig(); #region 从微信获取App logo, 存入objNewModel try { GetAppInfoResult result = AppApi.GetAppInfo(strToken, int.Parse(Config.WeixinAppId)); objNewModel.CoverUrl = result.square_logo_url; } catch (Exception ex) { _Logger.Error("an error occurd when get app logo :{0}", ex); } #endregion var lst = new List <string>(); objNewModel.Id = objModel.Id; objNewModel.AppName = data.name; if (Request["CorpID"] != objModel.WeixinCorpId && !string.IsNullOrEmpty(Request["Secret"])) { objNewModel.WeixinCorpId = Request["CorpID"]; } if (Request["Secret"] != objModel.WeixinCorpSecret && Request["Secret"] != "******" && !string.IsNullOrEmpty(Request["Secret"])) { objNewModel.WeixinCorpSecret = Request["Secret"]; } if (Request["Welcome"] != objModel.WelcomeMessage) { objNewModel.WelcomeMessage = Request["Welcome"]; } if (Request["Token"] != objModel.WeixinToken && Request["Token"] != "******" && !string.IsNullOrEmpty(Request["Token"])) { objNewModel.WeixinToken = Request["Token"]; } if (Request["EncodingAESKey"] != objModel.WeixinEncodingAESKey && Request["EncodingAESKey"] != "******" && !string.IsNullOrEmpty(Request["EncodingAESKey"])) { objNewModel.WeixinEncodingAESKey = Request["EncodingAESKey"]; } sys.Repository.Update(objNewModel); #endregion #region 清理缓存 //清理缓存 if (WeChatCommonService.lstDepartment(AccountManageID) != null) { cacheManager.Remove("DepartmentList"); } if (WeChatCommonService.lstTag(AccountManageID) != null) { cacheManager.Remove("TagItem"); } if (WeChatCommonService.lstUser(AccountManageID) != null) { cacheManager.Remove("UserItem" + AccountManageID); } if (WeChatCommonService.lstSysWeChatConfig != null) { cacheManager.Remove("SysWeChatConfig"); } var newMenus = _sysMenuService.GetMenusByUserID(loginUser, null); loginUser.Menus = newMenus; Session["UserInfo"] = loginUser; #endregion return(Json(doJson(null))); }