Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $json = file_get_contents('php://input');//Jsonはphpから受け取るらしい
- $data = json_decode($json, true);//連想配列指定
- if(empty($data)) die();
- $webhook_url = $data["url"];
- $webhook_dat = $data["content"];
- if($webhook_url == 'test'){
- echo "test mode\n";
- echo "data = ".$webhook_dat."\n";
- }else{
- //メッセージの内容を定義(別の配列にして作成user名とか変更可)
- $message = array(
- // 'username' => 'Twitter Bot',
- // 'text' => 'メッセージ内容', //Slackの場合
- 'content' => $webhook_dat //Discordの場合
- );
- //curlで送信する
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $webhook_url);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8'));
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($message));
- curl_exec($ch);
- curl_close($ch);
- echo "ok";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement