Browse Source

gcm调试

chenjunkai 6 years ago
parent
commit
90d8810497
1 changed files with 9 additions and 5 deletions
  1. 9 5
      Controller/Test.py

+ 9 - 5
Controller/Test.py

@@ -27,9 +27,16 @@ import time
 class Test(View):
 
     def get(self, request, *args, **kwargs):
+        return self.do_gcm_push(request)
+
+    def do_gcm_push(self,request):
         import json
         import requests
-
+        response = ResponseObject()
+        rg_id = request.GET.get('rg_id', '')
+        serverKey = request.GET.get('serverKey', '')
+        if not rg_id or not serverKey:
+            return response.json(444)
         data = {
             "key1": "abc",
             "key2": "def"
@@ -40,13 +47,10 @@ class Test(View):
             "data": data,
             "delay_while_idle": False,
             "time_to_live": 3600,
-            "registration_ids": [
-                'eSooD4fAARg:APA91bEPenBPnSn5aXIQk56QdLOQ1Mu3hevHsekP_0eDpg458y2ZMBP6By2rVsGYIoxZrXxvkkptPKUE9CmUygBxaZXABddUWB9FyLlznRFerC7RG9X5PsEOH58xK9_aTUdkT7p6Ocld']
+            "registration_ids": [rg_id]
         }
 
         url = 'https://android.googleapis.com/gcm/send'
-        serverKey = "AAAAb9YP3rk:APA91bHu8u-CTpcd0g6lKPo0WNVqCi8jZub1cPPbSAY9AucT1HxlF65ZDUko9iG8q2ch17bwu9YWHpK1xI1gHSRXCslLvZlXEmHZC0AG3JKg15XuUvlFKACIajUFV-pOeGRT8tM6-31I"
-
         data = json.dumps(json_data).encode('utf-8')
         headers = {'Content-Type': 'application/json', 'Authorization': 'key=%s' % serverKey}
         req = requests.post(url, data, headers=headers)