gpt4 book ai didi

c# - Pushsharp 支持 Apple Push Notification Authentication Key

转载 作者:太空狗 更新时间:2023-10-29 19:46:30 26 4
gpt4 key购买 nike

是否pushsharp支持新的 Apple approach使用 Apple Push Notification Authentication Key(永不过期)而不是使用证书发送 APN?有什么方法可以将它与 pushsharp 一起使用吗?如果没有,是否有任何其他 C# 库支持它?

最佳答案

你在这里:

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方法。

关于c# - Pushsharp 支持 Apple Push Notification Authentication Key,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42332611/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com