Thứ Năm, 1 tháng 8, 2013

apns-gcm

GCM

1. How to work

概念:
sender_id: google apiのproject id
registration_id: 端末とアプリを定義するID

1. 端末からGCM までregistration_idを要求します。
2. GCMは端末へregistration_idを返す
3. 端末から自分のサーバーにregistration_idを登録する。
4.
5. 自分のサーバーからGCMへPush notificationを出す。
内容:

Request format

To send a message, the application server issues a POST request tohttps://android.googleapis.com/gcm/send.
A message request is made of 2 parts: HTTP header and HTTP body.
The HTTP header must contain the following headers:
  • Authorization: key=YOUR_API_KEY
  • Content-Typeapplication/json for JSON; application/x-www-form-urlencoded;charset=UTF-8 for plain text.
For example:


Content-Type:application/jsonAuthorization:key=AIzaSyB-1uEai2WiUapxCs2Q0GZYzPu7Udno5aA
{
  "registration_ids" : ["APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx..."],
  "data" : {
    ...
  },
}

Body

registration_id
data.

2. Implement

2.1 Client
-  Android example
2.2  Server
https://github.com/bogdal/django-gcm


OpenSSL command


  1. These files now need to be converted to the PEM format by executing this command from the terminal:
    openssl pkcs12 -clcerts -nokeys -out apns-dev-cert.pem -in apns-dev-cert.p12
    openssl pkcs12 -nocerts -out apns-dev-key.pem -in apns-dev-key.p12
  2. If you wish to remove the passphrase, either do not set one when exporting/converting or execute:
    openssl rsa -in apns-dev-key.pem -out apns-dev-key-noenc.pem
  3. Finally, you need to combine the key and cert files into a apns-dev.pem file we will use when connecting to APNS:
    cat apns-dev-cert.pem apns-dev-key-noenc.pem > apns-dev.pem

2 nhận xét:

  1. Androi
    https://github.com/unglevan/android-gcm

    iOS
    https://github.com/samuraisam/pyapns

    Trả lờiXóa
  2. いいいね。助けられました。
    ありがとうございます

    Trả lờiXóa