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

相关内容

热门资讯

固有有辅助"德普软件... 固有有辅助"德普软件"开挂(透视)辅助下载(介绍教程证实有挂);无需打开直接搜索微信(1367043...
原先有辅助"新天道辅... 原先有辅助"新天道辅助软件"开挂(透视)辅助神器(攻略教程有挂分享);无需打开直接搜索加薇13670...
往昔有辅助"开心泉州... 往昔有辅助"开心泉州小程序辅助器安全吗"开挂(透视)辅助下载(大神讲解有挂猫腻);无需打开直接搜索薇...
从前有开挂"中至抚州... 较多好评“微乐万能挂官网”开挂(透视)辅助教程 了解更多开挂安装加(136704302)微信号是一款...
素来有辅助"随意玩脚... 素来有辅助"随意玩脚本辅助工具透视"开挂(透视)辅助插件(必赢方法有挂教学);无需打开直接搜索打开薇...
起初有辅助"德扑之星... 起初有辅助"德扑之星插件"开挂(透视)辅助下载(高科技教程确实有挂);打开点击测试直接进入微信(13...
先前有辅助"浙江游戏... 先前有辅助"浙江游戏厅辅助器"开挂(透视)辅助脚本(详细教程确实有挂)这是一款可以让一直输的玩家,快...
一向有辅助"新财神辅... 一向有辅助"新财神辅助器"开挂(透视)辅助工具(详细教程有挂解密)>>您好:软件加薇13670430...
先前有辅助"开心泉州... >>您好:开心泉州免费辅助器确实是有挂的,很多玩家在这款开心泉州免费辅助器游戏中打牌都会发现很多用户...
一向有辅助"wpk透... >>您好:wpk透视辅助下载确实是有挂的,很多玩家在这款wpk透视辅助下载游戏中打牌都会发现很多用户...