推送通知问题(APNS)

时间:2020-02-11 12:14:05

标签: c# push-notification apple-push-notifications asp.net-core-2.1 windows-server-2019

发布.Net Core 2.1 api项目后发现一些问题。我创建了一个用于制作推送通知(IOS)的.Net核心api项目,只要该api在本地主机中,它就可以正常工作。发布api后,它将无法像在localhost中那样正常工作。 api已发布在Windows Server-2019中 并托管在IIS 10中。服务器中已经安装了ASP.NET Core必备组件。 P8private 键用于发出推送通知。

注意:- 我正在将ApnServerType用作“开发(https://api.development.push.apple.com:443)”

我正在使用的api代码是

    [HttpPost]
    [ProducesResponseType(200)]
    [ProducesResponseType(400)]
    [ProducesResponseType(500)]
    public async Task<IActionResult> Post([FromBody] input value)
    {
        var response = new SingleResponse<ApnsResponse>();
        try
        {
            if (!string.IsNullOrEmpty(value.messageTitle) && !string.IsNullOrEmpty(value.messageBody) && !string.IsNullOrEmpty(value.deviceId) && !string.IsNullOrEmpty(value.confidentialKey))
            {
                if (value.confidentialKey == ConfidentialKey)
                {
                    var respones = new ApnsResponse();
                    using (var apn = new ApnSender(p8privateKey, KeyID, TeamID, BundleID, ApnServerType.Development))
                    {
                        var notificationMessageType1 = new NotificationMessageType1();
                        notificationMessageType1.aps = new messageType1();
                        notificationMessageType1.aps.alert = new alertType1();
                        notificationMessageType1.aps.alert.title = value.messageTitle;
                        notificationMessageType1.aps.alert.body = value.messageBody;
                        response.Model = await apn.SendAsync(value.deviceId, notificationMessageType1);
                        response.Message = "Success";
                    }
                }
            }
        }
        catch (Exception ex)
        {
            response.DidError = true;
            response.Message = "Failed";
            response.ErrorMessage = ex.Message;
            response.ErrorException = new Exception();
            response.ErrorException = ex;
        }
        return response.ToHttpResponse();
    }

Localhost

中运行时,来自api的响应

Localhost response

服务器

运行api时获得的响应

enter image description here

0 个答案:

没有答案