Skip to content

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

@onestar1

Description

@onestar1

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

如果是重启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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions