
发送消息非常简单,只需要向以下URL发一个GET或者POST请求:
https://sc.ftqq.com/[SCKEY(登入后可见)].send
接受两个参数:
最简单的消息发送方式是通过浏览器,在地址栏输入以下URL,回车后即可发送:
https://sc.ftqq.com/[SCKEY(登入后可见)].send?text=主人服务器又挂掉啦~
在PHP中,可以直接用file_get_contents来调用:
file_get_contents('https://sc.ftqq.com/[SCKEY(登入后可见)].send?text='.urlencode('主人服务器又挂掉啦~'));
可以把它封装成一个函数:
function sc_send( $text , $desp = '' , $key = '[SCKEY(登入后可见)]' ) { $postdata = http_build_query( array( 'text' => $text, 'desp' => $desp ) ); $opts = array('http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata ) ); $context = stream_context_create($opts); return $result = file_get_contents('https://sc.ftqq.com/'.$key.'.send', false, $context); }
SCKEY是非常重要的,所以请妥善保存,不要随便告诉别人。另外同样内容的消息一分钟只能发送一次,服务器只保留一周的消息记录。