using CloudGaming.Core.AgileConfig.AgileConfigClient; using CloudGaming.Core.AgileConfig; using Refit; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; using CloudGaming.Code.DataBaseModel; using CloudGaming.Core.AgileConfig.AgileConfigApi; namespace CloudGaming.Api.Admin.Test.AgileConfigTest { public class AuthClientTest { [Test] public async Task Test1() { // 调用登录接口获取 JWT 令牌 var authClient = RestService.For("http://124.220.55.158:94"); var loginRequest = new LoginRequest { UserName = "admin", Password = "dbt@com@1234" }; var loginResponse = await authClient.LoginAsync(loginRequest); string jwtToken = loginResponse.Token; // 使用 JWT 令牌调用受保护的 API var httpClient = new HttpClient(new BasicAuthHttpClientHandler("admin", "dbt@com@1234")) { BaseAddress = new Uri("http://124.220.55.158:94") }; try { var agileConfigClient = RestService.For(httpClient); var apps = await agileConfigClient.GetAllAppsAsync(); //dfa47997-fb5c-b644-3770-880f5e7fb403 //huanmeng Console.WriteLine("所有应用列表:"); foreach (var app in apps) { Console.WriteLine($"应用名称: {app.Name}, 应用ID: {app.Id}"); } } catch (Exception ex) { } var httpClient1 = new HttpClient(new BasicAuthHttpClientHandler("huanmeng", "dfa47997-fb5c-b644-3770-880f5e7fb403")) { BaseAddress = new Uri("http://124.220.55.158:94") }; try { var agileConfigClient1 = RestService.For(httpClient1); var xx = await agileConfigClient1.GetAppConfigsAsync("huanmeng", "DEV"); var dic = xx.ConvertToDictionary(); var json = DictionaryConvertToJson.ToJson(dic); //var list = xx.ConvertToList(); ////list. //var result1 = AgileConfigExtend.ConvertToJson(list); //string json1 = JsonConvert.SerializeObject(result1, Formatting.Indented); //var xxxcc = AgileConfigExtend.ParseToNestedJson(list); //var result = AgileConfigExtend.ParseToJson(list); //string json = JsonConvert.SerializeObject(result, Formatting.Indented); //Console.WriteLine(json); //string list = ""; //list.ForEach(it => list += it + "\r\n"); //var json = AgileConfigExtend.ConvertToNestedJson(list); } catch (Exception ex) { } } [Test] public async Task Test2() { var httpClient = new HttpClient(new BasicAuthHttpClientHandler("CloudGaming", "95BB717C61D1ECB0E9FB82C932CC77FF")) { BaseAddress = new Uri("http://124.220.55.158:94") }; var agileConfigClient1 = RestService.For(httpClient); var xx = await agileConfigClient1.GetAppConfigsAsync("CloudGaming", "DEV"); try { var xxx = await agileConfigClient1.GetAppConfigAsync("CloudGaming", "DEV"); } catch (Exception ex) { } } [Test] public async Task Test3() { var httpClient = new HttpClient(new BasicAuthHttpClientHandler("admin", "dbt@com@1234")) { BaseAddress = new Uri("http://124.220.55.158:94") }; var agileConfigClient = RestService.For(httpClient); try { var list = await agileConfigClient.GetAppConfigAsync("CloudGaming", "DEV"); var dic = list.ConvertToDictionary(); var json = DictionaryConvertToJson.ToJson(dic); var model = JsonConvert.DeserializeObject(json); } catch (Exception ex) { } } [Test] public async Task Test4() { // 调用登录接口获取 JWT 令牌 var authClient = RestService.For("http://124.220.55.158:94"); var loginRequest = new LoginRequest { UserName = "admin", Password = "dbt@com@1234" }; var loginResponse = await authClient.LoginAsync(loginRequest); string jwtToken = loginResponse.Token; // 使用 JWT 令牌调用受保护的 API var httpClient = new HttpClient(new AuthenticatedHttpClientHandler(jwtToken)) { BaseAddress = new Uri("http://124.220.55.158:94") }; try { var agileConfigClient = RestService.For(httpClient); var model = await agileConfigClient.GetJson("CloudGaming", "DEV"); } catch (Exception ex) { } } } }