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

相关内容

热门资讯

透视关于"aapok... 透视关于"aapoker真的假的"竟然真的有辅助神器(哔哩哔哩)1、下载好aapoker真的假的脚本...
透视揭露"hh po... 透视揭露"hh poker透视器下载"果然存在有辅助方法(哔哩哔哩)1)hh poker透视器下载有...
透视教你"wepok... 透视教你"wepoker辅助器是真的吗"本来真的是有辅助方法(哔哩哔哩)进入游戏-大厅左侧-新手福利...
透视总结"aapok... 透视总结"aapoker辅助插件工具"好像有辅助插件(哔哩哔哩)1、上手简单,内置详细流程视频教学,...
透视透视"aapok... 透视透视"aapoker怎么设置抽水"总是真的是有辅助神器(哔哩哔哩)1、aapoker怎么设置抽水...
透视辅助"poker... 透视辅助"poker world辅助"真是是真的辅助挂(哔哩哔哩)1、这是跨平台的poker wor...
透视有挂"德州辅助工... 透视有挂"德州辅助工具到底怎么样"果然有辅助挂(哔哩哔哩)1)德州辅助工具到底怎么样免费钻石:进一步...
透视解谜"wpk俱乐... 透视解谜"wpk俱乐部怎么作必弊"一直是真的辅助软件(哔哩哔哩)1、wpk俱乐部怎么作必弊破解器简单...
透视教你"wepok... 透视教你"wepoker有辅助工具吗"一贯存在有辅助工具(哔哩哔哩)1、打开软件启动之后找到中间准星...
透视推荐"poker... 透视推荐"pokerworld修改器"原来真的是有辅助器(哔哩哔哩)1、下载好pokerworld修...