feat:第一次提交

This commit is contained in:
LyMysterious
2025-10-17 18:33:29 +08:00
commit 79780d8b3a
26 changed files with 1372 additions and 0 deletions
@@ -0,0 +1,11 @@
namespace NapCatRobotClient.Core
{
/// <summary>
/// 缓存前缀
/// </summary>
public class RedisPrefix
{
public const string GoodsKey = "GoodsInfo";
}
}
@@ -0,0 +1,2 @@
global using Furion;
global using Newtonsoft.Json;
@@ -0,0 +1,32 @@
using FreeRedis;
using Microsoft.Extensions.DependencyInjection;
namespace NapCatRobotClient.Core.Helper
{
public static class RedisExtensions
{
public static IServiceCollection AddRedis(this IServiceCollection services, string redisConnection)
{
RedisHelper.Initialization(redisConnection);
return services;
}
}
/// <summary>
/// Redis
/// </summary>
public abstract class RedisHelper
{
public static RedisClient Client;
public static void Initialization(string redisConnection)
{
Client = new(redisConnection)
{
Serialize = JsonConvert.SerializeObject,
Deserialize = JsonConvert.DeserializeObject
};
Client.Set(Guid.NewGuid().ToString(), "", 10);
}
}
}
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Flurl.Http" Version="4.0.2" />
<PackageReference Include="FreeRedis" Version="1.5.0" />
<PackageReference Include="Furion" Version="4.9.7.131" />
</ItemGroup>
<ItemGroup>
<Folder Include="RobotAPI\Dto\Response\" />
</ItemGroup>
</Project>
@@ -0,0 +1,53 @@
namespace NapCatRobotClient.Core.RobotAPI.Dto.Request
{
public class GroupSendMessageRequest
{
/// <summary>
/// 群号码
/// </summary>
[JsonProperty("group_id")]
public string GroupId { get; set; }
/// <summary>
/// 消息内容
/// </summary>
[JsonProperty("message")]
public List<MessageItem> Message { get; set; }
}
public class MessageItem
{
/// <summary>
/// 消息类型 每一种消息一个item (text:文本 at:艾特 reply:引用)
/// </summary>
[JsonProperty("type")]
public string Type { get; set; }
/// <summary>
/// 数据
/// </summary>
[JsonProperty("data")]
public MessageData Data { get; set; }
}
public class MessageData
{
/// <summary>
/// 消息内容
/// </summary>
[JsonProperty("text", NullValueHandling = NullValueHandling.Ignore)]
public string Text { get; set; }
/// <summary>
/// 如果是艾特,这里填写QQ
/// </summary>
[JsonProperty("qq", NullValueHandling = NullValueHandling.Ignore)]
public string QQ { get; set; }
/// <summary>
/// 如果是引用,这里填写引用的消息ID
/// </summary>
[JsonProperty("id", NullValueHandling = NullValueHandling.Ignore)]
public string Id { get; set; }
}
}
@@ -0,0 +1,30 @@
using Flurl.Http;
using NapCatRobotClient.Core.RobotAPI.Dto.Request;
namespace NapCatRobotClient.Core.RobotAPI
{
public class RobotAPI
{
/// <summary>
/// 发送群文本消息
/// </summary>
/// <param name="groupId"></param>
/// <param name="message"></param>
/// <returns></returns>
public static async Task<string> SendGroupText(GroupSendMessageRequest request)
{
return await Post(JsonConvert.SerializeObject(request), "/send_group_msg");
}
private static async Task<string> Post(string parameters, string action)
{
string url = App.Configuration["QQConfig:SendApiUrl"] + action;
string response = await url.WithHeader("Authorization", "Bearer " + App.Configuration["QQConfig:AccessToken"])
.WithHeader("Content-Type", "application/json;charset=utf-8")
.PostStringAsync(parameters)
.ReceiveString();
Console.WriteLine($"{DateTime.Now} 请求地址:{url} 请求结果:{response}");
return response;
}
}
}
@@ -0,0 +1,73 @@
namespace NapCatRobotClient.Core
{
public class Utils
{
/// <summary>
/// 格式化数字为中文单位
/// </summary>
/// <param name="number"></param>
/// <returns></returns>
public static string FormatNumberToChineseUnit(decimal number)
{
if (number >= 100000000) // 亿
{
decimal value = number / 100000000.0M;
return $"{value:0.#}亿";
}
else if (number >= 10000) // 万
{
decimal value = number / 10000.0M;
return $"{value:0.#}万";
}
else
{
return number.ToString();
}
}
/// <summary>
/// 解析中文数字
/// </summary>
/// <param name="chineseNumber"></param>
/// <returns></returns>
public static decimal ParseChineseNumber(string chineseNumber)
{
if (string.IsNullOrWhiteSpace(chineseNumber)) return 0;
chineseNumber = chineseNumber.Trim();
decimal multiplier = 1;
if (chineseNumber.Contains("亿"))
multiplier = 100000000;
else if (chineseNumber.Contains("万"))
multiplier = 10000;
var numberPart = chineseNumber.Replace("亿", "").Replace("万", "");
if (!decimal.TryParse(numberPart, out decimal value)) return 0;
return value * multiplier;
}
/// <summary>
/// 计算手续费
/// </summary>
/// <param name="amount"></param>
/// <returns></returns>
public static decimal CalculateFee(decimal amount)
{
decimal rate = 0;
if (amount < 500_0000) // 0 ~ 499w
rate = 0.05m; // 5%
else if (amount < 1000_0000) // 500 ~ 999w
rate = 0.10m; // 10%
else if (amount < 1500_0000) // 1000 ~ 1499w
rate = 0.15m; // 15%
else if (amount < 2000_0000) // 1500 ~ 1999w
rate = 0.20m; // 20%
else // 2000w以上
rate = 0.30m; // 30%
return amount * rate;
}
}
}