我在 c# asp.net 上的项目,对于苹果钱包 pkpass,注册和注销任务工作完美,当我调试工作 amazin 但是,当我尝试发送消息时,调试一切正常,但通知没有到达客户端(移动) 任何人都可以在这个问题上帮助我们吗?注意:正如他们在苹果文档中提到的那样。从 2021 年 3 月开始,他们将使用 tls12 和 http/2。我没明白 http/2 的意思
private void SendEmptyPushNotification(payload objpayload, string pushToken)
{
string server = "api.push.apple.com"; // Production getway.push.apple.com and 2195 is legacy now is 2197
using (TcpClient tcpClient = new TcpClient(server, 443))
{
using (SslStream sslStream = new SslStream(tcpClient.GetStream()))
{
try
{
string path_to_apple_certificate = VapidKeys.PassTypeCertificateP ;
byte[] applecertificateData = File.ReadAllBytes(path_to_apple_certificate);
X509Certificate2Collection certs = new X509Certificate2Collection();
X509Certificate cert = GetCertificateFromBytes(applecertificateData, VapidKeys.PassTypeCertificatePassword); // here the pass
certs.Add(cert);
sslStream.AuthenticateAsClient(server, certs, SslProtocols.Tls12, false);
}
catch (AuthenticationException exp)
{
string messagee = exp.Message;
throw new AuthenticationException(exp.Message);
int x = 5;
int y = 10;
int l = x + y;
Console.Write(exp.Message);
}
catch (IOException exp)
{
throw new IOException(exp.Message);
}
MemoryStream memoryStream = new MemoryStream();
BinaryWriter writer = new BinaryWriter(memoryStream);
writer.Write((byte)0);
writer.Write((byte)0);
writer.Write((byte)32);
writer.Write(ConvertHexStringToByteArray(pushToken.ToUpper()));
//string payload = "{\"aps\":\"\"}";
string payload = "{\"aps\":{\"badge\":1,\"sound\":\"oven.caf\",\"alert\":\"" + "hello testing" + "\"}}";// @"{""aps"":{""alert"":{""Title"":"" title hello "", ""body"":"" bodey hello ""},},}";// string payload = "{\"aps\":{\"alert\":\"" + "Title " + objpayload.title + ": " + objpayload.message + "\"}}";
writer.Write((byte)0);
writer.Write((byte)payload.Length);
byte[] b1 = System.Text.Encoding.UTF8.GetBytes(payload);
writer.Write(b1);
writer.Flush();
byte[] array = memoryStream.ToArray();
sslStream.Write(array);
sslStream.Flush();
tcpClient.Close();
}
}
}