Ejemplo n.º 1
0
        public void Run(string code, PerformContext context)
        {
            context.WriteLine("开始处理新增和更新代理授权【Code: {0}】...", code);
            var authInfo = ComponentApi.GetAuthInfo(_componentAccessToken, _componentAppId, code);

            if (authInfo.ErrCode == 0)
            {
                _redis.StringSet(CacheKey.UserAccessTokenPrefix + authInfo.AuthorizationInfo.AuthorizerAppId, authInfo.AuthorizationInfo.AuthorizerAccessToken, new TimeSpan(0, 0, authInfo.AuthorizationInfo.ExpiresIn));
                _redis.StringSet(CacheKey.UserRefreshTokenPrefix + authInfo.AuthorizationInfo.AuthorizerAppId, authInfo.AuthorizationInfo.AuthorizerRefreshToken);
                var now     = (DateTime.UtcNow.Ticks - 621355968000000000) / 10000000;
                var message = new UserMessageRequsetXml("<xml></xml>")
                {
                    AppId        = authInfo.AuthorizationInfo.AuthorizerAppId,
                    MsgType      = "event",
                    Event        = "authorized",
                    FromUserName = authInfo.AuthorizationInfo.AuthorizerAppId,
                    EventKey     = code,
                    CreateTime   = (int)now
                };
                _event.Enqueue(message);
                context.WriteLine("创建授权事件到推送...");
                context.WriteLine("处理新增和更新代理授权【{0}】完毕...", authInfo.AuthorizationInfo.AuthorizerAppId);
            }
            else
            {
                context.WriteLine("处理新增和更新代理授权【{0}】错误:{1}...", authInfo.AuthorizationInfo.AuthorizerAppId, authInfo.ErrMsg);
                throw new ServiceException(authInfo.ErrCode, authInfo.ErrMsg);
            }
        }
Ejemplo n.º 2
0
        public override Task <GetAppIdResponse> GetAppId(GetAppIdRequest request, ServerCallContext context)
        {
            var resp = new GetAppIdResponse();
            var data = ComponentApi.GetAuthInfo(_componentAccessToken, _componentAppId, request.Code);

            if (data.ErrCode == 0)
            {
                resp.AppId = data.AuthorizationInfo.AuthorizerAppId;
            }
            else
            {
                resp.Error = new Error
                {
                    ErrCode = data.ErrCode,
                    ErrMsg  = data.ErrMsg
                };
            }
            return(Task.FromResult(resp));
        }