API、SDK和开发文档

开发说明

视频版设计文档: 📼 项目视频说明 📼 项目架构和模块说明

目录说明

  • api: Laravel实现的API接口,点此查看请求和返回demo
  • docker: API实现的docker封装,一键启动,方便使用
  • doc: 文档目录,包括界面设计源文件(Adobe XD)和资源文件(logo和avatar)
  • push: 基于 gorush 架设的推送微服务,配置文件开启 async 可以提升发送速度
  • ios: 用于放置 iOS 源文件,ios/Prototype_version 目录是我边学边写的原型验证版本(SwiftUI+Moya+Codable),很多地方需要重写,仅供参考
  • quickapp: 用于放置快应用源代码
  • android: 用于放置安卓客户端源代码

开发环境搭建

下载代码

git clone https://github.com/easychen/pushdeer.git

启动docker环境

运行 docker-compose up -d,启动API。默认访问地址为http://127.0.0.1:8800。可修改docker-compose.yml调整端口。

SDK 和函数

PHP函数:

function pushdeer_send($text, $desp = '', $type='text', $key = '[PUSHKEY]')
{
    $postdata = http_build_query(array( 'text' => $text, 'desp' => $desp, 'type' => $type , 'pushkey' => $key ));
    $opts = array('http' =>
    array(
        'method'  => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded',
        'content' => $postdata));
    
    $context  = stream_context_create($opts);
    return $result = file_get_contents('https://api2.pushdeer.com/message/push', false, $context);
}

API 说明

在线文档(Swagger)

API_BASE=http://127.0.0.1:8800

认证方式:通过登入接口获得token,通过postget方式附带token参数即可自动登入。

模拟登入(环境变量APP_DEBUG=true时可用)

GET /login/fake

通过苹果 idToken 登入

POST /login/idtoken

参数说明备注
idTokenSign in with Apple 中得到的 idToken

通过微信 oauth code 登入

POST /login/wecode

参数说明备注
code客户端微信授权得到的code

合并用户并将旧用户删除

POST /user/merge

参数说明备注
token认证token
type字符串,必须为 apple 或者 wechat
tokenorcodetype 为 apple时此字段为 idToken,否则为 微信code

获得当前用户的基本信息

POST /user/info

参数说明备注
token认证token

注册设备

POST /device/reg

参数说明备注
token认证token
name设备名称
device_iddevice 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
idKey ID
nameKey新名称

重置一个Key

POST /key/regen

参数说明备注
token认证token
idKey ID

获取当前用户的Key列表

POST /key/list

参数说明备注
token认证token

删除Key

POST /key/remove

参数说明备注
token认证token
idKey ID

推送消息

POST /message/push

参数说明备注
pushkeyPushKey
text推送消息内容
desp消息内容第二部分,选填
type格式,选填文本=text,markdown,图片=image,默认为markdown

type 为 image 时,text 中为要发送图片的URL。

获得当前用户的消息列表

POST /message/list

参数说明备注
token认证token
limit消息条数默认为10,最大100

删除消息

POST /message/remove

参数说明备注
token认证token
id消息ID

通用返回格式:

{
    code:正确为0,错误为非0,
    content:内容,错误时无此字段,
    error:错误信息,无错误时无此字段
}