Skip to content

Commit

Permalink
升级.net 8.0
Browse files Browse the repository at this point in the history
增加事件回调服务
增加长连接服务

更新事件回调使用方法
  • Loading branch information
Vicente.Yu committed Sep 8, 2024
1 parent 2cb92f6 commit 01b838f
Show file tree
Hide file tree
Showing 31 changed files with 2,378 additions and 20 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,3 @@ MigrationBackup/

# Fody - auto-generated XML schema
FodyWeavers.xsd

158 changes: 158 additions & 0 deletions EventCallbackList.md

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions FeishuNetSdk.Endpoint/FeishuNetSdk.Endpoint.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<OutputType>Library</OutputType>
<IsPackable>true</IsPackable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Title>FeishuNetSdk.Endpoint</Title>
<Authors>Vicente Yu</Authors>
<PackageProjectUrl>https://github.com/vicenteyu/FeishuNetSdk</PackageProjectUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/vicenteyu/FeishuNetSdk</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>feishu; sdk; dotnet; .net8.0</PackageTags>
<Copyright>MIT</Copyright>
<Description>适用于飞书开放平台的.Net开发包</Description>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Version>3.0.0</Version>
</PropertyGroup>

<ItemGroup>
<None Include="LICENSE">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<None Include="README.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\src\FeishuNetSdk.csproj" />
</ItemGroup>

</Project>
53 changes: 53 additions & 0 deletions FeishuNetSdk.Endpoint/FeishuNetSdkEndpointExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// ************************************************************************
// Assembly : FeishuNetSdk
// Author : yxr
// Created : 2024-09-07
//
// Last Modified By : yxr
// Last Modified On : 2024-09-07
// ************************************************************************
// <copyright file="FeishuNetSdkEndpointExtension.cs" company="Vicente Yu">
// MIT
// </copyright>
// <summary>提供飞书事件回调地址服务的扩展</summary>
// ************************************************************************
using FeishuNetSdk.Services;
using Microsoft.AspNetCore.Mvc;
using System.Text.Json;

#pragma warning disable IDE0130
namespace Microsoft.Extensions.DependencyInjection
#pragma warning restore IDE0130
{
/// <summary>
/// 启用飞书事件回调地址服务
/// </summary>
public static class FeishuNetSdkEndpointExtension
{
/// <summary>
/// 事件回调监听地址
/// </summary>
/// <param name="app"></param>
/// <param name="pattern"></param>
/// <returns></returns>
public static IEndpointRouteBuilder UseFeishuEndpoint(this IEndpointRouteBuilder app, string pattern)
{
app.MapPost(pattern, async (IEventCallbackServiceProvider provider, ILogger<WebApplication> logger, [FromBody] object input) =>
{
logger.LogInformation("FeishuEndpoint: {json}", input);
var result = await provider.HandleAsync(input);
logger.LogInformation("EventHandle: {json}", JsonSerializer.Serialize(result));
if (result?.Success != true)
return Results.Problem(result?.Error);
if (result?.Dto != null)
return Results.Json(result.Dto);
return Results.Ok();
});

return app;
}
}
}
21 changes: 21 additions & 0 deletions FeishuNetSdk.Endpoint/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 vicenteyu

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
12 changes: 12 additions & 0 deletions FeishuNetSdk.Endpoint/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"profiles": {
"FeishuNetSdk.Endpoint": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5155;http://localhost:5156"
}
}
}
45 changes: 45 additions & 0 deletions FeishuNetSdk.Endpoint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# FeishuNetSdk.Endpoint

FeishuNetSdk 开发包的事件回调终结点扩展。

