Last active
September 12, 2016 01:47
-
-
Save shyazusa/518e53fbd2dcbd1ec2195e0fc5c79253 to your computer and use it in GitHub Desktop.
PHPからSlackへチャットを送る
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
<?php | |
// slack | |
$mes = print_r('', true); // ここにメッセージなり配列変数ブチ込んで | |
$headers = array(); | |
$url = 'https://hooks.slack.com/services/hoge/fuga/piyo/'; | |
$payload = array( | |
'text' => $mes, | |
// 'text' => '<@shy_azusa>: '.$mes, // @したい場合はこっち | |
'channel' => '#server_log', // 好きなチャンネルへどうぞ | |
); | |
$params = array('payload' => json_encode($payload)); | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $params); | |
curl_exec($ch); | |
curl_error($ch); | |
curl_close($ch); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment