django 如何在不一致时设置交互端点

zpgglvta  于 2023-08-08  发布在  Go
关注(0)|答案(1)|浏览(95)

我试图设置一个交互端点,但验证不起作用。

@csrf_exempt
def discord_endpoint(request):
     return JsonResponse({'type':1})

字符串
我突突道:

Validation errors:
interactions_endpoint_url: The specified interactions endpoint url could not be verified.


在我的Django应用程序中,作为discord的post响应:

b'{"application_id":"...","entitlements":[],"id":"...","token":"...","type":1,"user":{"avatar":"...","avatar_decoration":null,"discriminator":"0","global_name":"...","id":"...","public_flags":0,"username":"nickname"},"version":1}'

b5lpy0ml

b5lpy0ml1#

我找到了答案:

@csrf_exempt
def discord_endpoint(request):

    verify_key = VerifyKey(bytes.fromhex('PUBLIC CODE'))

    signature = request.headers["X-Signature-Ed25519"]
    timestamp = request.headers["X-Signature-Timestamp"]
    body = request.body.decode("utf-8")

    try:
        verify_key.verify(f'{timestamp}{body}'.encode(), bytes.fromhex(signature))
        return JsonResponse({'type':1})
    except BadSignatureError:
        print('dupa')
        return JsonResponse({'error': 'Invalid request method'}, status=405)

字符串

相关问题