我使用以下代码通过苹果推送通知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"
}
)
每次尝试发送通知时,它总是抛出错误,知道它可能来自哪里吗?