我使用以下代码通过apple推送通知api发送通知。它工作得很好,直到几天前它开始抛出一个错误:
插座被远程关闭
这是我正在使用的代码:
p8key = "*****"
private_key = OpenSSL::PKey::EC.new p8key
token = JWT.encode(
{
'iss': "*****",
'iat': DateTime.now().to_time.to_i
},
private_key,
'***',
header_fields=
{
'alg':"***",
"kid": "***"
}
)
client = NetHttp2::Client.new("https://api.push.apple.com:443")
client.on(:error) { |exception| puts "Exception has been raised: #{exception}" }
msg = "Hello"
body = { aps: { alert: msg, sound: "sound.mp3", badge: 1 } }.to_json
request = client.call(
:post,
"/3/device/#{recipient.push_token}",
body: body,
headers:
{
'authorization' => "bearer #{token}",
"apns-topic" => "com.dogtime.dogtimeinit"
}
)
每次我尝试发送通知时,它总是抛出错误,知道它可能来自哪里吗?