ftqq发送消息
http://sc.ftqq.com/?c=code
key
SCU85809T3b5b8451bc911ad1cbc6cabb5f7cfcd95e52405a05a71发送消息非常简单,只需要向以下URL发一个GET或者POST请求:
https://sc.ftqq.com/SCU85809T3b5b8451bc911ad1cbc6cabb5f7cfcd95e52405a05a71.send接受两个参数:
text:消息标题,最长为256,必填。
desp:消息内容,最长64Kb,可空,支持MarkDown。
举例
https://sc.ftqq.com/SCU85809T3b5b8451bc911ad1cbc6cabb5f7cfcd95e52405a05a71.send?text=主人服务器又挂掉啦~在PHP中,可以直接用file_get_contents来调用:
file_get_contents(‘ https://sc.ftqq.com/SCU85809T3b5b8451bc911ad1cbc6cabb5f7cfcd95e52405a05a71.send?text='.urlencode('主人服务器又挂掉啦~’));
可以把它封装成一个函数:
function sc_send( $text , $desp = '' , $key = 'SCU85809T3b5b8451bc911ad1cbc6cabb5f7cfcd95e52405a05a71' )
{
$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是非常重要的,所以请妥善保存,不要随便告诉别人。另外同样内容的消息一分钟只能发送一次,服务器只保留一周的消息记录。