AsyncpushnotificationtoMicrosoftAuthenticatorApp
创始人
2024-09-21 08:30:19
0

'Async push notification to Microsoft Authenticator App”改为“将异步推送通知到 Microsoft Authenticator 应用程序”,实现方法如下所示:

首先需要安装 Microsoft 的推送通知服务 NuGet 包。在代码中创建一个 PushModel,包含推送内容信息。然后创建一个 PushHub 来执行消息的实际推送,并通过 Microsoft 帐号的用户 ID 检查已注册 Authenticator 应用程序的用户。最后,将推送通知对象序列化为 JSON 字符串并推送到 Microsoft。示例代码如下:

using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;

namespace PushNotificationDemo
{
    public class PushModel
    {
        public string UserId { get; set; }
        public string Title { get; set; }
        public string Message { get; set; }
        public string Data { get; set; }
    }

    [HubName("pushHub")]
    public class PushHub : Hub
    {
        public void PushNotification(PushModel model)
        {
            var pushService = new PushService();
            pushService.Push(model);
        }
    }

    public class PushService
    {
        public async Task Push(PushModel model)
        {
            var microsoftUrl = "https://login.microsoftonline.com/common/oauth2/token";
            var clientId = "";
            var clientSecret = "";
            var authenticatorUrl = "https://graph.microsoft.com/v1.0/me/appRoleAssignedTo";
            var tokensUrl = "https://graph.microsoft.com/v1.0/me/microsoft.graph.get";

            var token = await GetAccessToken(microsoftUrl, clientId, clientSecret);

            var authenticatorService = new AuthenticatorService();
            var userId = authenticatorService.GetRegisteredUserId(token, authenticatorUrl);

            if (string.IsNullOrEmpty(userId))
            {
                // Throw exception here or handle it as per requirement
            }

            var pushNotification = new PushNotification();
            pushNotification.PushUserId = userId;
            pushNotification.Title = model.Title;
            pushNotification.Message = model.Message

相关内容

热门资讯

透视好牌"wepok... 1、透视好牌"wepoker分析"详细辅助靠谱教程(原生是有挂);详细教程。2、wepoker分析透...
透视挂透视"约局吧怎... 透视挂透视"约局吧怎么看有没有挂"详细辅助黑科技教程(先前真的是有挂)1、很好的工具软件,可以解锁游...
透视好牌"佛手大菠萝... 透视好牌"佛手大菠萝辅助"详细辅助细节揭秘(竟然是有挂);玩家必备必赢加哟《136704302》。各...
透视辅助"sohoo... 透视辅助"sohoo poker辅助"详细辅助AI教程(其实是真的有挂);玩家必备必赢加哟《1367...
透视智能ai"hhp... 透视智能ai"hhpoker买挂"详细辅助必胜教程(原本是有挂);玩家必备必赢加哟《13670430...
透视辅助"哈糖大菠萝... 自定义哈糖大菠萝挂系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅助器,不管你是...
透视辅助"wepok... 透视辅助"wepoker辅助器免费"详细辅助软件教程(固有真的是有挂)是一款可以让一直输的玩家,快速...
透视透视"pokep... 透视透视"pokeplus脚本"详细辅助AI教程(确实有挂);pokeplus脚本软件透明挂更新新赛...
透视黑科技"拱趴大菠... 透视黑科技"拱趴大菠萝有挂吗"详细辅助新2025教程(先前有挂);最新版2024是一款经典耐玩的益智...
透视苹果版"大菠萝免... 1、透视苹果版"大菠萝免费辅助"详细辅助分享教程(先前是真的有挂)。2、大菠萝免费辅助透视辅助简单,...