跳到主要内容

FreeKit.Platform

简介

Platform 是一个综合性平台服务模块,提供多种基础业务能力,包括行政区域管理、用户地址管理、定时任务、代码生成、热点数据聚合等功能。

功能模块

基础服务

  • 行政区域管理 (Area)
    • 提供中国行政区域数据维护
  • 用户地址 (UserAddress)
    • 用户收货地址管理
  • 定时任务 (TaskInfo)
    • 任务调度与管理

开发工具

  • 代码生成 (CG)
    • 数据库配置 (DbConfig)
    • 任务构建 (TaskBuild)
    • 代码模板 (Template)

用户服务

  • 用户积分 (UserIntergrals)
    • 每日签到功能
  • 保险箱 (SafeBoxe)
    • 用户数据安全存储

内容服务

  • 外链历史 (LinkHistory)
    • 记录和统计外部链接访问
  • 每日热点 (DailyHot)
    • 聚合多平台热点数据,支持以下数据源:
      • 社交媒体:微博、抖音、B站
      • 技术社区:GitHub、掘金、CSDN、SegmentFault
      • 新闻资讯:36氪、百度、知乎、今日头条
      • 游戏社区:NGA、米哈游、LOL
      • 其他平台:豆瓣、V2EX、简书、贴吧等
  • 导航服务 (Nav)
    • 分类目录 (Catalog)
    • 导航项目 (NavItem)
  • 本地化 (Localization)
  • 灵魂语录 (Soul)
    • 每日一句功能

开发者社区

  • 中国独立开发者项目 (Project)
    • 开发者信息 (DevUser)
    • 项目管理 (DevProject)
    • 社交账号关联 (DevUserSocial)
    • 用户系统 (User)

配置指南

1. 模块注册

List<Type> typeAssemblies = new List<Type>()
{
typeof(Program),
typeof(IApplicationService),
typeof(FreeKitModule),
typeof(PlatformModuleStartup)
};

containerBuilder.RegisterModule(new FreeKitModule(typeAssemblies.ToArray(), null));
containerBuilder.RegisterModule(new UnitOfWorkModule(typeAssemblies.ToArray(), null));

2. 服务依赖

services.AddModule<PlatformModuleStartup>("module-platform", c);

3. CAP 配置

var assemblies = new List<Assembly>
{
typeof(BasicIdentityModuleStartup).Assembly,
typeof(PlatformModuleStartup).Assembly
};

services.AddKitCap(c) // 分布式事务一致性CAP
.AddSubscriberAssembly(assemblies.ToArray());

4. Swagger 配置

var projectNames = new List<string>()
{
"FreeKit.Platform"
};
// 注入业务服务
services.AddSwagger(c, projectNames);

技术栈

  • .NET Core
  • CAP (分布式事务)
  • Swagger (API文档)
  • AutoFac (依赖注入)

平台消息中心

已落地能力

  • 统一消息中心 API:POST /api/plat/messages/send
  • 消息重试 API:POST /api/plat/messages/{id}/retry
  • 统一消息落库:记录业务类型、渠道、状态、第三方消息 Id、失败原因
  • 渠道发送器:飞书机器人、企业微信机器人、微信公众号模板消息
  • 事件驱动对接:Platform.Message.Send CAP 主题
  • CmsKit 通知扇出:当前默认关闭,普通业务消息以站内信 + SignalR 为主

对接建议

  • 当前阶段:普通业务一律以站内信 + SignalR 为主,不再把外部渠道作为默认业务能力
  • 异常告警:外部渠道仅建议承接系统异常、运维告警、任务失败等少量高优先级消息,直接发送到固定群 webhook
  • To B:如果后续确实出现运营后台、审核流、工单流等场景,再单独打开业务外发,不和 To C 普通互动消息混用
  • 微信:当前实现为公众号模板消息模式,适合已知 openid 的服务通知;若后续转向小程序订阅消息,可在现有 IMessageChannelSender 抽象下新增发送器

配置示例

{
"PlatformMessage": {
"EnableCmsKitNotificationFanout": false,
"DefaultChannels": [],
"AllowedCmsKitNotificationTypes": [],
"Feishu": {
"Enabled": false,
"WebhookUrl": "https://open.feishu.cn/open-apis/bot/v2/hook/xxxx",
"Secret": "sign-secret"
},
"WeCom": {
"Enabled": false,
"WebhookUrl": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxx"
},
"WeChatOfficialAccount": {
"Enabled": false,
"AppId": "wx-app-id",
"AppSecret": "wx-app-secret",
"TemplateId": "template-id",
"DefaultUrl": "https://your-domain/notifications"
}
},
"SendException": {
"Enable": true,
"MailTo": "ops@example.com",
"GroupWebhook": {
"Enabled": true,
"Channel": "Feishu",
"WebhookUrl": "https://open.feishu.cn/open-apis/bot/v2/hook/xxxx",
"Secret": "sign-secret"
}
}
}

与业务模块的边界

  • 业务模块负责产生事件和业务文案,不直接耦合第三方平台 SDK
  • CmsKit 等 C 端业务模块默认只负责站内消息,不承担外部渠道触达职责
  • Platform 模块保留渠道发送和状态记录能力,但当前更适合承接异常告警和少量 To B 场景
  • 如果将来重新打开业务外发,建议按模块、按事件类型逐项白名单开启,不要恢复成全量通知外推
List<Type> typeAssemblies =new List<Type>()
{
typeof(Program),
typeof(IApplicationService),
typeof(FreeKitModule),
+ typeof(PlatformModuleStartup),
};

containerBuilder.RegisterModule(new FreeKitModule(typeAssemblies.ToArray(), null));
containerBuilder.RegisterModule(new UnitOfWorkModule(typeAssemblies.ToArray(), null));
  • 依赖
services.AddModule<PlatformModuleStartup>("module-platform", c);
  • CAP
var assemblies = new List<Assembly>
{
typeof(BasicIdentityModuleStartup).Assembly,
+ typeof(PlatformModuleStartup).Assembly,
};

services.AddKitCap(c) // 分布式事务一致性CAP
.AddSubscriberAssembly(assemblies.ToArray());
;
var projectNames = new List<string>()
{
+ "FreeKit.Platform",
};
//注入业务服务
services.AddSwagger(c, projectNames);