2014-10-07 112 views
3

我用下面的项目在我的项目能够APNS:APNS问题和Django

https://github.com/stephenmuss/django-ios-notifications

我能在我的生产应用精细发送和接收推送通知,但沙箱APNS有奇怪的问题,我无法解决。它一直不会连接到推送服务。当我手动_connect()做的APNServiceFeedbackService班,我得到以下错误:

File "/Users/MyUser/git/prod/django/ios_notifications/models.py", line 56, in _connect 
    self.connection.do_handshake() 
Error: [('SSL routines', 'SSL3_READ_BYTES', 'sslv3 alert handshake failure')] 

我试图重新创建APN证书的次数不断得到同样的错误。还有什么我失踪?

我使用的端点gateway.push.apple.comgateway.sandbox.push.apple.com用于连接服务。还有什么我应该考虑这个?我已阅读以下内容:

Apns php error "Failed to connect to APNS: 110 Connection timed out."

Converting PKCS#12 certificate into PEM using OpenSSL

Error Using PHP for iPhone APNS

+0

您是否找到答案?你如何使用TLS推送通知? – 2014-11-10 08:04:17

+0

当您连接到Apple的服务器时,您可以选择要使用的上下文。查看我在上面使用的项目以获取更多指导。该项目的工作和生产就绪。 – KVISH 2014-11-10 14:01:52

回答

5

原来,Apple在开发中将ssl上下文从SSL3更改为TLSv1。他们最终会在生产中做到这一点(不确定何时)。下面的链接显示了在接受到上述项目我拉请求:

https://github.com/stephenmuss/django-ios-notifications/commit/879d589c032b935ab2921b099fd3286440bc174e

基本上,如果你使用Python或其他语言的类似的东西使用OpenSSL.SSL.TLSv1_METHOD

虽然OpenSSL.SSL.SSLv3_METHOD在生产中工作,它可能不会在不久的将来工作。 OpenSSL.SSL.TLSv1_METHOD工作在生产和发展。

UPDATE

苹果将删除SSL生产3.0支持在2014年10月29日因狮子狗缺陷。

https://developer.apple.com/news/?id=10222014a

+0

对于那些使用apns-client的用户:目前有一个解决此问题的公开请求https://bitbucket.org/sardarnl/apns-client/pull-request/10/apple-sandbox-gateway-stopped-supporting/ DIFF – lekksi 2014-10-09 08:23:22

-1

我已经使用python-的Django的APN合作,为此,你需要三样东西URL,PORT证书由Apple提供用于身份验证。

views.py

import socket, ssl, json, struct 

theCertfile = '/tmp/abc.cert'  ## absolute path where certificate file is placed. 
ios_url = 'gateway.push.apple.com' 
ios_port = 2195 
deviceToken = '3234t54tgwg34g' ## ios device token to which you want to send notification 

def ios_push(msg, theCertfile, ios_url, ios_port, deviceToken): 

    thePayLoad = { 
       'aps': { 
        'alert':msg, 
        'sound':'default', 
        'badge':0, 
        }, 
      } 

    theHost = (ios_url, ios_port) 
    data = json.dumps(thePayLoad) 

    deviceToken = deviceToken.replace(' ','') 
    byteToken = deviceToken.decode('hex') # Python 2 

    theFormat = '!BH32sH%ds' % len(data) 
    theNotification = struct.pack(theFormat, 0, 32, byteToken, len(data), data) 

    # Create our connection using the certfile saved locally 
    ssl_sock = ssl.wrap_socket(socket.socket(socket.AF_INET, socket.SOCK_STREAM), certfile = theCertfile) 
    ssl_sock.connect(theHost) 

    # Write out our data 
    ssl_sock.write(theNotification) 

    # Close the connection -- apple would prefer that we keep 
    # a connection open and push data as needed. 
    ssl_sock.close() 

希望这会为你工作。

+1

此代码有效,但它不是答案。原因在于,对于开发,现在必须使用'TLS'而不是'SSL3'。'SSL3'仍然在生产,但在不久的将来会被删除。 – KVISH 2014-10-08 19:36:00