Compare commits

..

No commits in common. "39691254ca373f36322df903fdc793f77a285559" and "a2141e18b023610734ec711df09786fa42ade40e" have entirely different histories.

2 changed files with 8 additions and 23 deletions

View File

@ -38,14 +38,14 @@ public class PushController : ControllerBase
if (_env.IsDevelopment()) if (_env.IsDevelopment())
{ {
uri = "https://api.sandbox.push.apple.com"; uri = "https://api.sandbox.push.apple.com";
p12FilePath = "/volume1/AcaMate/PROJECT/Application/Back/private/AM_Push_Sandbox.pfx"; p12FilePath = "/volume1/AcaMate/PROJECT/Application/Back/private/AM_Push_Sandbox.p12";
// p12FilePath = "private/AM_Push_Sandbox.p12"; // "private/AM_Push_Sandbox.p12";
} }
else else
{ {
uri = "https://api.push.apple.com"; uri = "https://api.push.apple.com";
p12FilePath = "/volume1/AcaMate/PROJECT/Application/Back/private/AM_Push.pfx"; p12FilePath = "/volume1/AcaMate/PROJECT/Application/Back/private/AM_Push.p12";
// p12FilePath = "private/AM_Push.p12"; // "private/AM_Push.p12";
} }
var apnsTopic = "me.myds.ipstien.acamate.AcaMate"; var apnsTopic = "me.myds.ipstien.acamate.AcaMate";

View File

@ -1,6 +1,5 @@
using System.Net.Http; using System.Net.Http;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
@ -38,26 +37,12 @@ public class PushServiceWithP12
}; };
var jsonPayload = JsonSerializer.Serialize(payload); var jsonPayload = JsonSerializer.Serialize(payload);
var certificate = new X509Certificate2(p12Path, p12Password,
X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable
);
var handler = new HttpClientHandler(); var handler = new HttpClientHandler();
handler.ClientCertificates.Add(certificate);
try
{
var certificate = new X509Certificate2(p12Path, p12Password,
X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);
handler.ClientCertificates.Add(certificate);
}
catch (CryptographicException ex)
{
Console.WriteLine($"CryptographicException: {ex.Message}");
}
catch (Exception ex)
{
Console.WriteLine($"Unexpected error: {ex.Message}");
}
using var client = new HttpClient(handler) using var client = new HttpClient(handler)
{ {