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

相关内容

热门资讯

透视挂!打大a开挂神器免费下载... 透视挂!打大a开挂神器免费下载,皮皮胡子辅助,透明挂教程(竟然有挂)-哔哩哔哩;小薇(透视辅助)致您...
发现一款!掌中乐游戏中心破解版... 发现一款!掌中乐游戏中心破解版,微乐家乡破解,实用技巧(有挂规律)-哔哩哔哩;1、不需要AI权限,帮...
总算了解!欢乐对决辅助菜单,榕... 总算了解!欢乐对决辅助菜单,榕城510k有没有挂,技巧教程(揭秘有挂)-哔哩哔哩;1、超多福利:超高...
揭秘攻略!乐乐围棋入门辅助,新... 揭秘攻略!乐乐围棋入门辅助,新久久辅助器,系统教程(今日头条)-哔哩哔哩;小薇(透视辅助)致您一封信...
我来分享!决胜游戏辅助器,皮皮... 《我来分享!决胜游戏辅助器,皮皮跑子胡子修改器,攻略教程!(有挂细节)-哔哩哔哩》 皮皮跑子胡子修改...
我来教教大家!蜀山四川破解好友... 我来教教大家!蜀山四川破解好友版辅助,邯郸胡乐修改器,揭秘攻略(有挂猫腻)-哔哩哔哩;人气非常高,a...
透视有挂!泸州大二新手攻略,新... 【福星临门,好运相随】;透视有挂!泸州大二新手攻略,新九哥开挂,线上教程(发现有挂)-哔哩哔哩;暗藏...
玩家攻略推荐!宝宝浙江辅助器,... 玩家攻略推荐!宝宝浙江辅助器,新海贝之城脚本,曝光教程(有挂细节)-哔哩哔哩;1、很好的新海贝之城脚...
科普常识!上饶辅助,龙江填大坑... 科普常识!上饶辅助,龙江填大坑视频攻略,细节揭秘(有挂秘籍)-哔哩哔哩;超受欢迎的龙江填大坑视频攻略...
让我来分享经验!牛总管辅助方法... 让我来分享经验!牛总管辅助方法,葫芦娃七子降妖破解版,玩家教你(有挂神器)-哔哩哔哩;1、完成葫芦娃...