|
@@ -19,6 +19,9 @@ import apns2
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
import os
|
|
|
from Ansjer.config import BASE_DIR
|
|
|
+from Object.TokenObject import TokenObject
|
|
|
+import jpush as jpush
|
|
|
+from Model.models import Device_User, Device_Info, Equipment_Info, App_Info,UID_App
|
|
|
|
|
|
|
|
|
class DetectControllerView(View):
|
|
@@ -29,19 +32,35 @@ class DetectControllerView(View):
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
request.encoding = 'utf-8'
|
|
|
operation = kwargs.get('operation')
|
|
|
- return self.validation(request.GET, request, operation)
|
|
|
+ return self.validation(request.GET, operation)
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
request.encoding = 'utf-8'
|
|
|
operation = kwargs.get('operation')
|
|
|
- return self.validation(request.POST, request, operation)
|
|
|
+ return self.validation(request.POST, operation)
|
|
|
|
|
|
- def validation(self, request_dict, request, operation):
|
|
|
+ def validation(self, request_dict, operation):
|
|
|
response = ResponseObject()
|
|
|
if operation is None:
|
|
|
return response.json(444, 'error path')
|
|
|
- if operation == 'push':
|
|
|
- return self.do_push(request_dict, response)
|
|
|
+ token = request_dict.get('token', None)
|
|
|
+ uid = request_dict.get('uid', None)
|
|
|
+ tko = TokenObject(token)
|
|
|
+ if tko.code == 0:
|
|
|
+ userID = tko.userID
|
|
|
+ if operation == 'changeStatus':
|
|
|
+ return self.do_change_status(userID, uid, response)
|
|
|
+ else:
|
|
|
+ return response.json(414)
|
|
|
+ else:
|
|
|
+ return response.json(tko.code)
|
|
|
+
|
|
|
+ def do_change_status(self, userID, uid,response):
|
|
|
+ dvqs = Device_Info.objects.filter(userID_id=userID, UID=uid)
|
|
|
+ if dvqs.exists():
|
|
|
+ return
|
|
|
+ else:
|
|
|
+ return response.json(173)
|
|
|
|
|
|
def do_push(self, request_dict, response):
|
|
|
device_token = request_dict.get('device_token')
|
|
@@ -64,4 +83,126 @@ class DetectControllerView(View):
|
|
|
except Exception as e:
|
|
|
return response.json(10, repr(e))
|
|
|
|
|
|
- # def do_
|
|
|
+
|
|
|
+class NotificationView(View):
|
|
|
+
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ operation = kwargs.get('operation')
|
|
|
+ return self.validation(request.GET, operation)
|
|
|
+
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ operation = kwargs.get('operation')
|
|
|
+ return self.validation(request.POST, operation)
|
|
|
+
|
|
|
+ def validation(self, request_dict, operation):
|
|
|
+ response = ResponseObject()
|
|
|
+ if operation is None:
|
|
|
+ return response.json(444, 'error path')
|
|
|
+ uidToken = request_dict.get('uidToken', None)
|
|
|
+ time = request_dict.get('time', None)
|
|
|
+
|
|
|
+ # 设备主键uid
|
|
|
+ tko = TokenObject(uidToken)
|
|
|
+ response.lang = tko.lang
|
|
|
+ if tko.code != 0:
|
|
|
+ if operation == 'jpush':
|
|
|
+ return
|
|
|
+ elif operation == 'gcm':
|
|
|
+ return
|
|
|
+ elif operation == 'apns':
|
|
|
+ return
|
|
|
+ else:
|
|
|
+ return response.json(414)
|
|
|
+ else:
|
|
|
+ return response.json(tko.code)
|
|
|
+
|
|
|
+ def do_jpush(self):
|
|
|
+ jpush_config = {
|
|
|
+ 'com.ansjer.accloud_ab': {
|
|
|
+ 'Key': 'f0dc047e5e53fd14199de5b0',
|
|
|
+ 'Secret': 'aa7f7db33e9f0a7f3871aa1c'},
|
|
|
+ 'com.ansjer.adcloud_ab': {
|
|
|
+ 'Key': '76d97b535185114985608234',
|
|
|
+ 'Secret': 'c9a92b301043cc9c52778692'},
|
|
|
+ 'com.ansjer.zccloud_ab': {
|
|
|
+ 'Key': 'd9924f56d3cc7c6017965130',
|
|
|
+ 'Secret': '869d832d126a232f158b5987'},
|
|
|
+ 'com.ansjer.loocamccloud_ab': {
|
|
|
+ 'Key': 'd1cc44797b4642b0e05304fe',
|
|
|
+ 'Secret': 'c3e8b4ca8c576de61401e56a'},
|
|
|
+ 'com.ansjer.loocamdcloud_ab': {
|
|
|
+ 'Key': '76d97b535185114985608234',
|
|
|
+ 'Secret': 'c9a92b301043cc9c52778692'},
|
|
|
+ 'com.ansjer.zccloud_a': {
|
|
|
+ 'Key': '57de2a80d68bf270fd6bdf5a',
|
|
|
+ 'Secret': '3d354eb6a0b49c2610decf42'},
|
|
|
+ 'com.ansjer.accloud_a': {
|
|
|
+ 'Key': 'ff95ee685f49c0dc4013347b',
|
|
|
+ 'Secret': 'de2c20959f5516fdeeafe78e'},
|
|
|
+ 'com.ansjer.adcloud_a': {
|
|
|
+ 'Key': '2e47eb1aee9b164460df3668',
|
|
|
+ 'Secret': 'b9137d8d684bc248f1809b6d'},
|
|
|
+ 'com.ansjer.loocamccloud_a': {
|
|
|
+ 'Key': '23c9213215c7ca0ec945629b',
|
|
|
+ 'Secret': '81e4b1e859cc8387e2e6c431'},
|
|
|
+ 'com.ansjer.loocamdcloud_a': {
|
|
|
+ 'Key': '1dbdd60a16e9892d6f68a073',
|
|
|
+ 'Secret': '80a97690e7e043109059b403'},
|
|
|
+ 'com.ansjer.customizedb_a': {
|
|
|
+ 'Key': '9d79630aa49adfa291fe2568',
|
|
|
+ 'Secret': '4d8ff52f88136561875a0212'},
|
|
|
+ }
|
|
|
+ response = ResponseObject()
|
|
|
+ devToken = ''
|
|
|
+ app_key = ''
|
|
|
+ master_secret = ''
|
|
|
+
|
|
|
+ # 此处换成各自的app_key和master_secret
|
|
|
+ _jpush = jpush.JPush(app_key, master_secret)
|
|
|
+ push = _jpush.create_push()
|
|
|
+ # if you set the logging level to "DEBUG",it will show the debug logging.
|
|
|
+ _jpush.set_logging("DEBUG")
|
|
|
+ # push.audience = jpush.all_
|
|
|
+ push.audience = jpush.registration_id(devToken)
|
|
|
+
|
|
|
+ push.notification = jpush.notification(alert="hello python jpush api")
|
|
|
+ push.platform = jpush.all_
|
|
|
+ try:
|
|
|
+ res = push.send()
|
|
|
+ except Exception as e:
|
|
|
+ print("Exception")
|
|
|
+ return response.json(10, repr(e))
|
|
|
+ return response.json(0)
|
|
|
+
|
|
|
+ def do_gmc(self):
|
|
|
+ import json
|
|
|
+ import requests
|
|
|
+
|
|
|
+ data = {
|
|
|
+ "key1": "abc",
|
|
|
+ "key2": "def"
|
|
|
+ }
|
|
|
+
|
|
|
+ json_data = {
|
|
|
+ "collapse_key": "WhatYouWant",
|
|
|
+ "data": data,
|
|
|
+ "delay_while_idle": False,
|
|
|
+ "time_to_live": 3600,
|
|
|
+ "registration_ids": [
|
|
|
+ 'eSooD4fAARg:APA91bEPenBPnSn5aXIQk56QdLOQ1Mu3hevHsekP_0eDpg458y2ZMBP6By2rVsGYIoxZrXxvkkptPKUE9CmUygBxaZXABddUWB9FyLlznRFerC7RG9X5PsEOH58xK9_aTUdkT7p6Ocld']
|
|
|
+ }
|
|
|
+
|
|
|
+ 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)
|
|
|
+ response = ResponseObject()
|
|
|
+
|
|
|
+ return response.json(0)
|
|
|
+
|
|
|
+ def do_apns(self):
|
|
|
+ return
|