# Chanify **Repository Path**: DaTeTOMe/Chanify ## Basic Information - **Project Name**: Chanify - **Description**: Chanify是一个简单的消息接收分类应用, 可以通过Webhook或API来发送推送消息 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: dev - **Homepage**: https://www.oschina.net/p/chanify - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 5 - **Created**: 2021-06-14 - **Last Updated**: 2021-06-14 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Chanify [![Docker](https://img.shields.io/docker/v/wizjin/chanify?sort=semver&logo=docker&style=flat-square)](https://hub.docker.com/r/wizjin/chanify) [![Release](https://img.shields.io/github/v/release/chanify/chanify?logo=github&style=flat-square)](https://github.com/chanify/chanify/releases/latest) [![iTunes App Store](https://img.shields.io/itunes/v/1531546573?logo=apple&style=flat-square)](https://itunes.apple.com/cn/app/id1531546573) [![WebStore](https://img.shields.io/chrome-web-store/v/llpdpmhkemkjeeigibdamadahmhoebdg?logo=Google%20Chrome&logoColor=white&style=flat-square)](https://chrome.google.com/webstore/detail/chanify/llpdpmhkemkjeeigibdamadahmhoebdg) [![Workflow](https://img.shields.io/github/workflow/status/chanify/chanify/ci?label=build&logo=github&style=flat-square)](https://github.com/chanify/chanify/actions?workflow=ci) [![CodeQL](https://img.shields.io/github/workflow/status/chanify/chanify/codeql?label=codeql&logo=github&style=flat-square)](https://github.com/chanify/chanify/actions?workflow=codeql) [![Codecov](https://img.shields.io/codecov/c/github/chanify/chanify?logo=codecov&style=flat-square)](https://codecov.io/gh/chanify/chanify) [![Total alerts](https://img.shields.io/lgtm/alerts/g/chanify/chanify.svg?logo=lgtm&logoWidth=18&style=flat-square)](https://lgtm.com/projects/g/chanify/chanify/alerts/) [![Go Report Card](https://goreportcard.com/badge/github.com/chanify/chanify?style=flat-square)](https://goreportcard.com/report/github.com/chanify/chanify) [![Go Reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/github.com/chanify/chanify) [![GitHub](https://img.shields.io/github/license/chanify/chanify?style=flat-square)](LICENSE) [![Docker pull](https://img.shields.io/docker/pulls/wizjin/chanify?style=flat-square)](https://hub.docker.com/r/wizjin/chanify) [![Downloads](https://img.shields.io/github/downloads/chanify/chanify/total?style=flat-square)](https://github.com/chanify/chanify/releases/latest) [![Users](https://img.shields.io/chrome-web-store/users/llpdpmhkemkjeeigibdamadahmhoebdg?style=flat-square)](https://chrome.google.com/webstore/detail/chanify/llpdpmhkemkjeeigibdamadahmhoebdg) [English](README.md) | 简体中文 Chanify 是一个简单的消息推送工具。每一个人都可以利用提供的 API 来发送消息推送到自己的 iOS 设备上。

目录

  1. 功能
  2. 入门
  3. 安装
  4. 用法
  5. HTTP API
  6. 配置文件
  7. 安全
  8. Chrome 插件
  9. 贡献
  10. 许可证
