diff --git a/README.md b/README.md index 977b090..9d06369 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,260 @@ -# pushdeer-doc -开放源码的无App推送方案·设计和规划文档 +# PushDeerOS + +PushDeer开源版,可以自行架设的无APP推送服务 + +|登入|设备|Key|消息|设置| +|-|-|-|-|-| +|![](doc/design_and_resource/登入.png)|![](doc/design_and_resource/设备.png)|![](doc/design_and_resource/key.png)|![](doc/design_and_resource/消息.png)|![](doc/design_and_resource/设置.png) + +[📼 项目视频说明](https://www.bilibili.com/video/BV1Ar4y1S7em/) + +## 产品定义 + +PushDeer的**核心价值**,包括:「易用」、「可控」和「渐进」。 + +### 易用 + +易用性表现在两个方面: + +1. 易安装:采用无APP方案,直接**去掉安装步骤** +1. 易调用:只需输入URL,**无需阅读文档**,就可以发送消息 + +### 可控 + +1. `Self-hosted`:让有能力和精力的用户可以自行架设,避免因为在线服务下线导致的接口更换风险。 +1. 非商用免费:不用PushDeer挣钱,就无需支付费用 +1. 不依赖微信消息接口:不像Server酱那样受腾讯政策影响 + +### 渐进 + +1. 通过URL即可发送基本的文本消息;通过更多参数,可以对消息的样式等细节进行调整 +1. 无APP不能实现的功能不能覆盖的机型,后期可以通过APP来补充 + +## 商业模式 + +PushDeer是一个商业开源项目,采用「开放源码」、「自用免费」、「在线服务收费」的方式进行运作。 + +### 具体实现 + +PushDeer是一个以盈利为目的的商业项目,品牌和源码所有权都由「方糖君」公司持有,但和纯商业项目不同的地方在于: + +1. 它开放源代码,所有人都可以在非商业前提下按GPLv2授权使用 +1. 它接受社区贡献代码,作为回报,它会从商业收益中拿出部分来赞助项目贡献人 +1. 如果商业收益够大,它会尝试雇佣项目贡献人以兼职或者全职的方式为项目工作 + +这里边有一些细节: + +1. 为了避免某些个人或者公司使用源码搭建在线竞品服务收费,我们限制了源码不能商用 +1. 在刚开始的时候,项目并没有商业收入,而却是开发工作量最大的。所以首先我们会承担产品和界面设计、API设计和开发等工作;并通过众筹的方式筹集了一些资金给其他大模块的贡献人 + +开放源码形式保证了其他代码贡献人在非商业场景下对源码的可控: + +1. 如果社区和代码贡献人不满意「方糖君」主导的商业化,可以 Fork 一个版本,继续在非商用的前提下自行运营 +1. 如果「方糖君」之后不再开放源代码,普通用户依然可以按之前的协议使用修改协议前的源码 + +## 用户细分 + +PushDeer主要面向以下三类用户 + +1. 高阶电脑用户 +1. 开发者 +1. 公司或自媒体 + +### 高阶电脑用户 + +具有一定电脑操作技能的高阶用户,比如: + +1. NAS 用户 +1. 站长 +1. 电脑技术爱好者 + +他们使用PushDeer的场景包括但不限于: + +1. 推送路由器和 NAS 的状态、公网 IP 等信息 +1. 推送 Wordpress 最新的评论 +1. 推送加密货币达到特定价格的通知 +1. 在多台设备上推送文本 +1. 自动化工具推送定期汇报 + +### 开发者 + +使用PushDeer的场景包括但不限于: + +1. 推送报错和调试信息 +1. 推送服务器异常 +1. 推送定时任务输出 +1. 在自己的软件发送消息到手机(引导用户填入PushDeer的key) + +### 公司或自媒体 + +使用PushDeer的场景包括但不限于: + +1. 面向自己的用户推送通知、内容和营销信息(类似公众号,但不受微信限制) + +## 项目目录说明 + +- api: Laravel实现的API接口,[点此查看请求和返回demo](doc/api/PushDeerOS.md) +- docker: API实现的docker封装,一键启动,方便使用 +- doc: 文档目录,包括界面设计源文件(Adobe XD)和资源文件(logo和avatar) +- push: 基于 [gorush](https://github.com/appleboy/gorush) 架设的推送微服务,配置文件开启 async 可以提升发送速度 +- ios: 用于放置 iOS 源文件,`ios/Prototype_version` 目录是我边学边写的原型验证版本(SwiftUI+Moya+Codable),很多地方需要重写,仅供参考 +- quickapp: 用于放置快应用源代码 + +## 开发环境搭建 + +### 下载代码 + +```git clone https://gitlab.com/easychen/pushdeeros``` + +### 配置推送证书 + +进入 `push` 目录,修改 `*.yml.sample` 为 `*.yml`。其中iOS应用和Clip使用两个分开的证书进行推送,`ios.yml` 是APP的配置、`clip.yml`是Clip的配置。注意根据开发和产品状态,修改`yml`中的值`production`。 + +默认配置中,`c.p12` 是APP的推送证书、`cc.p12`是Clip的推送证书。 + +### 启动docker环境 + +运行 `docker-compose up -d`,启动API。默认访问地址为`http://127.0.0.1:8800`。可修改`docker-compose.yml`调整端口。 + +### API 说明 + +API_BASE=http://127.0.0.1:8800 + +认证方式:通过登入接口获得`token`,通过`post`和`get`方式附带`token`参数即可自动登入。 + +#### 模拟登入 + +`GET /login/fake` + +#### 获得当前用户的基本信息 + +`POST /user/info` + +|参数|说明|备注| +|-|-|-| +|token|认证token| + +#### 注册设备 + +`POST /device/reg` + +|参数|说明|备注| +|-|-|-| +|token|认证token| +|name|设备名称| +|device_id|device token(推送用)| +|is_clip|是否轻应用|0为APP| + +#### 设备列表 + +`POST /device/list` + +|参数|说明|备注| +|-|-|-| +|token|认证token| + +#### 重命名设备 + +`POST /device/rename` + +|参数|说明|备注| +|-|-|-| +|token|认证token| +|id|设备id| +|name|设备新名称| + +#### 移除设备 + +`POST /device/remove` + +|参数|说明|备注| +|-|-|-| +|token|认证token| +|id|设备id| + +#### 生成一个新Key + +`POST /key/gen` + +|参数|说明|备注| +|-|-|-| +|token|认证token| + +#### 重命名Key + +`POST /key/rename` + +|参数|说明|备注| +|-|-|-| +|token|认证token| +|id|Key ID| +|name|Key新名称| + +#### 重置一个Key + +`POST /key/regen` + +|参数|说明|备注| +|-|-|-| +|token|认证token| +|id|Key ID| + +#### 获取当前用户的Key列表 + +`POST /key/list` + +|参数|说明|备注| +|-|-|-| +|token|认证token| + +#### 删除Key + +`POST /key/remove` + +|参数|说明|备注| +|-|-|-| +|token|认证token| +|id|Key ID| + + +#### 推送消息 + +`POST /message/push` + +|参数|说明|备注| +|-|-|-| +|pushkey|PushKey| +|text|推送消息内容| +|desp|消息内容第二部分,选填| +|type|格式,选填|文本=text,markdown,图片=image,默认为markdown| + +#### 获得当前用户的消息列表 + +`POST /message/list` + + +|参数|说明|备注| +|-|-|-| +|token|认证token| +|limit|消息条数|默认为10,最大100 + +#### 删除消息 + +`POST /message/remove` + +|参数|说明|备注| +|-|-|-| +|token|认证token| +|id|消息ID| + + +[更详细的请求和返回值可以参考这里](doc/api/PushDeerOS.md) + +通用错误返回格式: + +``` +{ + code:正确为0,错误为非0, + content:错误信息 +} +``` diff --git a/api/.editorconfig b/api/.editorconfig new file mode 100644 index 0000000..1671c9b --- /dev/null +++ b/api/.editorconfig @@ -0,0 +1,18 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false + +[*.{yml,yaml}] +indent_size = 2 + +[docker-compose.yml] +indent_size = 4 diff --git a/api/.env.example b/api/.env.example new file mode 100644 index 0000000..6c80973 --- /dev/null +++ b/api/.env.example @@ -0,0 +1,52 @@ +APP_NAME=Laravel +APP_ENV=local +APP_KEY= +APP_DEBUG=true +APP_URL=http://localhost + +LOG_CHANNEL=stack +LOG_DEPRECATIONS_CHANNEL=null +LOG_LEVEL=debug + +DB_CONNECTION=mysql +DB_HOST=mariadb +DB_PORT=3306 +DB_DATABASE=pushdeer +DB_USERNAME=root +DB_PASSWORD=theVeryp@ssw0rd + +BROADCAST_DRIVER=log +CACHE_DRIVER=file +FILESYSTEM_DRIVER=local +QUEUE_CONNECTION=sync +SESSION_DRIVER=file +SESSION_LIFETIME=120 + +MEMCACHED_HOST=127.0.0.1 + +REDIS_HOST=127.0.0.1 +REDIS_PASSWORD=null +REDIS_PORT=6379 + +MAIL_MAILER=smtp +MAIL_HOST=mailhog +MAIL_PORT=1025 +MAIL_USERNAME=null +MAIL_PASSWORD=null +MAIL_ENCRYPTION=null +MAIL_FROM_ADDRESS=null +MAIL_FROM_NAME="${APP_NAME}" + +AWS_ACCESS_KEY_ID= +AWS_SECRET_ACCESS_KEY= +AWS_DEFAULT_REGION=us-east-1 +AWS_BUCKET= +AWS_USE_PATH_STYLE_ENDPOINT=false + +PUSHER_APP_ID= +PUSHER_APP_KEY= +PUSHER_APP_SECRET= +PUSHER_APP_CLUSTER=mt1 + +MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" +MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" diff --git a/api/.gitattributes b/api/.gitattributes new file mode 100644 index 0000000..967315d --- /dev/null +++ b/api/.gitattributes @@ -0,0 +1,5 @@ +* text=auto +*.css linguist-vendored +*.scss linguist-vendored +*.js linguist-vendored +CHANGELOG.md export-ignore diff --git a/api/.gitignore b/api/.gitignore new file mode 100644 index 0000000..eb003b0 --- /dev/null +++ b/api/.gitignore @@ -0,0 +1,15 @@ +/node_modules +/public/hot +/public/storage +/storage/*.key +/vendor +.env +.env.backup +.phpunit.result.cache +docker-compose.override.yml +Homestead.json +Homestead.yaml +npm-debug.log +yarn-error.log +/.idea +/.vscode diff --git a/api/.styleci.yml b/api/.styleci.yml new file mode 100644 index 0000000..877ea70 --- /dev/null +++ b/api/.styleci.yml @@ -0,0 +1,14 @@ +php: + preset: laravel + version: 8 + disabled: + - no_unused_imports + finder: + not-name: + - index.php + - server.php +js: + finder: + not-name: + - webpack.mix.js +css: true diff --git a/api/README.md b/api/README.md new file mode 100644 index 0000000..8878ec1 --- /dev/null +++ b/api/README.md @@ -0,0 +1,66 @@ +
+ + + +## About Laravel + +Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as: + +- [Simple, fast routing engine](https://laravel.com/docs/routing). +- [Powerful dependency injection container](https://laravel.com/docs/container). +- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage. +- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent). +- Database agnostic [schema migrations](https://laravel.com/docs/migrations). +- [Robust background job processing](https://laravel.com/docs/queues). +- [Real-time event broadcasting](https://laravel.com/docs/broadcasting). + +Laravel is accessible, powerful, and provides tools required for large, robust applications. + +## Learning Laravel + +Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework. + +If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains over 1500 video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library. + +## Laravel Sponsors + +We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the Laravel [Patreon page](https://patreon.com/taylorotwell). + +### Premium Partners + +- **[Vehikl](https://vehikl.com/)** +- **[Tighten Co.](https://tighten.co)** +- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)** +- **[64 Robots](https://64robots.com)** +- **[Cubet Techno Labs](https://cubettech.com)** +- **[Cyber-Duck](https://cyber-duck.co.uk)** +- **[Many](https://www.many.co.uk)** +- **[Webdock, Fast VPS Hosting](https://www.webdock.io/en)** +- **[DevSquad](https://devsquad.com)** +- **[Curotec](https://www.curotec.com/services/technologies/laravel/)** +- **[OP.GG](https://op.gg)** +- **[CMS Max](https://www.cmsmax.com/)** +- **[WebReinvent](https://webreinvent.com/?utm_source=laravel&utm_medium=github&utm_campaign=patreon-sponsors)** +- **[Lendio](https://lendio.com)** +- **[Romega Software](https://romegasoftware.com)** + +## Contributing + +Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions). + +## Code of Conduct + +In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct). + +## Security Vulnerabilities + +If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed. + +## License + +The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). diff --git a/api/app/Console/Kernel.php b/api/app/Console/Kernel.php new file mode 100644 index 0000000..d8bc1d2 --- /dev/null +++ b/api/app/Console/Kernel.php @@ -0,0 +1,32 @@ +command('inspire')->hourly(); + } + + /** + * Register the commands for the application. + * + * @return void + */ + protected function commands() + { + $this->load(__DIR__.'/Commands'); + + require base_path('routes/console.php'); + } +} diff --git a/api/app/Exceptions/Handler.php b/api/app/Exceptions/Handler.php new file mode 100644 index 0000000..8e7fbd1 --- /dev/null +++ b/api/app/Exceptions/Handler.php @@ -0,0 +1,41 @@ +> + */ + protected $dontReport = [ + // + ]; + + /** + * A list of the inputs that are never flashed for validation exceptions. + * + * @var array