using System; using System.Collections.Generic; using JsonRpcLite.Network; using JsonRpcLite.Services; using JsonRpcLite.Utilities; using Newtonsoft.Json; using WingInterfaceLibrary.Enum; using WingInterfaceLibrary.Interface; using WingInterfaceLibrary.Request.Authentication; using WingServerCommon.Log; using WingServerCommon.Service; namespace WingCloudServer.Plugin { public interface ITokenVerifyPlugin : IJsonRpcHttpServerEnginePlugin { } public class TokenVerifyPlugin : JsonRpcService, ITokenVerifyPlugin { protected IAuthenticationService _authenticationService; public override void Load(JsonRpcClientPool jsonRpcClientPool) { base.Load(jsonRpcClientPool); _authenticationService = GetProxy(); } /// /// 不需要token验证的接口列表 /// /// public static List NotValidationRequiredList = new List { "IConnectService/ConnectAsync", "IEmailService/SendEmailAsync", "ILoginService/CommonLoginAsync", "ILoginService/CheckLoginTypeAsync", "ILoginService/CommonSignUpAsync", "ILoginService/CheckSMSVerificationCodeAsync", "ILoginService/SendSMSVerificationCodeAsync", "ILoginService/SendEmailVerificationCodeAsync", "ILoginService/CheckEmailVerificationCodeAsync", "ILoginService/RetrievePasswordByPhoneAsync", "ILoginService/RetrievePasswordByEmailAsync", "ILoginService/VerifyAccountAsync", "IManagementService/AdminLogin", "IManagementService/FindReportPreviewUrlAsync", "IManagementService/FindReportShareConentAsync", "IManagementService/FindRelatedDeviceCodesAsync", "IManagementService/AddReportTemplateAsync", "IManagementService/UpdateReportTemplateAsync", "IManagementService/RemoveReportTemplateAsync", "IManagementService/GetReportTemplateAsync", "IManagementService/GetShareExamUrlAsync", "IRemedicalService/GetReportElementByLanguageAsync", "IRemedicalService/PushFinshExamNotificationToClientAsync", "INotificationService/SendMessageAsync", "INotificationService/PostMessageAsync", "IRegionService/GetRegionsAsync", "IReportService/FindShareContentAsync", "ISMSService/SendMessageAsync", "ISMSService/CheckVerificationCodeAsync", "ISMSService/GeneralMessageAsync", "IStorageService/UploadFileAsync", "IVinnoServerService/UpdateServerInfoAsync", "IVinnoServerService/GetServerInfoListAsync", "IVinnoServerService/EchoAsync", "IVinnoServerService/GetPasswordRuleAsync", "IVinnoServerService/UpdateServerIPListAsync", "IAIDiagnosisService/DiagnosisImageAsync", "IReportService/CreateReportTemplatePreviewAsync", "IWingRtcService/GetRoomIdAsync", "IWingRtcService/GenerateRoomUrlAsync", "IWingRtcService/GetRtcSettingAsync", "IWingRtcService/GetUserSignAsync", "ILiveConsultationService/SyncServerMessageAsync", "IManagementService/ImitateLoginAsync", "IManagementService/FindCMSTemplateByUserAsync", "IManagementService/FindCMSStatisticRecordsAsync", "IPaymentService/PayNotify", }; public PluginProcessResult PreProcess(IJsonRpcHttpContext context, byte[] requestData) { var dataLength = (int)context.GetRequestContentLength(); var requests = JsonRpcCodec.DecodeRequestsAsync(requestData, new System.Threading.CancellationToken(), dataLength).Result; var apiName = $"{context.GetRequestPath().Trim('/')}/{requests[0].Method.Trim('/')}"; if (context.GetRequestPath() != "/IAuthenticationService" && context.GetRequestPath() != "/IMasterInteractionCenterService"&& context.GetRequestPath() != "/ILockService" && !NotValidationRequiredList.Contains(apiName)&&!context.GetRequestPath().Contains("IDynamicSlaveService") ) { var tokenRequest = new ValidateTokenRequest(); try { tokenRequest = JsonConvert.DeserializeObject>(requests[0].Params.Value.ToString().Replace("\r", "").Replace("\n", "").Replace("\t", ""))[0]; } catch (Exception) { try { tokenRequest = JsonConvert.DeserializeObject(requests[0].Params.Value.ToString().Replace("\r", "").Replace("\n", "").Replace("\t", "")); } catch (Exception ex) { Logger.WriteLineError($"TokenVerifyPlugin err{ex.ToString()},{JsonConvert.SerializeObject(requests)}"); } } var result = _authenticationService.ValidateTokenAsync(tokenRequest).Result; if (result.Code != CustomerRpcCode.Ok) { ThrowRpcException((int)result.Code, "Permission validation error"); } } return new PluginProcessResult(requestData, false); } public PluginProcessResult PostProcess(IJsonRpcHttpContext context, byte[] responseData) { return new PluginProcessResult(responseData, false); } } }