Server 酱发送消息非常简单,只需要向以下 URL 发一个GET或者POST请求:
https://sc.ftqq.com/[your-key].send接受两个参数:
PHP 的代码当然是最简单的了,可以直接一个file_get_contents()就可以了
file_get_contents('https://sc.ftqq.com/[your-key].send?text='.urlencode('PHP 调用 Server 酱推送微信模板消息'));为了方便使用,我们封装成一个函数
function sendByServer($text, $desp = '', $key = '[your-key]')
{
$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);
$result = file_get_contents('https://sc.ftqq.com/'.$key.'.send', false, $context);
return $result;
}依赖requests模块,亦可以使用其他请求模块,示例代码为Python2,请求语法应该和Python3差别不大
# coding=utf-8
import requests
key = "" # 你的key
url = "https://sc.ftqq.com/%s.send"%(key)
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36'}
payload = {'text': 'Server 酱提醒标题', 'desp': 'Python 用 Server 酱推送微信模板消息内容'}
requests.post(url, params=payload, headers=headers)本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。