def device_token_receive(request):
if request.method != 'PUT':
return HttpResponse(status=405)
if request.body is b'':
return JsonResponse({'error': 'Bad Request'}, status=400)
query_dict = request.body.decode('utf-8')
body = json.loads(query_dict)
error = False
if 'device_token' not in body:
error = True
if 'uuid' not in body:
error = True
if 'sandbox' not in body:
error = True
if error:
return JsonResponse({'error': 'Bad Request'}, status=400)
device_token = body['device_token']
uuid = body['uuid']
sandbox = body['sandbox']
if DeviceToken.objects.filter(uuid=uuid).count() != 0:
token = DeviceToken.objects.get(uuid=uuid)
token.device_token = device_token
token.use_sandbox = sandbox
token.save()
else:
token = DeviceToken()
token.device_token = device_token
token.uuid = uuid
token.use_sandbox = sandbox
token.save()
return JsonResponse({'result': 'success'}, status=200)
评论列表
文章目录