Esempio n. 1
0
        /// <summary>
        /// 获取应用套件令牌。
        /// 先从本地缓存获取,没有则从微信端获取。
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="suiteId"></param>
        /// <param name="suiteSecret"></param>
        /// <param name="suiteTicket"></param>
        /// <param name="errMessage"></param>
        /// <returns></returns>
        public static string GetSuiteToken(this TokenManager manager, string suiteId, string suiteSecret, string suiteTicket, out string errMessage)
        {
            errMessage = string.Empty;
            string cacheKey           = string.Format("SUITETOKEN:{0}:{1}:{2}", suiteId, suiteSecret, suiteTicket);
            string suite_access_token = CacheManager.Instance().Get <string>(cacheKey);

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

            var request = new GetSuiteTokenRequest();

            request.suite_id     = suiteId;
            request.suite_secret = suiteSecret;
            request.suite_ticket = suiteTicket;
            var result = ApiHelper.Instance().GetSuiteToken(request);

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

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

            return(suite_access_token);
        }
Esempio n. 2
0
        /// <summary>
        /// 获取应用套件令牌
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="suite_id"></param>
        /// <param name="suite_secret"></param>
        /// <param name="suite_ticket"></param>
        /// <returns></returns>
        public static GetSuiteTokenResult GetSuiteToken(this ApiHelper helper, string suite_id, string suite_secret, string suite_ticket)
        {
            GetSuiteTokenRequest request = new GetSuiteTokenRequest();

            request.suite_id     = suite_id;
            request.suite_secret = suite_secret;
            request.suite_ticket = suite_ticket;
            return(helper.GetSuiteToken(request));
        }
Esempio n. 3
0
        /// <summary>
        /// 获取应用套件令牌
        /// 该Api.Weixin用于获取应用套件令牌(suite_access_token)。
        /// 注1:由于应用提供商可能托管了大量的企业号,其安全问题造成的影响会更加严重,故Api.Weixin中除了合法来源IP校验之外,还额外增加了1项安全策略:
        /// 获取suite_access_token时,还额外需要suite_ticket参数(请永远使用最新接收到的suite_ticket)。suite_ticket由企业号后台定时推送给应用套件,并定时更新。
        /// 注2:通过本接口获取的accesstoken不会自动续期,每次获取都会自动更新。
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        public static GetSuiteTokenResult GetSuiteToken(this ApiHelper helper, GetSuiteTokenRequest request)
        {
            string url = string.Format("{0}service/get_suite_token", baseUrl);

            return(HttpHelper.HttpPost.GetJsonResult <GetSuiteTokenRequest, GetSuiteTokenResult>(url, request));
        }