[![.NET](https://github.com/vicenteyu/FeishuNetSdk/actions/workflows/dotnet.yml/badge.svg?branch=main&event=push)](https://github.com/vicenteyu/FeishuNetSdk/actions/workflows/dotnet.yml) [![FeishuNetSdk](https://buildstats.info/nuget/FeishuNetSdk "FeishuNetSdk")](https://www.nuget.org/packages/FeishuNetSdk/ "FeishuNetSdk")

飞书开放平台网址:[https://open.feishu.cn/](https://open.feishu.cn/)

接口清单详见:

[TenantAccessToken 适用接口清单](https://github.com/vicenteyu/FeishuNetSdk/blob/main/TenantAccessList.md)

[UserAccessToken 适用接口清单](https://github.com/vicenteyu/FeishuNetSdk/blob/main/UserAccessList.md)

## 注意事项:

### 在开始配置之前,你需要确保已了解以下注意事项:

- 配置终结点并运行程序
- 将终点地址配置到 飞开发者后台 事件与回调的请求地址中。

## 用法:

### 1、安装Nuget包
```csharp
PM> Install-Package FeishuNetSdk.Endpoint
```

### 2、服务注册

**(1)输入`应用凭证`的方式**
```csharp
builder.Services
.AddFeishuNetSdk(
AppId: "cli_a*********013",
AppSecret: "H2wl******************UBfyVn",
EncryptKey: "75vyV******************wpkjy",
VerificationToken: "WVrlO******************2EsMSJw");
```

**(2)配置终结点**
```csharp
//启用飞书事件回调地址服务
app.UseFeishuEndpoint("/a/b/c/d");
```
43 changes: 43 additions & 0 deletions FeishuNetSdk.WebSocket/FeishuNetSdk.WebSocket.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Title>FeishuNetSdk.WebSocket</Title>
<Authors>Vicente Yu</Authors>
<PackageProjectUrl>https://github.com/vicenteyu/FeishuNetSdk</PackageProjectUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/vicenteyu/FeishuNetSdk</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>feishu; sdk; dotnet; .net8.0</PackageTags>
<Copyright>MIT</Copyright>
<Description>适用于飞书开放平台的.Net开发包</Description>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Version>3.0.0</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
<PackageReference Include="protobuf-net" Version="3.2.30" />
<PackageReference Include="WatsonWebsocket" Version="4.1.2" />
</ItemGroup>

<ItemGroup>
<None Include="LICENSE">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<None Include="README.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\src\FeishuNetSdk.csproj" />
</ItemGroup>

</Project>
41 changes: 41 additions & 0 deletions FeishuNetSdk.WebSocket/FeishuNetSdkWebSocketExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// ************************************************************************
// Assembly : FeishuNetSdk
// Author : yxr
// Created : 2024-09-07
//
// Last Modified By : yxr
// Last Modified On : 2024-09-07
// ************************************************************************
// <copyright file="FeishuNetSdkWebSocketExtensions.cs" company="Vicente Yu">
// MIT
// </copyright>
// <summary>提供注册SDK的扩展</summary>
// ************************************************************************
#pragma warning disable IDE0130
namespace Microsoft.Extensions.DependencyInjection
#pragma warning restore IDE0130
{
/// <summary>
/// 提供注册SDK的扩展
/// </summary>
public static class FeishuNetSdkWebSocketExtensions
{
/// <summary>
/// 注册SDK
/// </summary>
/// <param name="services"></param>
/// <returns></returns>
public static IServiceCollection AddFeishuWebSocket(this IServiceCollection services)
{
var serviceProvider = services.BuildServiceProvider();

_ = serviceProvider.GetService<FeishuNetSdk.IFeishuApi>()
?? throw new NotSupportedException("缺少关键服务:FeishuNetSdk");
_ = serviceProvider.GetService<Options.IOptionsMonitor<FeishuNetSdk.FeishuNetSdkOptions>>()
?? throw new NotSupportedException("缺少关键服务:FeishuNetSdk");

services.AddHostedService<FeishuNetSdk.WebSocket.WssService>();
return services;
}
}
}
Loading

0 comments on commit 01b838f

Please sign in to comment.