Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

微信公众号管理的时候, 出现 #243

Open
onestar1 opened this issue Sep 9, 2024 · 1 comment
Open

微信公众号管理的时候, 出现 #243

onestar1 opened this issue Sep 9, 2024 · 1 comment

Comments

@onestar1
Copy link

onestar1 commented Sep 9, 2024

公众号管理 第一次编辑后,会执行一次全局注册。

如果是重启netcore 后, 再问一次公众号 就会出现,
Unhandled exception. Senparc.Weixin.Exceptions.UnRegisterAppIdException: 此appId(wx09c4a176ef1ec44d)尚未注册,请先使用AccessTokenContainer.Register完成注册(全局执行一次即可)!
image

需要增加判断 或者,每次启动的时候 自动注册公众号列表的内容,否则就要重新编辑保存一次 公众号。

protected virtual async Task AfterRunBotAsync(IServiceProvider serviceProvider, RequestMessageText requestMessage, MpAccountDto mpAccountDto, SenparcAiResult senparcAiResult, DateTimeOffset startTime) { Console.WriteLine("MpAccountDTO:" + mpAccountDto.ToJson(indented: true)); string resultMsg = $"{senparcAiResult.OutputString}\r\n -- AI 计算耗时:{SystemTime.DiffTotalMS(startTime)}毫秒"; Console.WriteLine("公众号客服消息2:" + resultMsg); WxJsonResult result = await CustomApi.SendTextAsync(mpAccountDto.AppId, requestMessage.FromUserName, resultMsg); await Console.Out.WriteLineAsync(result.ToJson()); }

await CustomApi.SendTextAsync(mpAccountDto.AppId, requestMessage.FromUserName, resultMsg);

我现在是放在 [MpMessageHandler("JeffreyMp")] 的构造函数中
// 检查 appId 是否已注册
if (!AccessTokenContainer.CheckRegistered(_mpAccountDto.AppId)) {
// 如果未注册,进行注册
AccessTokenContainer.Register(_mpAccountDto.AppId, _mpAccountDto.AppSecret);
}

@JeffreySu
Copy link
Contributor

感谢反馈!

目前的规则应该是在启动的时候就会注册,您可以看一下,重启之后,是否有对应的日志可以看到:

https://github.com/NeuCharFramework/Senparc.Xncf.WeixinManager/blob/4ebe4f537b0ca6d9010cb18a90c9a869e68e5139/src/Senparc.Xncf.WeixinManager/Register.Middleware.cs#L107-L107

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants