【问题标题】:Pushsharp support of Apple Push Notification Authentication Key对 Apple Push Notification Authentication Key 的 Pushshap 支持
【发布时间】:2017-07-09 00:38:44
【问题描述】:

pushsharp 是否支持新的Apple approach 使用 Apple 推送通知身份验证密钥(永不过期)而不是使用证书来发送 APN?有什么方法可以与pushsharp一起使用吗?如果没有,是否有其他 C# 库支持它?

【问题讨论】:

  • 您好,请问您是否找到了这个问题的答案?谢谢。
  • 没有。我认为到目前为止没有任何支持。我现在只是继续使用旧代码和证书。希望他们将来会添加此功能

标签: c# apple-push-notifications pushsharp


【解决方案1】:

你在这里:

private string GetToken()
{
    var algorithm = "ES256";
    var teamID = "teamID";
    var apnsKeyID = "apnsKeyID";
    var apnsAuthKeyPath = @"apnsAuthKeyPath";
    var epochNow = DateTimeOffset.Now.ToUnixTimeSeconds();

    var header = new Dictionary<string, object>()
    {
        { "alg", algorithm },
        { "kid" , apnsKeyID }
    };
    var payload = new Dictionary<string, object>()
    {
        { "iss", teamID },
        { "iat", epochNow }
    };

    var privateKey = GetPrivateKey(apnsAuthKeyPath);
    var token = Jose.JWT.Encode(payload, privateKey, algorithm: Jose.JwsAlgorithm.ES256, extraHeaders: header);
    return token;
}
private CngKey GetPrivateKey(string apnsAuthKey)
{
    using (var reader = File.OpenText(apnsAuthKey))
    {
        var ecPrivateKeyParameters = (ECPrivateKeyParameters)new PemReader(reader).ReadObject();
        var x = ecPrivateKeyParameters.Parameters.G.AffineXCoord.GetEncoded();
        var y = ecPrivateKeyParameters.Parameters.G.AffineYCoord.GetEncoded();
        var d = ecPrivateKeyParameters.D.ToByteArrayUnsigned();
        return EccKey.New(x, y, d);
    }
}

那么你可以简单地调用apns中的send方法。

【讨论】:

    猜你喜欢
    • 2023-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-14
    • 1970-01-01
    • 2011-01-18
    • 1970-01-01
    相关资源
    最近更新 更多