Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f98cc6ff5a |
+19
-17
@@ -3,6 +3,7 @@ using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Text.Unicode;
|
||||
|
||||
@@ -13,18 +14,22 @@ namespace SimApi.Helpers
|
||||
/// <summary>
|
||||
/// 当前CST时间
|
||||
/// </summary>
|
||||
public static DateTime CstNow
|
||||
public static DateTime CstNow => DateTime.UtcNow.AddHours(8);
|
||||
|
||||
/// <summary>
|
||||
/// JSON序列化常规选项
|
||||
/// </summary>
|
||||
public static JsonSerializerOptions JsonOption => new()
|
||||
{
|
||||
get => DateTime.UtcNow.AddHours(8);
|
||||
}
|
||||
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All),
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// 当前秒级时间戳
|
||||
/// </summary>
|
||||
public static double TimestampNow
|
||||
{
|
||||
get => (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds;
|
||||
}
|
||||
public static double TimestampNow => (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds;
|
||||
|
||||
/// <summary>
|
||||
/// 检测手机号是否正确
|
||||
@@ -45,13 +50,13 @@ namespace SimApi.Helpers
|
||||
/// <returns></returns>
|
||||
public static string Md5(string source, string mode = "x2")
|
||||
{
|
||||
byte[] sor = Encoding.UTF8.GetBytes(source);
|
||||
MD5 md5 = MD5.Create();
|
||||
byte[] result = md5.ComputeHash(sor);
|
||||
StringBuilder strbul = new StringBuilder(40);
|
||||
for (int i = 0; i < result.Length; i++)
|
||||
var sor = Encoding.UTF8.GetBytes(source);
|
||||
var md5 = MD5.Create();
|
||||
var result = md5.ComputeHash(sor);
|
||||
var strbul = new StringBuilder(40);
|
||||
foreach (var t in result)
|
||||
{
|
||||
strbul.Append(result[i].ToString(mode));
|
||||
strbul.Append(t.ToString(mode));
|
||||
}
|
||||
|
||||
return strbul.ToString();
|
||||
@@ -64,10 +69,7 @@ namespace SimApi.Helpers
|
||||
/// <returns></returns>
|
||||
public static string Json(object obj)
|
||||
{
|
||||
return JsonSerializer.Serialize(obj, new JsonSerializerOptions
|
||||
{
|
||||
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All)
|
||||
});
|
||||
return JsonSerializer.Serialize(obj, JsonOption);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
using System.Text.Unicode;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SimApi.Helpers;
|
||||
|
||||
namespace SimApi;
|
||||
|
||||
@@ -16,11 +17,7 @@ public partial class Synapse
|
||||
|
||||
private void FireEvent(string eventName, object param)
|
||||
{
|
||||
var paramJson = JsonSerializer.Serialize(param, new JsonSerializerOptions
|
||||
{
|
||||
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All),
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
});
|
||||
var paramJson = JsonSerializer.Serialize(param, SimApiUtil.JsonOption);
|
||||
var router = $"event.{Options.AppName}.{eventName}";
|
||||
var props = EventClientChannel.CreateBasicProperties();
|
||||
props.AppId = Options.AppId;
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Text.Json;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using RabbitMQ.Client.Events;
|
||||
using SimApi.Helpers;
|
||||
|
||||
namespace SimApi;
|
||||
|
||||
@@ -35,13 +36,7 @@ public partial class Synapse
|
||||
{
|
||||
mt.Invoke(callClass, pt == typeof(string)
|
||||
? new object[] { reqBody }
|
||||
: new[]
|
||||
{
|
||||
JsonSerializer.Deserialize(reqBody, pt, new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
||||
})
|
||||
});
|
||||
: new[] { JsonSerializer.Deserialize(reqBody, pt, SimApiUtil.JsonOption) });
|
||||
EventServerChannel.BasicAck(ea.DeliveryTag, false);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
+2
-10
@@ -38,11 +38,7 @@ public partial class Synapse
|
||||
|
||||
private object FireRpc(string app, string action, object param)
|
||||
{
|
||||
var paramJson = JsonSerializer.Serialize(param, new JsonSerializerOptions
|
||||
{
|
||||
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All),
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
});
|
||||
var paramJson = JsonSerializer.Serialize(param, SimApiUtil.JsonOption);
|
||||
var router = $"server.{app}";
|
||||
SimApiBaseResponse response;
|
||||
var props = RpcClientChannel.CreateBasicProperties();
|
||||
@@ -65,11 +61,7 @@ public partial class Synapse
|
||||
if (ResponseCache.TryGetValue(props.MessageId, out var value))
|
||||
{
|
||||
response = JsonSerializer.Deserialize<SimApiBaseResponse<object>>(
|
||||
Encoding.UTF8.GetString(value), new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All)
|
||||
});
|
||||
Encoding.UTF8.GetString(value), SimApiUtil.JsonOption);
|
||||
ResponseCache.Remove(props.MessageId);
|
||||
break;
|
||||
}
|
||||
|
||||
+4
-11
@@ -4,6 +4,7 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Unicode;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -48,10 +49,7 @@ public partial class Synapse
|
||||
}
|
||||
else
|
||||
{
|
||||
var paramObj = JsonSerializer.Deserialize(reqBody, pt, new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
||||
});
|
||||
var paramObj = JsonSerializer.Deserialize(reqBody, pt, SimApiUtil.JsonOption);
|
||||
param = new[] { paramObj };
|
||||
}
|
||||
var ret = mt.Invoke(callClass, param);
|
||||
@@ -59,9 +57,8 @@ public partial class Synapse
|
||||
}
|
||||
catch (TargetInvocationException e)
|
||||
{
|
||||
if (e.InnerException is SimApiException)
|
||||
if (e.InnerException is SimApiException ie)
|
||||
{
|
||||
var ie = e.InnerException as SimApiException;
|
||||
Logger.LogDebug("RPC调用错误: {Err}", ie.Message);
|
||||
res = new SimApiBaseResponse(ie.Code, ie.Message);
|
||||
}
|
||||
@@ -77,11 +74,7 @@ public partial class Synapse
|
||||
}
|
||||
}
|
||||
|
||||
var returnJson = JsonSerializer.Serialize((object)res, new JsonSerializerOptions
|
||||
{
|
||||
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All),
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
});
|
||||
var returnJson = JsonSerializer.Serialize((object)res, SimApiUtil.JsonOption);
|
||||
var reply = $"client.{ea.BasicProperties.ReplyTo}.{ea.BasicProperties.AppId}";
|
||||
var props = RpcServerChannel.CreateBasicProperties();
|
||||
props.AppId = Options.AppId;
|
||||
|
||||
Reference in New Issue
Block a user