-
Notifications
You must be signed in to change notification settings - Fork 137
Description
公众号管理 第一次编辑后,会执行一次全局注册。
如果是重启netcore 后, 再问一次公众号 就会出现,
Unhandled exception. Senparc.Weixin.Exceptions.UnRegisterAppIdException: 此appId(wx09c4a176ef1ec44d)尚未注册,请先使用AccessTokenContainer.Register完成注册(全局执行一次即可)!

需要增加判断 或者,每次启动的时候 自动注册公众号列表的内容,否则就要重新编辑保存一次 公众号。
在
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);
}