Beispiel #1
0
        public static async Task <object> CallService(IServerProxyFactory serverProxyFactory, string apiPath, string token, JObject input)
        {
            CallServiceType     callType;
            Type                InputType;
            var                 routeService = RouteManager.GetRouteService(apiPath);
            IVirtualProxyServer remoteProxy  = default;

            if (routeService == null)
            {
                remoteProxy = serverProxyFactory.CreateProxy(apiPath);
                if (remoteProxy != null)
                {
                    InputType = remoteProxy.InputType;
                    callType  = CallServiceType.Custom;
                }
                else
                {
                    return(new BaseApiResult <object> {
                        ErrMessage = "创建代理失败", Code = -1
                    });
                }
            }
            else
            {
                InputType = routeService.InputType;
                callType  = CallServiceType.Aggregate;
            }
            switch (callType)
            {
            case CallServiceType.Aggregate:
                if (AuthManager.CheckAuth(routeService, token, input, InputType, out object aggregateInputObj))
                {
                    return(await routeService.Process(aggregateInputObj, serverProxyFactory));
                }
                else
                {
                    return(new BaseApiResult <object> {
                        ErrMessage = "尚未登录或登录凭证已失效,请重新登录后再试", Code = -2
                    });
                }

            case CallServiceType.Custom:
            default:
                if (AuthManager.CheckAuth(apiPath, token, input, InputType, out object customInputObj))
                {
                    return(await remoteProxy.SendAsync(customInputObj));
                }
                else
                {
                    return(new BaseApiResult <object> {
                        ErrMessage = "尚未登录或登录凭证已失效,请重新登录后再试", Code = -2
                    });
                }
            }
        }