/// <summary>
        /// 注册每个corpId和corpSecret,在调用高级接口时可以仅使用AppKey(由 AccessTokenContainer.BuildingKey() 方法获得)
        /// </summary>
        /// <param name="corpId"></param>
        /// <param name="corpSecret"></param>
        /// <param name="name">标记AccessToken名称(如微信公众号名称),帮助管理员识别。当 name 不为 null 和 空值时,本次注册内容将会被记录到 Senparc.Weixin.Config.SenparcWeixinSetting.Items[name] 中,方便取用。</param>
        public static void Register(string corpId, string corpSecret, string name = null)
        {
            //记录注册信息,RegisterFunc委托内的过程会在缓存丢失之后自动重试
            RegisterFunc = () =>
            {
                //using (FlushCache.CreateInstance())
                //{
                var bag = new AccessTokenBag()
                {
                    Name              = name,
                    CorpId            = corpId,
                    CorpSecret        = corpSecret,
                    ExpireTime        = DateTimeOffset.MinValue,
                    AccessTokenResult = new AccessTokenResult()
                };
                Update(BuildingKey(corpId, corpSecret), bag, null);
                return(bag);
                //}
            };
            RegisterFunc();

            if (!name.IsNullOrEmpty())
            {
                Senparc.Weixin.Config.SenparcWeixinSetting.Items[name].WeixinCorpId     = corpId;
                Senparc.Weixin.Config.SenparcWeixinSetting.Items[name].WeixinCorpSecret = corpSecret;
            }

            JsApiTicketContainer.Register(corpId, corpSecret);   //连带注册JsApiTicketContainer

            ProviderTokenContainer.Register(corpId, corpSecret); //连带注册ProviderTokenContainer
        }
Esempio n. 2
0
        public static void Register(string corpId, string corpSecret, string name = null)
        {
            //记录注册信息,RegisterFunc委托内的过程会在缓存丢失之后自动重试
            RegisterFunc = () =>
            {
                using (FlushCache.CreateInstance())
                {
                    var bag = new AccessTokenBag()
                    {
                        Name              = name,
                        CorpId            = corpId,
                        CorpSecret        = corpSecret,
                        ExpireTime        = DateTime.MinValue,
                        AccessTokenResult = new AccessTokenResult()
                    };
                    Update(BuildingKey(corpId, corpSecret), bag);
                    return(bag);
                }
            };
            RegisterFunc();

            JsApiTicketContainer.Register(corpId, corpSecret);   //连带注册JsApiTicketContainer

            ProviderTokenContainer.Register(corpId, corpSecret); //连带注册ProviderTokenContainer
        }