Skip to content

Commit 89f58c7

Browse files
committed
[修改]1. 修改HTTPJSON消息格式为基础框架库
1 parent a2c0276 commit 89f58c7

File tree

5 files changed

+18
-198
lines changed

5 files changed

+18
-198
lines changed

GameFrameX.NetWork.HTTP/BaseHttpHandler.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using GameFrameX.NetWork.Messages;
1+
using GameFrameX.Foundation.Http.Normalization;
2+
using GameFrameX.NetWork.Messages;
23
using GameFrameX.Utility;
34
using GameFrameX.Utility.Setting;
45

@@ -106,7 +107,7 @@ public bool CheckSign(Dictionary<string, object> paramMap, out string error)
106107
// 内部验证
107108
if (!paramMap.ContainsKey(GlobalConst.HttpSignKey) || !paramMap.ContainsKey(GlobalConst.HttpTimestampKey))
108109
{
109-
error = HttpResult.ParamError;
110+
error = HttpJsonResult.ValidationErrorString();
110111
return false;
111112
}
112113

@@ -117,7 +118,7 @@ public bool CheckSign(Dictionary<string, object> paramMap, out string error)
117118
// 5分钟内有效
118119
if (span.TotalMinutes > 5)
119120
{
120-
error = HttpResult.Create(HttpStatusCode.Illegal, "http命令已过期");
121+
error = HttpJsonResult.IllegalString();
121122
return false;
122123
}
123124

@@ -127,7 +128,7 @@ public bool CheckSign(Dictionary<string, object> paramMap, out string error)
127128
return true;
128129
}
129130

130-
error = HttpResult.CheckFailed;
131+
error = HttpJsonResult.ValidationErrorString();
131132
return false;
132133
}
133134
}

GameFrameX.NetWork.HTTP/GameFrameX.NetWork.HTTP.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<OutputPath>..\bin\app</OutputPath>
3838
</PropertyGroup>
3939
<ItemGroup>
40+
<PackageReference Include="GameFrameX.Foundation.Http.Normalization" Version="1.0.2" />
4041
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
4142
</ItemGroup>
4243

GameFrameX.NetWork.HTTP/HttpHandler.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Buffers;
22
using System.Diagnostics;
3+
using GameFrameX.Foundation.Http.Normalization;
34
using GameFrameX.NetWork.Abstractions;
45
using GameFrameX.NetWork.Messages;
56
using GameFrameX.ProtoBuf.Net;
@@ -84,14 +85,14 @@ public static async Task HandleRequest(HttpContext context, Func<string, BaseHtt
8485
if (!paramMap.TryAdd(keyValuePair.Key, keyValuePair.Value))
8586
{
8687
// 参数Key发生重复
87-
await context.Response.WriteAsync(HttpResult.CreateErrorParam("参数重复了:" + keyValuePair.Key));
88+
await context.Response.WriteAsync(HttpJsonResult.ErrorString(HttpStatusCode.ParamErr, "参数重复了:" + keyValuePair.Key));
8889
return;
8990
}
9091
}
9192
}
9293
else
9394
{
94-
await context.Response.WriteAsync(HttpResult.CreateErrorParam("不支持的Content Type: " + headContentType));
95+
await context.Response.WriteAsync(HttpJsonResult.ErrorString(HttpStatusCode.ParamErr, "不支持的Content Type: " + headContentType));
9596
return;
9697
}
9798
}
@@ -106,13 +107,13 @@ public static async Task HandleRequest(HttpContext context, Func<string, BaseHtt
106107
// 检查指令是否有效
107108
if (command.IsNullOrEmptyOrWhiteSpace())
108109
{
109-
await context.Response.WriteAsync(HttpResult.Undefined);
110+
await context.Response.WriteAsync(HttpJsonResult.ErrorString(HttpStatusCode.Undefined, HttpStatusMessage.UndefinedCommand));
110111
return;
111112
}
112113

113114
if (!GlobalSettings.IsAppRunning)
114115
{
115-
await context.Response.WriteAsync(HttpResult.CreateActionFailed("服务器状态错误[正在起/关服]"));
116+
await context.Response.WriteAsync(HttpJsonResult.ErrorString(HttpStatusCode.ActionFailed, "服务器状态错误[正在起/关服]"));
116117
return;
117118
}
118119

@@ -137,7 +138,7 @@ public static async Task HandleRequest(HttpContext context, Func<string, BaseHtt
137138
if (handler == null)
138139
{
139140
LogHelper.Warn($"http cmd handler 不存在:{command}");
140-
await context.Response.WriteAsync(HttpResult.NotFound);
141+
await context.Response.WriteAsync(HttpJsonResult.NotFoundString());
141142
return;
142143
}
143144

@@ -179,7 +180,7 @@ public static async Task HandleRequest(HttpContext context, Func<string, BaseHtt
179180
catch (Exception e)
180181
{
181182
LogHelper.Error($"{logHeader}, 发生异常. {{0}} {{1}}", e.Message, e.StackTrace);
182-
await context.Response.WriteAsync(HttpResult.Create(HttpStatusCode.ServerError, e.Message));
183+
await context.Response.WriteAsync(HttpJsonResult.ServerErrorString());
183184
}
184185
}
185186
}

GameFrameX.NetWork.HTTP/HttpResult.cs

Lines changed: 0 additions & 163 deletions
This file was deleted.

GameFrameX.NetWork.HTTP/HttpStatusCode.cs

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,25 @@ namespace GameFrameX.NetWork.HTTP;
33
/// <summary>
44
/// HTTP状态码
55
/// </summary>
6-
public enum HttpStatusCode
6+
public static class HttpStatusCode
77
{
8-
/// <summary>
9-
/// 成功
10-
/// </summary>
11-
Success = 0,
12-
138
/// <summary>
149
/// 未定义的命令
1510
/// </summary>
16-
Undefined = 11,
11+
public const int Undefined = 11;
1712

1813
/// <summary>
1914
/// 非法
2015
/// </summary>
21-
Illegal = 12,
16+
public const int Illegal = 12;
2217

2318
/// <summary>
2419
/// 参数错误
2520
/// </summary>
26-
ParamErr = 13,
27-
28-
/// <summary>
29-
/// 验证失败
30-
/// </summary>
31-
CheckFailed = 14,
21+
public const int ParamErr = 13;
3222

3323
/// <summary>
3424
/// 操作失败
3525
/// </summary>
36-
ActionFailed = 15,
37-
38-
/// <summary>
39-
/// 未找到的命令
40-
/// </summary>
41-
NotFound = 16,
42-
43-
/// <summary>
44-
/// 服务器错误
45-
/// </summary>
46-
ServerError = 17,
26+
public const int ActionFailed = 15;
4727
}

0 commit comments

Comments
 (0)