Exemple #1
0
        /// <summary>
        /// 获取企业号access_token。
        /// 先从本地缓存获取,没有则从微信端获取。
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="suiteId"></param>
        /// <param name="authCorpId">授权的企业号ID</param>
        /// <param name="permanentCode">永久授权码</param>
        /// <param name="suiteAccessToken"></param>
        /// <param name="errMessage"></param>
        /// <returns></returns>
        public static string GetCorpToken(this TokenManager manager, string suiteId, string authCorpId, string permanentCode,
                                          string suiteAccessToken, out string errMessage)
        {
            errMessage = string.Empty;
            string cacheKey     = string.Format("CORPTOKEN:{0}:{1}:{2}", suiteId, authCorpId, suiteAccessToken);
            string access_token = CacheManager.Instance().Get <string>(cacheKey);

            if (!string.IsNullOrEmpty(access_token))
            {
                return(access_token);
            }

            var request = new GetCorpTokenRequest();

            request.suite_id       = suiteId;
            request.auth_corpid    = authCorpId;
            request.permanent_code = permanentCode;
            var result = ApiHelper.Instance().GetCorpToken(suiteAccessToken, request);

            if (result.errcode != 0)
            {
                errMessage = string.Format("GetCorpToken: errcode:{0},errmsg:{1}", result.errcode, result.errmsg);
                return(access_token);
            }

            //缓存corp_token
            access_token = result.access_token;
            CacheManager.Instance().Set(cacheKey, access_token, result.expires_in);

            return(access_token);
        }
Exemple #2
0
        /* 2016.06.03 service/set_agent 以及 service/get_agent 接口下线。 by wzx
         * /// <summary>
         * /// 获取企业号应用
         * /// 该API用于获取授权方的企业号某个应用的基本信息,包括头像、昵称、帐号类型、认证类型、可见范围等信息
         * /// </summary>
         * /// <param name="helper"></param>
         * /// <param name="suite_id">套件ID</param>
         * /// <param name="auth_corpid">授权方企业ID</param>
         * /// <param name="permanent_code">永久授权码</param>
         * /// <param name="agentid">授权方应用ID</param>
         * /// <param name="suite_access_token"></param>
         * /// <returns></returns>
         * public static GetAgentResult GetAgent(this ApiHelper helper, string suite_id, string auth_corpid, string permanent_code,
         *  string agentid, string suite_access_token)
         * {
         *  var request = new GetAgentRequest();
         *  request.suite_id = suite_id;
         *  request.auth_corpid = auth_corpid;
         *  request.permanent_code = permanent_code;
         *  request.agentid = agentid;
         *  return helper.GetAgent(suite_access_token, request);
         * }
         * /// <summary>
         * /// 获取企业号应用
         * /// 该API用于获取授权方的企业号某个应用的基本信息,包括头像、昵称、帐号类型、认证类型、可见范围等信息
         * /// </summary>
         * /// <param name="helper"></param>
         * /// <param name="request"></param>
         * /// <param name="suite_access_token"></param>
         * /// <returns></returns>
         * public static GetAgentResult GetAgent(this ApiHelper helper, string suite_access_token, GetAgentRequest request)
         * {
         *  string url = string.Format("{0}service/get_agent?suite_access_token={1}", baseUrl, suite_access_token);
         *  return HttpHelper.HttpPost.GetJsonResult<GetAgentRequest, GetAgentResult>(url, request);
         * }
         * /// <summary>
         * /// 设置企业号应用
         * /// 该API用于设置授权方的企业应用的选项设置信息,如:地理位置上报等。注意,获取各项选项设置信息,需要有授权方的授权。
         * /// </summary>
         * /// <param name="helper"></param>
         * /// <param name="request"></param>
         * /// <param name="suite_access_token"></param>
         * /// <returns></returns>
         * public static SetAgentResult SetAgent(this ApiHelper helper, string suite_access_token, SetAgentRequest request)
         * {
         *  string url = string.Format("{0}service/set_agent?suite_access_token={1}", baseUrl, suite_access_token);
         *  return HttpHelper.HttpPost.GetJsonResult<SetAgentRequest, SetAgentResult>(url, request);
         * }*/
        /// <summary>
        /// 获取企业号access_token
        /// 应用提供商在取得企业号的永久授权码并完成对企业号应用的设置之后,便可以开始通过调用企业接口(详见企业接口文档)来运营这些应用。
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="request"></param>
        /// <param name="suite_access_token"></param>
        /// <returns></returns>
        public static GetCorpTokenResult GetCorpToken(this ApiHelper helper, string suite_access_token, GetCorpTokenRequest request)
        {
            string url = string.Format("{0}service/get_corp_token?suite_access_token={1}", baseUrl, suite_access_token);

            return(HttpHelper.HttpPost.GetJsonResult <GetCorpTokenRequest, GetCorpTokenResult>(url, request));
        }