首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Server 酱签到提醒

Server 酱签到提醒

作者头像
AWF
修改2020-04-26 10:13:20
修改2020-04-26 10:13:20
1.6K0
举报
文章被收录于专栏:个人收藏个人收藏

转载自@沈唁

Server 酱发送消息非常简单,只需要向以下 URL 发一个GET或者POST请求:

代码语言:javascript
复制
https://sc.ftqq.com/[your-key].send

接受两个参数:

  • text:消息标题,最长为 256,必填
  • desp:消息内容,最长 64Kb,可空,支持 MarkDown

PHP 版

PHP 的代码当然是最简单的了,可以直接一个file_get_contents()就可以了

代码语言:javascript
复制
file_get_contents('https://sc.ftqq.com/[your-key].send?text='.urlencode('PHP 调用 Server 酱推送微信模板消息'));

为了方便使用,我们封装成一个函数

代码语言:javascript
复制
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;
}

Python 版

依赖requests模块,亦可以使用其他请求模块,示例代码为Python2,请求语法应该和Python3差别不大

代码语言:javascript
复制
# 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 删除。

评论
作者已关闭评论
0 条评论
热度
最新
推荐阅读
目录
  • 转载自@沈唁
    • PHP 版
    • Python 版
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档