## 功能 Chanify 包括这些功能: - 支持自定义频道分类消息 - 支持部署自己的节点服务器 - 依照去中心化设计的系统架构 - 随机账号生成保护隐私 - 支持文本/图片/音频/文件等多种消息格式 ## 入门 1. 从 AppStore 安装[iOS 应用](https://itunes.apple.com/cn/app/id1531546573)(1.0.0 或以上版本)。 2. 获取发送使用的令牌`token`,[更多细节](https://github.com/chanify/chanify-ios)。 3. 使用 API 来发送消息。 ## 安装 ### 预编译包 可以[这里](https://github.com/chanify/chanify/releases/latest)下载最新的预编译二进制包。 ### Docker ```bash $ docker pull wizjin/chanify:latest ``` ### 从源代码 ```bash $ git clone https://github.com/chanify/chanify.git $ cd chanify $ make install ``` ## 用法 ### 作为客户端 可以使用下列命令来发送消息 ```bash # 文本消息 $ chanify send --endpoint=http://
: --token= --text=<文本消息> # 链接消息 $ chanify send --endpoint=http://
: --token= --link=<网页链接> # 图片消息 $ chanify send --endpoint=http://
: --token= --image=<图片文件路径> # 音频消息 $ chanify send --endpoint=http://
: --token= --audio=<音频文件路径> # 文件消息 $ chanify send --endpoint=http://
: --token= --file=<文件路径> --text=<文件描述> # 动作消息 $ chanify send --endpoint=http://
: --token= --text=<文本消息> --title=<文本标题> --action="<动作名字>|<动作链接 url>" ``` `endpoint` 默认值是 `https://api.chanify.net`,并且会使用默认服务器发送消息。 如果使用的是自建的节点服务器,请在讲`endpoint`设置成自建服务器的 URL。 ### 作为无状态服务器 Chanify 可以作为无状态服务器运行,在这种模式下节点服务器不会保存设备信息(APNS 令牌)。 所有的设备信息会被存储在 api.chanify.net。 消息会在节点服务器加密之后由 api.chanify.net 代理发送给苹果的 APNS 服务器。 消息的流动如下: ```text 开始 => 自建节点服务器 => api.chanify.net => 苹果APNS服务器 => iOS客户端 ``` ```bash # 命令行启动 $ chanify serve --host= --port= --secret= --name= --endpoint=http://
: # 使用Docker启动 $ docker run -it wizjin/chanify:latest serve --secret= --name= --endpoint=http://
: ``` ### 作为有状态服务器 Chanify 可以作为有状态服务器运行,在这种模式下节点服务器会保存用户的设备信息(APNS 令牌)。 消息会直接由节点服务器加密之后发送给苹果的 APNS 服务器。 消息的流动如下: ```text 开始 => 自建节点服务器 => Apple server => iOS客户端 ``` 启动服务器 ```bash # 命令行启动 $ chanify serve --host= --port= --name= --datapath=~/.chanify --endpoint=http://
: # 使用Docker启动 $ docker run -it -v /my/data:/root/.chanify wizjin/chanify:latest serve --name= --endpoint=http://
: ``` 默认会使用 sqlite 保存数据,如果要使用 MySQL 作为数据库存储信息可以添加如下参数: ```bash --dburl=mysql://:@tcp(:)/?charset=utf8mb4&parseTime=true&loc=Local ``` 注意:Chanify 不会创建数据库,只会创建表格,所以使用前请先自行建立数据库。 ### 添加节点服务器 - 启动节点服务器 - 获取服务器二维码(`http://
:/`) - 打开 iOS 的客户端扫描二维码添加节点 ### 发送消息 #### 命令行 ```bash # 发送文本消息 $ curl --form-string "text=hello" "http://
:/v1/sender/" # 发送文本文件 $ cat message.txt | curl -H "Content-Type: text/plain" --data-binary @- "http://
:/v1/sender/" ``` #### Python 3 ```python from urllib import request, parse data = parse.urlencode({ 'text': 'hello' }).encode() req = request.Request("http://
:/v1/sender/", data=data) request.urlopen(req) ``` #### Ruby ```ruby require 'net/http' uri = URI('http://
:/v1/sender/') res = Net::HTTP.post_form(uri, 'text' => 'hello') puts res.body ``` #### NodeJS ```javascript const https = require('https') const querystring = require('querystring'); const data = querystring.stringify({ text: 'hello' }) const options = { hostname: '
:', port: 80, path: '/v1/sender/', method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': data.length } } var req = https.request(options, (res) => { res.on('data', (d) => { process.stdout.write(d); }); }); req.write(data); req.end(); ``` #### PHP ```php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => 'http://
:/v1/sender/', CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => [ 'text' => 'hello' ], ]); $response = curl_exec($curl); curl_close($curl); echo $response; ``` ## HTTP API ### 发送文本 - __GET__ ```url http://
:/v1/sender// ``` - __POST__ ```url http://
:/v1/sender/ ``` Content-Type: - `text/plain`: Body is text message - `multipart/form-data`: The block of data("text") is text message - `application/x-www-form-urlencoded`: `text=` - `application/json; charset=utf-8`: 字段都是可选的 ```json { "token": "<令牌Token>", "title": "<消息标题>", "text": "<文本消息内容>", "copy": "<可选的复制文本>", "autocopy": 1, "sound": 1, "priority": 10, "actions": [ "动作名称1|http:///", "动作名称2|http:///", ] } ``` 支持以下参数: | 参数名 | 默认值 | 描述 | | -------- | ----- | -------------------------------- | | title | 无 | 通知消息的标题 | | copy | 无 | 可选的复制文本(仅文本消息有效) | | autocopy | `0` | 是否自动复制文本(仅文本消息有效) | | sound | `0` | `1` 启用声音提示, 其他情况会静音推送 | | priority | `10` | `10` 正常优先级, `5` 较低优先级 | | actions | 无 | 动作列表 | 例如: ```url http://
:/v1/sender/?sound=1&priority=10&title=hello©=123&autocopy=1 ``` ### 发送链接 ```bash $ curl --form "link=@" "http://
:/v1/sender/" ``` ```json { "link": "", "sound": 1, "priority": 10, } ``` ### 发送图片 目前仅支持使用 **POST** 方法通过自建的有状态服务器才能发送图片。 - Content-Type: `image/png` 或者 `image/jpeg` ```bash cat | curl -H "Content-Type: image/jpeg" --data-binary @- "http://
:/v1/sender/" ``` - Content-Type: `multipart/form-data` ```bash $ curl --form "image=@" "http://
:/v1/sender/" ``` ### 发送音频 目前仅支持使用 **POST** 方法通过自建的有状态服务器才能发送 mp3 音频。 - Content-Type: `audio/mpeg` ```bash cat | curl -H "Content-Type: audio/mpeg" --data-binary @- "http://
:/v1/sender/" ``` - Content-Type: `multipart/form-data` ```bash $ curl --form "audio=@" "http://
:/v1/sender/" ``` ### 发送文件 目前仅支持使用 **POST** 方法通过自建的有状态服务器才能发文件。 - Content-Type: `multipart/form-data` ```bash $ curl --form "file=@<文件路径>" "http://
:/v1/sender/" ``` ### 发送动作 发送动作消息(最多 4 个动作)。 - Content-Type: `multipart/form-data` ```bash $ curl --form "action=动作名称1|http:///" "http://
:/v1/sender/" ``` ## 配置文件 可以通过 yml 文件来配置 Chanify,默认路径`~/.chanify.yml`。 ```yml server: host: 0.0.0.0 # 监听IP地址 port: 8080 # 监听端口 endpoint: http://my.server/path # 入口URL name: Node name # 节点名称 secret: # 无状态服务器使用的密钥 datapath: # 有状态服务器使用的数据存储路径 dburl: mysql://root:test@tcp(127.0.0.1:3306)/chanify?charset=utf8mb4&parseTime=true&loc=Local # 有状态服务器使用的数据库链接 register: enable: false # 关闭注册 whitelist: # 白名单 - - client: # 作为客户端发送消息时使用 sound: 1 # 是否有提示音 endpoint: token: ``` ## 安全 ### 设置可注册 可以通过禁用节点服务器的用户注册功能,来使 Node 服务器成为私有服务器,防止非授权用户使用。 ```bash chanify serve --registerable=false --whitelist=, ``` - `--registerable=false`: 这个参数用来禁用用户注册 - `whitelist`: 服务器禁用用户注册后,仍然可以添加使用的用户 ### 令牌生命周期 - 令牌默认寿命约 90 天左右 - 可以在频道详情页面配置令牌寿命 (1 天 ~ 5 年) 如果令牌被泄露,请将泄露的令牌添加到禁用列表(在 iOS 客户端设置页面)。 *注意: 请保护您的令牌不被泄露,禁用列表需要受信任的节点服务器(1.2.0 或以上版本)。* ## Chrome 插件 可以从[Chrome web store](https://chrome.google.com/webstore/detail/chanify/llpdpmhkemkjeeigibdamadahmhoebdg)下载插件. 插件有以下功能: - 发送选中的`文本/图片/音频/链接`消息到 Chanify - 发送网页链接到 Chanify ## 贡献 贡献使开源社区成为了一个令人赞叹的学习,启发和创造场所。 **十分感谢**您做出的任何贡献。 1. Fork 本项目 2. 切换到 dev 分支 (`git checkout dev`) 3. 创建您的 Feature 分支 (`git checkout -b feature/AmazingFeature`) 4. 提交您的更改 (`git commit -m 'Add some AmazingFeature'`) 5. 推送到分支 (`git push origin feature/AmazingFeature`) 6. 开启一个 Pull Request (合并到 `chanify:dev` 分支) ## 许可证 根据 MIT 许可证分发,详情查看[`LICENSE`](LICENSE)。