2014-10-07 109 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