update
This commit is contained in:
parent
ba41c6dad4
commit
0786589239
@ -4,9 +4,11 @@ using System.Collections.Generic;
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
|
using VideoConcat.Common.Api.Common;
|
||||||
|
|
||||||
namespace VideoConcat.Common.Api.Base
|
namespace VideoConcat.Common.Api.Base
|
||||||
{
|
{
|
||||||
|
|
||||||
public partial class UserLoginResponse
|
public partial class UserLoginResponse
|
||||||
{
|
{
|
||||||
[JsonProperty("user")]
|
[JsonProperty("user")]
|
||||||
|
|||||||
@ -5,11 +5,12 @@ namespace VideoConcat.Common.Api.Base
|
|||||||
{
|
{
|
||||||
public class SystemApi
|
public class SystemApi
|
||||||
{
|
{
|
||||||
public static async Task<UserLoginResponse> LoginAsync<UserLoginResponse>(string username, string password)
|
public static async Task<ApiResponse<UserLoginResponse>> LoginAsync<UserLoginResponse>(string username, string password)
|
||||||
{
|
{
|
||||||
HttpService Http = new();
|
HttpHelper Http = new();
|
||||||
ApiResponse<UserLoginResponse> res = await Http.PostAsync<UserLoginResponse>("/api/base/login", new { Username = username, Password = password, Platform = "pc" });
|
ApiResponse<UserLoginResponse> res = await Http.PostAsync<UserLoginResponse>("/api/base/login", new { Username = username, Password = password, Platform = "pc" });
|
||||||
return res.Data;
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
22
Common/Api/Common/Common.cs
Normal file
22
Common/Api/Common/Common.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace VideoConcat.Common.Api.Common
|
||||||
|
{
|
||||||
|
public class CommonResponese<T>
|
||||||
|
{
|
||||||
|
|
||||||
|
[JsonProperty("code")]
|
||||||
|
public int Code { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("data")]
|
||||||
|
public T Data { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("msg")]
|
||||||
|
public string Msg { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,59 +1,71 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace VideoConcat.Common.Tools
|
namespace VideoConcat.Common.Tools
|
||||||
{
|
{
|
||||||
public class HttpService
|
|
||||||
|
|
||||||
|
// HTTP 请求封装类
|
||||||
|
public class HttpHelper
|
||||||
{
|
{
|
||||||
private readonly HttpClient _httpClient;
|
private readonly HttpClient _httpClient;
|
||||||
|
|
||||||
public HttpService()
|
public HttpHelper()
|
||||||
{
|
{
|
||||||
|
|
||||||
_httpClient = new HttpClient
|
_httpClient = new HttpClient
|
||||||
{
|
{
|
||||||
//BaseAddress = new Uri("https://admin.xiangbing.vip"),
|
BaseAddress = new Uri("https://admin.xiangbing.vip")
|
||||||
BaseAddress = new Uri("http://127.0.0.1:8080"),
|
|
||||||
};
|
};
|
||||||
|
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ApiResponse<T>> PostAsync<T>(string url, object data)
|
// 发送 GET 请求
|
||||||
|
public async Task<ApiResponse<T>> GetAsync<T>(string url)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var json = JsonSerializer.Serialize(data);
|
var response = await _httpClient.GetAsync(url);
|
||||||
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
response.EnsureSuccessStatusCode();
|
||||||
|
var content = await response.Content.ReadAsStringAsync();
|
||||||
var response = await _httpClient.PostAsync(url, content);
|
return JsonConvert.DeserializeObject<ApiResponse<T>>(content);
|
||||||
var apiResponse = await ApiResponse<T>.CreateAsync(response);
|
|
||||||
|
|
||||||
if (!apiResponse.IsSuccess)
|
|
||||||
{
|
|
||||||
LogUtils.Error($"PostAsync<{typeof(T)}> failed: {apiResponse.Code} {apiResponse.Msg}");
|
|
||||||
}
|
|
||||||
|
|
||||||
return apiResponse;
|
|
||||||
}
|
|
||||||
catch (TaskCanceledException)
|
|
||||||
{
|
|
||||||
return new ApiResponse<T>
|
|
||||||
{
|
|
||||||
IsSuccess = false,
|
|
||||||
Msg = "请求超时",
|
|
||||||
Code = 408
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return new ApiResponse<T>
|
return new ApiResponse<T>
|
||||||
{
|
{
|
||||||
IsSuccess = false,
|
Code = 500,
|
||||||
Msg = ex.Message,
|
Msg = $"请求出错: {ex.Message}",
|
||||||
Code = 500
|
Data = default
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发送 POST 请求
|
||||||
|
public async Task<ApiResponse<T>> PostAsync<T>(string url, object data)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var json = JsonConvert.SerializeObject(data);
|
||||||
|
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||||
|
var response = await _httpClient.PostAsync(url, content);
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
var responseContent = await response.Content.ReadAsStringAsync();
|
||||||
|
return JsonConvert.DeserializeObject<ApiResponse<T>>(responseContent);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new ApiResponse<T>
|
||||||
|
{
|
||||||
|
Code = 500,
|
||||||
|
Msg = $"请求出错: {ex.Message}",
|
||||||
|
Data = default
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,39 +73,8 @@ namespace VideoConcat.Common.Tools
|
|||||||
|
|
||||||
public class ApiResponse<T>
|
public class ApiResponse<T>
|
||||||
{
|
{
|
||||||
public bool IsSuccess { get; set; }
|
|
||||||
public int Code { get; set; }
|
public int Code { get; set; }
|
||||||
public T Data { get; set; }
|
public T Data { get; set; }
|
||||||
public string Msg { get; set; }
|
public string Msg { get; set; }
|
||||||
public string RawContent { get; set; }
|
|
||||||
|
|
||||||
public static async Task<ApiResponse<T>> CreateAsync(HttpResponseMessage response)
|
|
||||||
{
|
|
||||||
var result = new ApiResponse<T>
|
|
||||||
{
|
|
||||||
IsSuccess = response.IsSuccessStatusCode,
|
|
||||||
Code = (int)response.StatusCode,
|
|
||||||
RawContent = await response.Content.ReadAsStringAsync()
|
|
||||||
};
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (result.IsSuccess)
|
|
||||||
{
|
|
||||||
result.Data = JsonSerializer.Deserialize<T>(result.RawContent);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result.Msg = result.RawContent; // 或解析错误结构
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (JsonException ex)
|
|
||||||
{
|
|
||||||
result.IsSuccess = false;
|
|
||||||
result.Msg = $"JSON解析失败: {ex.Message}";
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,7 @@ VisualStudioVersion = 17.11.35327.3
|
|||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VideoConcat", "VideoConcat.csproj", "{2FF5691C-3184-4B68-944B-C704E64C4E4E}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VideoConcat", "VideoConcat.csproj", "{2FF5691C-3184-4B68-944B-C704E64C4E4E}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "视频拼接", "..\视频拼接\视频拼接.vdproj", "{1444D25A-0A52-4C6A-8FF7-3D1002EA691F}"
|
Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "视频", "..\视频\视频.vdproj", "{6253EBA0-190A-4A7D-AC55-954172807A46}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -17,8 +17,8 @@ Global
|
|||||||
{2FF5691C-3184-4B68-944B-C704E64C4E4E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{2FF5691C-3184-4B68-944B-C704E64C4E4E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{2FF5691C-3184-4B68-944B-C704E64C4E4E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{2FF5691C-3184-4B68-944B-C704E64C4E4E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{2FF5691C-3184-4B68-944B-C704E64C4E4E}.Release|Any CPU.Build.0 = Release|Any CPU
|
{2FF5691C-3184-4B68-944B-C704E64C4E4E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{1444D25A-0A52-4C6A-8FF7-3D1002EA691F}.Debug|Any CPU.ActiveCfg = Debug
|
{6253EBA0-190A-4A7D-AC55-954172807A46}.Debug|Any CPU.ActiveCfg = Debug
|
||||||
{1444D25A-0A52-4C6A-8FF7-3D1002EA691F}.Release|Any CPU.ActiveCfg = Release
|
{6253EBA0-190A-4A7D-AC55-954172807A46}.Release|Any CPU.ActiveCfg = Release
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@ -24,7 +24,11 @@
|
|||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
</Window.Resources>
|
</Window.Resources>
|
||||||
<Grid>
|
<Grid>
|
||||||
<Border>
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="39*"/>
|
||||||
|
<ColumnDefinition Width="461*"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Border Grid.ColumnSpan="2">
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<StackPanel Width="500">
|
<StackPanel Width="500">
|
||||||
<StackPanel>
|
<StackPanel>
|
||||||
|
|||||||
@ -32,8 +32,16 @@ namespace VideoConcat.Views
|
|||||||
WPFDevelopers.Controls.MessageBox.Show("请输入用户名或者密码!");
|
WPFDevelopers.Controls.MessageBox.Show("请输入用户名或者密码!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
UserLoginResponse res =await SystemApi.LoginAsync<UserLoginResponse>(_userName, _password);
|
ApiResponse<UserLoginResponse> res = await SystemApi.LoginAsync<UserLoginResponse>(_userName, _password);
|
||||||
Console.WriteLine(res);
|
if (res.Code !=0)
|
||||||
|
{
|
||||||
|
WPFDevelopers.Controls.MessageBox.Show(res.Msg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
new Video().Show();
|
||||||
|
Close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user