|
@@ -21,7 +21,9 @@ 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
|
|
|
+from Model.models import Device_User, Device_Info, Equipment_Info, App_Info, UID_App
|
|
|
+from Object.UidTokenObject import UidTokenObject
|
|
|
+from Ansjer.config import SERVER_DOMAIN
|
|
|
|
|
|
|
|
|
class DetectControllerView(View):
|
|
@@ -44,57 +46,58 @@ class DetectControllerView(View):
|
|
|
if operation is None:
|
|
|
return response.json(444, 'error path')
|
|
|
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)
|
|
|
+ return self.do_change_status(userID, request_dict, response)
|
|
|
else:
|
|
|
return response.json(414)
|
|
|
else:
|
|
|
return response.json(tko.code)
|
|
|
|
|
|
- def do_change_status(self, userID, uid,response):
|
|
|
+ def do_change_status(self, userID, uid, request_dict, response):
|
|
|
+ uid = request_dict.get('uid', None)
|
|
|
+ token_val = request_dict.get('token_val', None)
|
|
|
+ appBundleId = request_dict.get('appBundleId', None)
|
|
|
+ push_type = request_dict.get('push_type', None)
|
|
|
dvqs = Device_Info.objects.filter(userID_id=userID, UID=uid)
|
|
|
- if dvqs.exists():
|
|
|
- return
|
|
|
+ aiqs = App_Info.objects.filter(appBundleId=appBundleId).values('app_type')
|
|
|
+ if dvqs.exists() and aiqs.exists():
|
|
|
+ now_time = int(time.time())
|
|
|
+ try:
|
|
|
+ UID_App.objects.create(
|
|
|
+ uid=uid,
|
|
|
+ userID_id=userID,
|
|
|
+ appBundleId=appBundleId,
|
|
|
+ app_type=aiqs[0]['app_type'],
|
|
|
+ push_type=push_type,
|
|
|
+ token_val=token_val,
|
|
|
+ addTime=now_time,
|
|
|
+ updTime=now_time)
|
|
|
+ except Exception as e:
|
|
|
+ print(repr(e))
|
|
|
+ else:
|
|
|
+ utko = UidTokenObject()
|
|
|
+ utko.generate(data={'uid': uid})
|
|
|
+ detectUrl = "{SERVER_DOMAIN}cloudVod/getSts?uidToken={uidToken}". \
|
|
|
+ format(uidToken=utko.token, SERVER_DOMAIN=SERVER_DOMAIN)
|
|
|
+ return response.json(0, {'detectUrl': detectUrl})
|
|
|
else:
|
|
|
return response.json(173)
|
|
|
|
|
|
- def do_push(self, request_dict, response):
|
|
|
- device_token = request_dict.get('device_token')
|
|
|
-
|
|
|
- try:
|
|
|
- daytime = time.strftime("%Y%m%d%H%M", time.localtime(1547256103))
|
|
|
- print(daytime)
|
|
|
- pem_path = os.path.join(BASE_DIR, 'Ansjer/file/apns-dev.pem')
|
|
|
- cli = apns2.APNSClient(mode="dev", client_cert=pem_path, password='111111')
|
|
|
- alert = apns2.PayloadAlert(body="body!", title="title!")
|
|
|
- payload = apns2.Payload(alert=alert)
|
|
|
- n = apns2.Notification(payload=payload, priority=apns2.PRIORITY_LOW)
|
|
|
- res = cli.push(n=n, device_token=device_token, topic='com.ansjer.zsavcloud')
|
|
|
- # assert res.status_code == 200, res.reason
|
|
|
- # assert res.apns_id
|
|
|
- if res.status_code == 200:
|
|
|
- return response.json(0)
|
|
|
- else:
|
|
|
- return response.json(404, res.reason)
|
|
|
- except Exception as e:
|
|
|
- return response.json(10, repr(e))
|
|
|
-
|
|
|
|
|
|
class NotificationView(View):
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
request.encoding = 'utf-8'
|
|
|
operation = kwargs.get('operation')
|
|
|
- return self.validation(request.GET, operation)
|
|
|
+ return self.validation(request.GET)
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
request.encoding = 'utf-8'
|
|
|
operation = kwargs.get('operation')
|
|
|
- return self.validation(request.POST, operation)
|
|
|
+ return self.validation(request.POST)
|
|
|
|
|
|
def validation(self, request_dict, operation):
|
|
|
response = ResponseObject()
|
|
@@ -102,23 +105,26 @@ class NotificationView(View):
|
|
|
return response.json(444, 'error path')
|
|
|
uidToken = request_dict.get('uidToken', None)
|
|
|
time = request_dict.get('time', None)
|
|
|
+ utko = UidTokenObject(uidToken)
|
|
|
+ uid = utko.UID
|
|
|
+ uaqs = UID_App.objects.filter(uid=uid).values('token_val','app_type','appBundleId')
|
|
|
+ if uaqs.exists():
|
|
|
|
|
|
- # 设备主键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)
|
|
|
+ return
|
|
|
+
|
|
|
+ # # 设备主键uid
|
|
|
+ # if pushType == 'jpush':
|
|
|
+ # return self.do_jpush(request_dict)
|
|
|
+ # elif pushType == 'gcm':
|
|
|
+ # return
|
|
|
+ # elif pushType == 'apns':
|
|
|
+ # return
|
|
|
+ # else:
|
|
|
+ # return response.json(414)
|
|
|
+
|
|
|
+
|
|
|
+ def do_jpush(self, request_dict):
|
|
|
|
|
|
- def do_jpush(self):
|
|
|
jpush_config = {
|
|
|
'com.ansjer.accloud_ab': {
|
|
|
'Key': 'f0dc047e5e53fd14199de5b0',
|
|
@@ -154,10 +160,12 @@ class NotificationView(View):
|
|
|
'Key': '9d79630aa49adfa291fe2568',
|
|
|
'Secret': '4d8ff52f88136561875a0212'},
|
|
|
}
|
|
|
+ appBundleId = request_dict.get('appBundleId', None)
|
|
|
+ devToken = request_dict.get('devToken', None)
|
|
|
+
|
|
|
response = ResponseObject()
|
|
|
- devToken = ''
|
|
|
- app_key = ''
|
|
|
- master_secret = ''
|
|
|
+ app_key = jpush_config[appBundleId]['Key']
|
|
|
+ master_secret = jpush_config[appBundleId]['Secret']
|
|
|
|
|
|
# 此处换成各自的app_key和master_secret
|
|
|
_jpush = jpush.JPush(app_key, master_secret)
|
|
@@ -167,14 +175,15 @@ class NotificationView(View):
|
|
|
# push.audience = jpush.all_
|
|
|
push.audience = jpush.registration_id(devToken)
|
|
|
|
|
|
- push.notification = jpush.notification(alert="hello python jpush api")
|
|
|
+ push.notification = jpush.notification(alert="hello 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)
|
|
|
+ else:
|
|
|
+ return response.json(0)
|
|
|
|
|
|
def do_gmc(self):
|
|
|
import json
|
|
@@ -190,8 +199,7 @@ class NotificationView(View):
|
|
|
"data": data,
|
|
|
"delay_while_idle": False,
|
|
|
"time_to_live": 3600,
|
|
|
- "registration_ids": [
|
|
|
- 'eSooD4fAARg:APA91bEPenBPnSn5aXIQk56QdLOQ1Mu3hevHsekP_0eDpg458y2ZMBP6By2rVsGYIoxZrXxvkkptPKUE9CmUygBxaZXABddUWB9FyLlznRFerC7RG9X5PsEOH58xK9_aTUdkT7p6Ocld']
|
|
|
+ "registration_ids": [ 'eSooD4fAARg:APA91bEPenBPnSn5aXIQk56QdLOQ1Mu3hevHsekP_0eDpg458y2ZMBP6By2rVsGYIoxZrXxvkkptPKUE9CmUygBxaZXABddUWB9FyLlznRFerC7RG9X5PsEOH58xK9_aTUdkT7p6Ocld']
|
|
|
}
|
|
|
|
|
|
url = 'https://android.googleapis.com/gcm/send'
|
|
@@ -204,5 +212,23 @@ class NotificationView(View):
|
|
|
|
|
|
return response.json(0)
|
|
|
|
|
|
- def do_apns(self):
|
|
|
- return
|
|
|
+ def do_apns(self, request_dict, response):
|
|
|
+ device_token = request_dict.get('device_token')
|
|
|
+
|
|
|
+ try:
|
|
|
+ daytime = time.strftime("%Y%m%d%H%M", time.localtime(1547256103))
|
|
|
+ print(daytime)
|
|
|
+ pem_path = os.path.join(BASE_DIR, 'Ansjer/file/apns-dev.pem')
|
|
|
+ cli = apns2.APNSClient(mode="dev", client_cert=pem_path, password='111111')
|
|
|
+ alert = apns2.PayloadAlert(body="body!", title="title!")
|
|
|
+ payload = apns2.Payload(alert=alert)
|
|
|
+ n = apns2.Notification(payload=payload, priority=apns2.PRIORITY_LOW)
|
|
|
+ res = cli.push(n=n, device_token=device_token, topic='com.ansjer.zsavcloud')
|
|
|
+ # assert res.status_code == 200, res.reason
|
|
|
+ # assert res.apns_id
|
|
|
+ if res.status_code == 200:
|
|
|
+ return response.json(0)
|
|
|
+ else:
|
|
|
+ return response.json(404, res.reason)
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(10, repr(e))
|