Created
July 22, 2022 20:06
-
-
Save mdsdias/d802161688ada240b16edc412d4b6ae3 to your computer and use it in GitHub Desktop.
a webhook with php curl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function postToDiscord($username, $message, $url) | |
{ | |
$payload = json_encode(array( | |
'username' => $username, | |
//'avatar_url' => $this->avatar, | |
'content' => $message, | |
//'embeds' => $embeds, | |
//'tts' => $tts, | |
)); | |
$dc = curl_init(); | |
curl_setopt($dc, CURLOPT_URL, $url); | |
curl_setopt($dc, CURLOPT_POST, TRUE); | |
curl_setopt($dc, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); | |
curl_setopt($dc, CURLOPT_RETURNTRANSFER, TRUE); | |
curl_setopt($dc, CURLOPT_SSL_VERIFYHOST, 2); | |
curl_setopt($dc, CURLOPT_SSL_VERIFYPEER, 1); | |
curl_setopt($dc, CURLOPT_POSTFIELDS, $payload); | |
$result = curl_exec($dc); | |
curl_close($dc); | |
return $json_result = json_decode($result, true); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment