From ffa7a490c9de3edd3bfee0348a99a367a78ca2dd Mon Sep 17 00:00:00 2001 From: JustSong Date: Thu, 22 Dec 2022 10:28:43 +0800 Subject: [PATCH] docs: update examples --- README.md | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index ea9f2a7..27527fc 100644 --- a/README.md +++ b/README.md @@ -167,7 +167,7 @@ proxy_send_timeout 300s; **示例:**
-点击展开 Bash 示例 +Bash 示例
```shell @@ -180,7 +180,8 @@ MESSAGE_PUSHER_TOKEN="666" function send_message { curl -s -X POST "$MESSAGE_PUSHER_SERVER/push/$MESSAGE_PUSHER_USERNAME" \ -H 'Content-Type: application/json' \ - -d '{"title":"'"$1"'","description":"'"$2"'", "content":"'"$3"'", "token":"'"$MESSAGE_PUSHER_TOKEN"'"}' > /dev/null + -d '{"title":"'"$1"'","description":"'"$2"'", "content":"'"$3"'", "token":"'"$MESSAGE_PUSHER_TOKEN"'"}' \ + >/dev/null } send_message 'title' 'description' 'content' @@ -190,32 +191,46 @@ send_message 'title' 'description' 'content'
-点击展开 Python 示例 +Python 示例
```python import requests -# GET 方式 -res = requests.get("https://your.domain.com/push/username?title={}&description={}&token={}".format("标题", "描述", "666")) +SERVER = "https://msgpusher.com" +USERNAME = "test" +TOKEN = "666" -# POST 方式 -res = requests.post("https://your.domain.com/push/username", json={ -"title": "标题", -"description": "描述", -"content": "**Markdown 内容**", -"token": "6666" -}) -print(res.text) -# 输出为:{"success":true,"message":"ok"} +def send_message(title, description, content): + # GET 方式 + # res = requests.get(f"{SERVER}/push/{USERNAME}?title={title}" + # f"&description={description}&content={content}&token={TOKEN}") + + # POST 方式 + res = requests.post(f"{SERVER}/push/{USERNAME}", json={ + "title": title, + "description": description, + "content": content, + "token": TOKEN + }) + res = res.json() + if res["success"]: + return None + else: + return res["message"] + + +error = send_message("标题", "描述", "**Markdown 内容**") +if error: + print(error) ```
-点击展开 Python 示例 +Go 示例
```go