immobiliare / ApnsPHP

ApnsPHP: Apple Push Notification & Feedback Provider
BSD 3-Clause "New" or "Revised" License
1.44k stars 452 forks source link

push notification production problem #104

Open roozbeh360 opened 8 years ago

roozbeh360 commented 8 years ago

hi i have problem in push notification when using production environment . the out put is :

INFO: Trying tls://gateway.push.apple.com:2195... INFO: Connected to tls://gateway.push.apple.com:2195. INFO: Sending messages queue, run #1: 1 message(s) left in queue. ApnsPHP[5792]: STATUS: Sending message ID 1 custom identifier: Message-Badge-3: 167 bytes. ApnsPHP[5792]: INFO: Disconnected.

why i cant receive any notification ? what's steps i must follow for production ?

marsgpl commented 8 years ago

check your device token. if you are using old APNS protocol (v1), APNS disconnects you when you pass invalid device token. Make sure the token is in format [a-f0-9]{64} (inside php code)

free6k commented 8 years ago

I also have this problem. Apnsphp dont working, but simple ruby script work. Why so?

#!/usr/bin/env ruby

require 'openssl'
require 'socket'
require 'json'

token = "XXX"
cert = File.read("XXX/production.pem")
ctx = OpenSSL::SSL::SSLContext.new
ctx.key = OpenSSL::PKey::RSA.new(cert, '') #set passphrase here, if any
ctx.cert = OpenSSL::X509::Certificate.new(cert)

sock = TCPSocket.new('gateway.push.apple.com', 2195) #development gateway
ssl = OpenSSL::SSL::SSLSocket.new(sock, ctx)
ssl.connect

payload = {"aps" => {"alert" => "Oh hai!", "badge" => 1, "sound" => 'default'}}
json = payload.to_json()
token =  [token.delete(' ')].pack('H*') #something like 2c0cad 01d1465 346786a9 3a07613f2 b03f0b94b6 8dde3993 d9017224 ad068d36
apnsMessage = "\0\0 #{token}\0#{json.length.chr}#{json}"
ssl.write(apnsMessage)

ssl.close
sock.close

puts "End"