Code Monkey home page Code Monkey logo

Comments (17)

Executor-Cheng avatar Executor-Cheng commented on August 18, 2024 1

我已经简单做了一个ASP.NET Core 7.0的项目来测试加好友是否能正确收悉和处理, 测试是通过的
示例在这个提交里: 5da2ff8
如果你想要自己玩一玩, 你需要改好 Startup.cs 里边的凭据, 访问 http://127.0.0.1:5000/robot/add?robotQQ=0000000, 然后再用测试账号加你的机器人账号, 看看是否正确拒绝
正确拒绝将出现以下提示:
p1

from mirai-csharp.

Executor-Cheng avatar Executor-Cheng commented on August 18, 2024

辛苦提供一下 mirai-api-http 的版本
仔细看了看实现应该是没问题的

from mirai-csharp.

DUWENINK avatar DUWENINK commented on August 18, 2024

辛苦提供一下 mirai-api-http 的版本 仔细看了看实现应该是没问题的

my mirai-api-http version is v2.4.0

from mirai-csharp.

Executor-Cheng avatar Executor-Cheng commented on August 18, 2024

在 .NET6.0&.NET 7.0, mirai v2.9.2 + mirai-api-http v2.4.0 下可以正确处理以及响应加好友信息
我怀疑是 mirai-api-http 与最新版本的 mirai 不兼容导致 mirai-api-http 未能收到加好友消息
还需要辛苦你检查一下 mirai-console 输出

from mirai-csharp.

DUWENINK avatar DUWENINK commented on August 18, 2024

我已经检查过了,console里边输出正常

from mirai-csharp.

Executor-Cheng avatar Executor-Cheng commented on August 18, 2024

刚刚看了看, 不排除你ws连接已被断开, 而你没有修改 ExamplePlugin.Disconnected.cs 中欲连接的QQ号导致无法收悉消息
建议你先使用最小方法重新复现一次问题:

using System;
using System.Threading.Tasks;
using Mirai.CSharp.HttpApi.Handlers;
using Mirai.CSharp.HttpApi.Models.EventArgs;
using Mirai.CSharp.HttpApi.Session;

// IDisconnectedEventArgs 和 IUnknownMessageEventArgs 不需要标定 RegisterMiraiHttpParserAttribute
public partial class ReconnectPlugin : IMiraiHttpMessageHandler<IDisconnectedEventArgs>
{
    public async Task HandleMessageAsync(IMiraiHttpSession session, IDisconnectedEventArgs e)
    {
        // e.Exception: 引发掉线的响应异常, 按需处理
        while (true)
        {
            try
            {
                await session.ConnectAsync(e.LastConnectedQQNumber);
                e.BlockRemainingHandlers = true;
                break;
            }
            catch (ObjectDisposedException) // session 已被释放
            {
                break;
            }
            catch (Exception)
            {
                await Task.Delay(1000);
            }
        }
    }
}
services.AddDefaultMiraiHttpFramework() // 表示使用 mirai-api-http 实现的构建器
        .AddInvoker<MiraiHttpMessageHandlerInvoker>() // 使用默认的调度器
        .AddHandler<ProcessFriendAddPlugin>()
        .AddHandler<ReconnectPlugin>()
        .AddClient<MiraiHttpSession>() // 使用默认的客户端
        .Services
        .Configure<MiraiHttpSessionOptions>(options =>
        {
            options.Host = "192.168.0.27";
            options.Port = 3652; // 端口
            options.AuthKey = "mahuatengnb"; // 凭据
        })
        .AddLogging();

顺便发现了我忘了在 ExamplePlugin.Disconnected.cs 里边写 break; 这件事

from mirai-csharp.

DUWENINK avatar DUWENINK commented on August 18, 2024

代码在netcore console中运行没问题 ,但是改到aspnetcore webapi中 则收不到事件处理信息 老哥有兴趣搞一个aspnetcore 的demo吗 ,it will help more person

from mirai-csharp.

