simple_example.php 547 B

1234567891011121314151617181920
  1. <?php
  2. require_once __DIR__ . '/../DiscordInteraction.php';
  3. use Discord\Interaction;
  4. use Discord\InteractionResponseType;
  5. $CLIENT_PUBLIC_KEY = getenv('CLIENT_PUBLIC_KEY');
  6. $signature = $_SERVER['HTTP_X_SIGNATURE_ED25519'];
  7. $timestamp = $_SERVER['HTTP_X_SIGNATURE_TIMESTAMP'];
  8. $postData = file_get_contents('php://input');
  9. if (Interaction::verifyKey($postData, $signature, $timestamp, $CLIENT_PUBLIC_KEY)) {
  10. echo json_encode(array(
  11. 'type' => InteractionResponseType::PONG
  12. ));
  13. } else {
  14. http_response_code(401);
  15. echo "Not verified";
  16. }