Python语言
提示
python代码使用了requests依赖,如果使用青龙面板请先安装依赖:pip install requests
# POST 发送(推荐,内容较长时使用)
# coding:utf-8
import json
import requests
# 通道码
channel_code = '4d05f4abdb0a0c2a0269900809946903'
head = '测试标题'
body = '测试内容'
jump_url = '' # 点击消息跳转的链接,不需要可留空
api_url = 'https://www.phprm.com/services/push/send/' + channel_code
headers = {'Content-Type': 'application/json;charset=UTF-8'}
payload = {'head': head, 'body': body, 'url': jump_url}
resp = requests.post(
api_url,
headers=headers,
data=json.dumps(payload).encode('utf-8'),
timeout=10
)
print(resp.status_code)
print(resp.text)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
也可以直接传 json= 参数,requests 会自动序列化并设置 Content-Type:
# coding:utf-8
import requests
channel_code = '4d05f4abdb0a0c2a0269900809946903'
api_url = 'https://www.phprm.com/services/push/send/' + channel_code
payload = {'head': '测试标题', 'body': '测试内容', 'url': ''}
resp = requests.post(api_url, json=payload, timeout=10)
print(resp.json())
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# GET 发送(最简单,只有 head 必填)
# coding:utf-8
import requests
channel_code = '4d05f4abdb0a0c2a0269900809946903'
api_url = 'https://www.phprm.com/services/push/trigger/' + channel_code
params = {'head': '测试标题', 'body': '测试内容'} # 中文由 requests 自动编码
resp = requests.get(api_url, params=params, timeout=10)
print(resp.text)
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
注意
- 注意不要把接口地址变量命名为
url后又放进消息体,否则会把 API 地址本身当成点击跳转链接发出去。 requests的返回值是 Response 对象,打印响应内容要用resp.text,不能直接json.dumps(resp)。
Last Updated: 2026/09/11, 21:21:10