发送消息
使用
最简单的使用方法,直接浏览器访问:
http://sm.rooot.me/send/app_key/title/body
如果您使用 php:
$res = file_get_contents('http://sm.rooot.me/send/app_key/title/body');
其中,app_key 和 title 为必填参数,body 为选填参数,支持 markdown 语法。
或您可以封装一个函数:
<?php
function sendMsg($app_key, $title, $body=''){
$url = 'http://sm.rooot.me/send';
$data = [
'app_key' => $app_key,
'title' => $title,
'body' => $body
];
$opts = [
'http' => [
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query($data),
'timeout' => 20
]
];
$context = stream_context_create($opts);
return file_get_contents($url,false,$context);
}
或您也可以使用 CURL 、ajax ,甚至可以使用表单发送。
总而言之,只要发送 GET 或 POST 请求并携带 app_key、title等参数到 http://sm.rooot.me/send,就可以处理您的请求并推送到您绑定的微信号中。
返回
返回格式为 json,包含四个参数
- code 状态码
- msg 简要信息
- status 状态
- dataset 服务器保存状态
| / | code | msg | status |
|---|---|---|---|
| 成功 | 0 | success | fatal |
| 失败 | 1 | needAppkey | fatal |
| 失败 | 2 | unknownAppKey | fatal |
| 失败 | 3 | needTitle | fatal |
| 警告 | 4 | toLong | warning |
| 失败 | 5 | unknownError | fatal |
| 失败 | 6 | sendError | fatal |
| 失败 | 7 | repeat | fatal |
| 失败 | 8 | msgClose | fatal |
PS
app_key非常重要,不要随意泄露。- 同样的消息一分钟内只能发送一次。
- 服务器 暂时 不主动删除您的历史消息。后期可能会删除前一个月的消息。请周知。