Advertisement
Mayumi_H

ifttt to discord (with url)

Jan 14th, 2023 (edited)
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 KB | None | 0 0
  1. <?php
  2. $json = file_get_contents('php://input');//Jsonはphpから受け取るらしい
  3. $data = json_decode($json, true);//連想配列指定
  4.  
  5. if(empty($data)) die();
  6.  
  7. $webhook_url = $data["url"];
  8. $webhook_dat = $data["content"];
  9.  
  10. if($webhook_url == 'test'){
  11.     echo "test mode\n";
  12.     echo "data = ".$webhook_dat."\n";
  13. }else{
  14.     //メッセージの内容を定義(別の配列にして作成user名とか変更可)
  15.     $message = array(
  16. //    'username' => 'Twitter Bot',
  17. //    'text' => 'メッセージ内容', //Slackの場合
  18.       'content' => $webhook_dat   //Discordの場合
  19.     );
  20.     //curlで送信する
  21.     $ch = curl_init();
  22.     curl_setopt($ch, CURLOPT_URL, $webhook_url);
  23.     curl_setopt($ch, CURLOPT_POST, true);
  24.     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8'));
  25.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  26.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  27.     curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($message));
  28.     curl_exec($ch);
  29.     curl_close($ch);
  30.     echo "ok";
  31. }
  32. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement