Exemplo n.º 1
0
        /// <summary>
        /// 设置企业号应用
        /// 此App只能修改现有的并且有权限管理的应用,无法创建新应用(因为新应用没有权限)
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="data">设置应用需要Post的数据</param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// <returns></returns>
        public static WorkJsonResult SetApp(string accessToken, SetAppPostData data, int timeOut = Config.TIME_OUT)
        {
            //TODO:需要对SetAppPostData中的null值过滤
            string url = string.Format("https://qyapi.weixin.qq.com/cgi-bin/agent/set?access_token={0}", accessToken.AsUrlData());

            return(Post.PostGetJson <WorkJsonResult>(url, formData: null));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 设置企业号应用
        /// 此App只能修改现有的并且有权限管理的应用,无法创建新应用(因为新应用没有权限)
        /// </summary>
        /// <returns></returns>
        public JsonResult SetApp(SetAppPostData data, int timeOut = Config.TIME_OUT)
        {
            var    accessToken = _api.GetAccessToken();
            string url         = string.Format("https://qyapi.weixin.qq.com/cgi-bin/agent/set?access_token={0}", accessToken);

            return(Post <JsonResult>(url, data, timeOut));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 设置企业号应用
        /// 此App只能修改现有的并且有权限管理的应用,无法创建新应用(因为新应用没有权限)
        /// </summary>
        /// <param name="accessTokenOrAppKey">调用接口凭证(AccessToken)或AppKey(根据AccessTokenContainer.BuildingKey(corpId, corpSecret)方法获得)</param>
        /// <param name="data">设置应用需要Post的数据</param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// <returns></returns>
        public static QyJsonResult SetApp(string accessTokenOrAppKey, SetAppPostData data, int timeOut = Config.TIME_OUT)
        {
            return(ApiHandlerWapper.TryCommonApi(accessToken =>
            {
                string url = string.Format("https://qyapi.weixin.qq.com/cgi-bin/agent/set?access_token={0}", accessToken.AsUrlData());

                return Post.PostGetJson <QyJsonResult>(url, formData: null);
            }, accessTokenOrAppKey));
        }
Exemplo n.º 4
0
        /// <summary>
        /// 设置企业号应用
        /// 此App只能修改现有的并且有权限管理的应用,无法创建新应用(因为新应用没有权限)
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="data">设置应用需要Post的数据</param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// <returns></returns>
        public static WorkJsonResult SetApp(string accessToken, SetAppPostData data, int timeOut = Config.TIME_OUT)
        {
            string url = string.Format("https://qyapi.weixin.qq.com/cgi-bin/agent/set?access_token={0}", accessToken.AsUrlData());

            //对SetAppPostData中的null值过滤
            JsonSetting jsonSetting = new JsonSetting(true);

            return(CommonJsonSend.Send <WorkJsonResult>(accessToken, url, data, jsonSetting: jsonSetting));
        }
Exemplo n.º 5
0
        public static WorkJsonResult SetApp(string accessTokenOrAppKey, SetAppPostData data, int timeOut = WxConfig.TIME_OUT)
        {
            return(ApiHandlerWapper.TryCommonApi(accessToken =>
            {
                string url = WxConfig.ApiWorkHost + "/cgi-bin/agent/set?access_token={0}";

                //对SetAppPostData中的null值过滤
                JsonSetting jsonSetting = new JsonSetting(true);

                return CommonJsonSend.Send <WorkJsonResult>(accessToken, url, data, jsonSetting: jsonSetting);
            }, accessTokenOrAppKey));
        }
Exemplo n.º 6
0
        /// <summary>
        /// 【异步方法】设置企业号应用【QY移植修改】
        /// 此App只能修改现有的并且有权限管理的应用,无法创建新应用(因为新应用没有权限)
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="data">设置应用需要Post的数据</param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// <returns></returns>
        public static async Task <WorkJsonResult> SetAppAsync(string accessToken, SetAppPostData data, int timeOut = Config.TIME_OUT)
        {
            //TODO:需要对SetAppPostData中的null值过滤
            string url = string.Format("https://qyapi.weixin.qq.com/cgi-bin/agent/set?access_token={0}", accessToken.AsUrlData());

            //对SetAppPostData中的null值过滤
            JsonSetting jsonSetting = new JsonSetting(true);

            return(await CommonJsonSend.SendAsync <WorkJsonResult>(accessToken, url, data, jsonSetting : jsonSetting));

            //return await Post.PostGetJsonAsync<WorkJsonResult>(url, formData: null);
        }
Exemplo n.º 7
0
        /// <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)));
        }
Exemplo n.º 8
0
        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.请求成功);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 设置企业号应用
        /// 此App只能修改现有的并且有权限管理的应用,无法创建新应用(因为新应用没有权限)
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="data">设置应用需要Post的数据</param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// <returns></returns>
        public static WxJsonResult SetApp(string accessToken, SetAppPostData data, int timeOut = Config.TIME_OUT)
        {
            string url = string.Format("https://qyapi.weixin.qq.com/cgi-bin/agent/set?access_token={0}", accessToken);

            SerializerHelper serializerHelper = new SerializerHelper();
            var jsonString = serializerHelper.GetJsonString(data);

            using (var ms = new MemoryStream())
            {
                var bytes = Encoding.UTF8.GetBytes(jsonString);
                ms.Write(bytes, 0, bytes.Length);
                ms.Seek(0, SeekOrigin.Begin);

                return(Post.PostGetJson <WxJsonResult>(url, null, ms, timeOut: timeOut));
            }

            ////Post.PostGetJson<WxJsonResult>(url,null,)

            //return Get.GetJson<WxJsonResult>(url);
        }
Exemplo n.º 10
0
        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.请求成功);
        }
Exemplo n.º 11
0
        public bool BeforeAddOrUpdate(SetAppPostData objModal, string ID)
        {
            //后台校验 Go here..
            bool          validate     = true;
            StringBuilder errMsg       = new StringBuilder();
            string        departId     = Request["departmentAll"];
            string        errorMessage = string.Empty;

            if (!CheckRequire(objModal.name, "应用名称长度为2-16个字符。<br/>", out errorMessage))
            {
                validate = false;
                errMsg.Append(T(errorMessage));
            }
            if (!CheckLength(objModal.name, "应用名称长度太长。<br/>", 16, out errorMessage))
            {
                validate = false;
                errMsg.Append(T(errorMessage));
            }
            if (!CheckRequire(objModal.description, "功能介绍长度为4-120个字。<br/>", out errorMessage))
            {
                validate = false;
                errMsg.Append(T(errorMessage));
            }
            if (!CheckLength(objModal.description, "功能介绍长度太长。<br/>", 120, out errorMessage))
            {
                validate = false;
                errMsg.Append(T(errorMessage));
            }
            if (!CheckLength(objModal.redirect_domain, "域名长度太长。<br/>", 50, out errorMessage))
            {
                validate = false;
                errMsg.Append(T(errorMessage));
            }

            if (!CheckRequire(Request["CorpID"], "请填写CorpID。<br/>", out errorMessage))
            {
                validate = false;
                errMsg.Append(T(errorMessage));
            }
            if (!CheckLength(Request["CorpID"], "CorpID长度太长。<br/>", 150, out errorMessage))
            {
                validate = false;
                errMsg.Append(T(errorMessage));
            }
            if (!CheckRequire(Request["Secret"], "请填写Secret。<br/>", out errorMessage))
            {
                validate = false;
                errMsg.Append(T(errorMessage));
            }
            if (!CheckLength(Request["Secret"], "Secret长度太长。<br/>", 250, out errorMessage))
            {
                validate = false;
                errMsg.Append(T(errorMessage));
            }
            if (!validate)
            {
                ModelState.AddModelError("不正确的输入", errMsg.ToString());
            }

            return(validate);
        }
Exemplo n.º 12
0
        public static async Task <WorkJsonResult> SetAppAsync(string accessTokenOrAppKey, SetAppPostData data, int timeOut = WxConfig.TIME_OUT)
        {
            return(await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
            {
                //TODO:需要对SetAppPostData中的null值过滤
                string url = WxConfig.ApiWorkHost + "/cgi-bin/agent/set?access_token={0}";

                //对SetAppPostData中的null值过滤
                JsonSetting jsonSetting = new JsonSetting(true);

                return await CommonJsonSend.SendAsync <WorkJsonResult>(accessToken, url, data, jsonSetting: jsonSetting);
            }, accessTokenOrAppKey));
        }
Exemplo n.º 13
0
        /// <summary>
        /// 设置企业号应用
        /// 此App只能修改现有的并且有权限管理的应用,无法创建新应用(因为新应用没有权限)
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="data">设置应用需要Post的数据</param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// <returns></returns>
        public static QyJsonResult SetApp(string accessToken, SetAppPostData data, int timeOut = Config.TIME_OUT)
        {
            string url = string.Format("https://qyapi.weixin.qq.com/cgi-bin/agent/set?access_token={0}", accessToken.AsUrlData());

            return(Get.GetJson <QyJsonResult>(url));
        }
Exemplo n.º 14
0
        /// <summary>
        /// 【异步方法】设置企业号应用
        /// 此App只能修改现有的并且有权限管理的应用,无法创建新应用(因为新应用没有权限)
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="data">设置应用需要Post的数据</param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// <returns></returns>
        public static async Task <QyJsonResult> SetAppAsync(string accessToken, SetAppPostData data, int timeOut = Config.TIME_OUT)
        {
            string url = string.Format("https://qyapi.weixin.qq.com/cgi-bin/agent/set?access_token={0}", accessToken.AsUrlData());

            return(await Post.PostGetJsonAsync <QyJsonResult>(url, formData : null));
        }
Exemplo n.º 15
0
        /// <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)));
        }