Ejemplo n.º 1
0
        public void Run(string appId, PerformContext context = null)
        {
            context.WriteLine("开始刷新AccessToken【{0}】...", appId);
            var resp = ComponentApi.RefreshAccessToken(_componentAccessToken, _componentAppId, appId, _redis.StringGet(CacheKey.UserRefreshTokenPrefix + appId));

            if (resp.ErrCode == 0)
            {
                _redis.StringSet(CacheKey.UserAccessTokenPrefix + appId, resp.AuthorizerAccessToken, new TimeSpan(0, 0, resp.ExpiresIn));
                _redis.StringSet(CacheKey.UserRefreshTokenPrefix + appId, resp.AuthorizerRefreshToken);
                context.WriteLine("刷新AccessToken【{0}】成功...", appId);
            }
            else
            {
                context.WriteLine("刷新AccessToken【{0}】失败:{1}...", appId, resp.ErrMsg);
                throw new ServiceException(resp.ErrCode, resp.ErrMsg);
            }
        }