Bark 自建 ios 消息推送
utils
本文字数:536 字 | 阅读时长 ≈ 3 min

Bark 自建 ios 消息推送

utils
本文字数:536 字 | 阅读时长 ≈ 3 min

1. Bark 使用

登录https://github.com/Finb/bark-server,根据下面指令下载相应的版本

For General User
1、Download precompiled binaries from the releases page
2、Add executable permissions to the bark-server binary: chmod +x bark-server
3、Start bark-server: ./bark-server --addr 0.0.0.0:8080 --data ./bark-data
4、Test the server: curl localhost:8080/ping

由于我是 linux 系统,这里我按照指示下载了文件,并执行如下命令 ./bark-server_linux_amd64 --addr 0.0.0.0:8080 --data ./bark-data,如果出现下面结果,表示安装成功

(base) root@iZuf67mlx4ftb5vohxeobnZ:~# ./bark-server_linux_amd64 --addr 0.0.0.0:8080 --data ./bark-data
2024-03-04 19:42:17    INFO    init apns client success...
2024-03-04 19:42:17    INFO    load route [register_compat] success...
2024-03-04 19:42:17    INFO    load route [misc] success...
2024-03-04 19:42:17    INFO    load route [push] success...
2024-03-04 19:42:17    INFO    load route [register] success...
2024-03-04 19:42:17    INFO    load route [push_compat] success...
2024-03-04 19:42:17    INFO    init database [./bark-data]...
2024-03-04 19:42:17    INFO    Bark Server Listen at: 0.0.0.0:8080 , Database: *database.BboltDB

 ┌───────────────────────────────────────────────────┐ 
 │                   Fiber v2.43.0                   │ 
 │                 http://[::]:8080                  │ 
 │                                                   │ 
 │ Handlers ............ 26  Processes ........... 1 │ 
 │ Prefork ....... Disabled  PID ............ 107785 │ 
 └───────────────────────────────────────────────────┘ 

2024-03-04 19:42:24     INFO    117.136.116.100 -> [ 200 ]  GET      727.98133ms /:device_key/:body => /HvAucBfeoiYtSR64Xcfqb6/%E8%BF%99%E9%87%8C%E6%94%B9%E6%88%90%E4%BD%A0%E8%87%AA%E5%B7%B1%E7%9A%84%E6%8E%A8%E9%80%81%E5%86%85%E5%AE%B9 
2024-03-04 19:42:28     INFO    117.136.116.100 -> [ 200 ]  GET      1.111296ms /register => /register?devicetoken=683cf860974683764dfbd67d74e14b449cf1e23d0eeb51c75a34051e77dcec48&key=HvAucBfeoiYtSR64Xcfqb6
(base) root@iZuf67mlx4ftb5vohxeobnZ:~# curl localhost:8080/ping
{"code":200,"message":"pong","timestamp":1709552149}

实现消息推送:https://github.com/Finb/bark-server/blob/master/docs/API_V2.md,打开上述链接,这里以 python 为例展示了怎么用

# Install the Python Requests library:
# `pip install requests`

import requests
import json


def send_request():
    # push
    # POST http://127.0.0.1:8080/push

    try:
        response = requests.post(
            url="http://127.0.0.1:8080/push",
            headers={
                "Content-Type": "application/json; charset=utf-8",
            },
            data=json.dumps({
                "body": "Test Bark Server",
                "device_key": "nysrshcqielvoxsa",
                "title": "bleem",
                "category": "myNotificationCategory",
                "sound": "minuet.caf",
                "badge": 1,
                "icon": "https://day.app/assets/images/avatar.jpg",
                "group": "test",
                "url": "https://mritd.com"
            })
        )
        print('Response HTTP Status Code: {status_code}'.format(
            status_code=response.status_code))
        print('Response HTTP Response Body: {content}'.format(
            content=response.content))
    except requests.exceptions.RequestException:
        print('HTTP Request failed')
12月 14, 2023
8月 10, 2022
10月 06, 2021