Executor-Cheng avatar Executor-Cheng commented on August 18, 2024

嗯……我觉得是包的问题。他引入了两个不同版本的DI
今天我会把#119 合并了, 发2.1.5版本出来解决一下在.NET 7.0下的依赖问题

from mirai-csharp.

DUWENINK avatar DUWENINK commented on August 18, 2024

嗯……我觉得是包的问题。他引入了两个不同版本的DI 今天我会把#119 合并了, 发2.1.5版本出来解决一下在.NET 7.0下的依赖问题

在netcore console中没有问题(但是如果我取消wile的循环则相当于console运行一次停止),为了模拟出常驻后台效果 我把这个封装在topshelf中删除while语句问题则和使用aspnetcore 一样,因此我猜想是运行完毕释放导致的 建议参考盛派SDK的实现
//使用中间件注册 MessageHandler,指定 CustomMessageHandler 为自定义处理方法 app.UseMessageHandlerForMp("/WeChat", (stream, postModel, maxRecordCount, serviceProvider) => new SaasMessageHandler(stream, postModel, maxRecordCount, false, serviceProvider), options => { options.AccountSettingFunc = context => senparcWeixinSetting.Value; });类似这种 然后自己在自定义的处理类中实现相关逻辑即可

from mirai-csharp.

Executor-Cheng avatar Executor-Cheng commented on August 18, 2024

那我还有一些问题
既然你是在ASP.NET Core下使用本框架, 本框架的 MiraiHttpFrameworkBuilder 注册 Invoker, Handler, Client, Subscription, SubscriptionResolver 时, 其生命周期默认为 Scoped。注册 ParserParserResolver 时, 其生命周期默认为 Singleton
意味着你需要在正确的DI容器下解析才是正确操作
并且你不能自行调用这些服务的 Dispose 方法
可以确认一下不?

from mirai-csharp.

DUWENINK avatar DUWENINK commented on August 18, 2024

Dispose

是的 我是正常注册的 并且没有调用Dispose

from mirai-csharp.

Executor-Cheng avatar Executor-Cheng commented on August 18, 2024

我已经发布了 v2.1.5, 添加了对.NET 7.0的支持, 你可以试一试在这个版本下问题是否仍存续
不止是要正常注册, 你还需要在 IServiceScope 中解析 Scoped 服务, 在这里就是需要在其中解析 IMiraiHttpSession, 而不是在根容器中解析

from mirai-csharp.

Executor-Cheng avatar Executor-Cheng commented on August 18, 2024

@DUWENINK 老哥, 问题还存续嘛

from mirai-csharp.

DUWENINK avatar DUWENINK commented on August 18, 2024

@DUWENINK 老哥, 问题还存续嘛

比较抱歉,问题还是存在的 老哥 强烈建议你分平台展示你的demo 我现在没办法直接用的topshelf把netcore console封装成服务运行的

from mirai-csharp.

Executor-Cheng avatar Executor-Cheng commented on August 18, 2024

好的, demo两天内我会进行完善
在这期间可以辛苦clone一次本项目, 然后在你的项目中直接引用本项目, 在以下地方置一个断点帮助我解决问题不:


置好断点后发一次好友请求, 看看断点是否有命中

from mirai-csharp.

DUWENINK avatar DUWENINK commented on August 18, 2024

我已经简单做了一个ASP.NET Core 7.0的项目来测试加好友是否能正确收悉和处理, 测试是通过的 示例在这个提交里: 5da2ff8 如果你想要自己玩一玩, 你需要改好 Startup.cs 里边的凭据, 访问 http://127.0.0.1:5000/robot/add?robotQQ=0000000, 然后再用测试账号加你的机器人账号, 看看是否正确拒绝 正确拒绝将出现以下提示: p1

谢谢你的demo 我打算采用你的代码进行测试,等我的消息

from mirai-csharp.

DUWENINK avatar DUWENINK commented on August 18, 2024

问题是解决的 谢谢老哥

from mirai-csharp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.