{"id":15587747,"url":"https://github.com/icyleaf/xiaomi-push","last_synced_at":"2025-04-24T04:50:28.900Z","repository":{"id":29752286,"uuid":"33295904","full_name":"icyleaf/xiaomi-push","owner":"icyleaf","description":"(unofficial) xiaomi push server sdk for ruby - 非官方小米推送服务端 Ruby SDK","archived":false,"fork":false,"pushed_at":"2021-04-28T21:59:09.000Z","size":152,"stargazers_count":8,"open_issues_count":2,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-21T01:07:21.460Z","etag":null,"topics":["ruby","ruby-sdk","xiaomi","xiaomi-push","xiaomi-sdk"],"latest_commit_sha":null,"homepage":"http://www.rubydoc.info/gems/xiaomi-push/frames","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/icyleaf.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-02T07:38:32.000Z","updated_at":"2019-11-27T01:14:35.000Z","dependencies_parsed_at":"2022-08-20T17:30:08.110Z","dependency_job_id":null,"html_url":"https://github.com/icyleaf/xiaomi-push","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icyleaf%2Fxiaomi-push","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icyleaf%2Fxiaomi-push/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icyleaf%2Fxiaomi-push/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icyleaf%2Fxiaomi-push/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/icyleaf","download_url":"https://codeload.github.com/icyleaf/xiaomi-push/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250566445,"owners_count":21451230,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ruby","ruby-sdk","xiaomi","xiaomi-push","xiaomi-sdk"],"created_at":"2024-10-02T22:03:08.880Z","updated_at":"2025-04-24T04:50:28.881Z","avatar_url":"https://github.com/icyleaf.png","language":"Ruby","readme":"# 非官方小米推送服务端 Ruby SDK\n\n[![Build Status](https://img.shields.io/circleci/project/github/icyleaf/xiaomi-push.svg?style=flat)](https://circleci.com/gh/icyleaf/xiaomi-push)\n[![Code Climate](https://img.shields.io/codeclimate/github/icyleaf/xiaomi-push.svg?style=flat)](https://codeclimate.com/github/icyleaf/xiaomi-push)\n[![Inline docs](http://inch-ci.org/github/icyleaf/xiaomi-push.svg?style=flat)](https://inch-ci.org/github/icyleaf/xiaomi-push)\n[![Gem version](https://img.shields.io/gem/v/xiaomi-push.svg?style=flat)](https://rubygems.org/gems/xiaomi-push)\n[![License](https://img.shields.io/badge/license-MIT-red.svg?style=flat)](LICENSE.txt)\n\n## TL;DR\n\n\u003e 特别注意：仅支持 Ruby 2.1.0 （包含）以上版本。\n\n### 安装\n\n添加如下至 Gemfile:\n\n```ruby\ngem 'xiaomi-push'\n```\n\n执行:\n\n```\n$ bundle\n```\n\n或直接安装:\n\n```\n$ gem install xiaomi-push\n```\n\n### 用法\n\n### 发单一消息\n\n支持按照 `reg_id`/`alias`/`topic`/`topics`/`user`/`all` 的方式向单个或一组设备发送同一条推送消息。\n\n```ruby\nrequire 'xiaomi-push'\n\n# 初始化\n# iOS (环境支持 :production/:sandbox)\nclient = Xiaomi::Push::IOS('Fill your app secret', :production)\n# Android\nclient = Xiaomi::Push::Android('Fill your app secret')\n\n# 消息结构\n# Hash 模式\nmessage = {\n  'title': 'Android 需要标题',\n  'descrption': 'iOS 主要显示描述',\n  'extra.uri': 'app://bbs?id=8624'\n}\n\n# Builder 模式\n# iOS\nmessage = Xiaomi::Push::Message::IOS.new(\n  description: 'iOS 主要显示描述',\n  badge: 10,\n  extras: {\n    uri: 'app://bbs?id=8624',\n    source: 'mpush'\n  }\n)\n\n# iOS 10\nmessage = Xiaomi::Push::Message::IOS.new(\n  title: '这是标题',\n  subtitle: '这是副标题'\n  description:'iOS 主要显示描述', # 对于 iOS 这里即可以是 description 也可以是 iOS 10 结构的 body\n  badge: 1,\n  extras: {\n    uri: 'app://bbs?id=8624',\n    source: 'mpush'\n  }\n)\n\n# Android\nmessage = Xiaomi::Push::Message::Android.new(\n  title: '标题要有吸引力',\n  description: '描述可以在手机显示两行',\n  notify_type: 'DEFAULT_ALL',\n  extras: {\n    source: 'mpush'\n  }\n)\n\n# 支持单独追加 extra\nmessage.extra('uri', 'app://bbs?id=8624')\n\n# 发消息\n# 根据 regid\nclient.message.send reg_id:'id', message:message\n\n# 根据 alias\nclient.message.send alias:'alias', message:message\n\n# 根据 topic\nclient.message.send topic:'topic', message:message\n\n# 全部推送\nclient.message.send all:true, message:message\n```\n\n### 发送多条消息\n\n支持同一设备类型的设备发送不同的消息。**注意**发送多个消息不能是不同类型的设备 key。\n\n支持的消息类型：\n\n- `:reg_id`\n  - `reg_id`\n  - `regid`\n  - `registration_id`\n- `:alias`\n  - `:alias`\n- `:user`\n  - `:user`\n  - `:account`\n  - `:useraccount`\n  - `:user_account`\n\n\u003e 以上子列表为消息体传递的设备的 key 的名字。\n\n```ruby\n# 向多个 reg id 发送不同的消息\nclient.messages.send(:reg_id, [\n  {\n    reg_id: 'abc',\n    title: '这是标题1',\n    description: '这个是推送的描述1',\n    notify_type: -1\n  },\n  {\n    regid: 'dfc',\n    title: '这是标题2',\n    description: '这个是推送的描述2',\n  },\n  {\n    registration_id: 'dfc',\n    title: '这是标题2',\n    description: '这个是推送的描述2',\n  }\n])\n\n# 这个是错误的消息，无法发送\nclient.messages.send(:alias, [\n  {\n    reg_id: 'abc',\n    title: '这是标题1',\n    description: '这个是推送的描述1',\n    notify_type: -1\n  },\n  {\n    user: 'dfc',\n    title: '这是标题2',\n    description: '这个是推送的描述2',\n  },\n])\n```\n\n### 订阅/取消订阅标签\n\n```ruby\n# 订阅单个 reg id 到 beijing 标签\nclient.topic.subscribe(reg_id: 'abc', topic: 'beijing')\n\n# 订阅多个 alias 到 beijing 标签\nclient.topic.subscribe(alias: 'abc,def,ghi,jkl', topic: 'beijing')\n\n# 取消订阅 beijing 标签的单个 reg id\nclient.topic.unsubscribe(reg_id: 'abc', topic: 'beijing')\n\n# 取消订阅 beijing 标签的多个 alias\nclient.topic.unsubscribe(alias: 'abc,def,ghi,jkl', topic: 'beijing')\n```\n\n### 获取无效 iOS 的推送设备\n\n用于检查 iOS 用户关闭了应用的推送或者是卸载了 App 的设备列表\n\n```ruby\nclient.feedback.invalid\n```\n\n### 获取消息的统计数据\n\n```ruby\n# 获取 2017-09-01 到 2017-09-30 应用 com.icyleaf.app.helloworld 统计数据\nclient.message.counters('20170901', '20170930', 'com.icyleaf.app.helloworld')\n```\n\n更多用例可查阅 [Rakefile](Rakefile)。\n\n### 命令行工具\n\n本 SDK 同时还附带一个命令行工具 `xmp`，可以使用它尽快快速的测试和验证参数信息.\n\n```bash\n# 发消息\n## iOS\n### 发送附加内容并设置未读消息数为 2\n$ xmp message --device ios --secret '\u003c密钥\u003e' \\\n  --alias '\u003cAlias\u003e' \\\n  -d '推送的描述内容' \\\n  -b 2 \\\n  -e uri=\"http://icyleaf.com\"\n# =\u003e {\"result\"=\u003e\"ok\", \"trace_id\"=\u003e\"abc\", \"code\"=\u003e0, \"data\"=\u003e{\"id\"=\u003e\"abc68b8350529097551xyz\"}, \"description\"=\u003e\"成功\", \"info\"=\u003e\"Received push messages for 1 ALIAS\"}\n\n## Android\n### 最基本的推送信息\n$ xmp message --device android --secret '\u003c密钥\u003e' \\\n  --regid '\u003cRegId\u003e' \\\n  -i '推送的标题' \\\n  -d '推送的描述内容'\n# =\u003e {\"result\"=\u003e\"ok\", \"trace_id\"=\u003e\"abc\", \"code\"=\u003e0, \"data\"=\u003e{\"id\"=\u003e\"abc68b8350529097551xyz\"}, \"description\"=\u003e\"成功\", \"info\"=\u003e\"Received push messages for 1 REG_ID\"}\n\n# 查找绑定的 aliases 和 topics\n$ xmp user --device ios --secret '\u003c密钥\u003e' --reg-id '\u003cRegId\u003e'\n# =\u003e alias count: 1\n# =\u003e  * ABCDEFGH-1234-5678-90ABC-F4DC5731EEFD\n# =\u003e topic count: 1\n# =\u003e  * all\n\n# 查找 iOS 无效的设备（Reg id）\n$ xmp feedback --device ios --secret '\u003c密钥\u003e'\n# =\u003e {\"result\"=\u003e\"ok\", \"trace_id\"=\u003e\"Xlm07b67505290966457ey\", \"code\"=\u003e0, \"data\"=\u003e{\"list\"=\u003e[\"+9AKnbpV22HafwE7vjYMr6Hc7i41ClyQr7iqX1fm7zc=\"]}}\n\n# 查看帮助\n$ xmp message --help\n\n  NAME:\n\n    xmp\n\n  DESCRIPTION:\n\n    小米推送命令行工具\n\n  COMMANDS:\n\n    feedback 获取小米无效的设备列表\n    message  发送小米推送消息\n    user     小米 aliases/topics 查询工具\n```\n\n## 相关资源\n\n- 官方 API 文档: https://dev.mi.com/console/doc/detail?pId=1163\n- 官方 SDK 下载：https://dev.mi.com/mipush/downpage/ (Python Java PHP)\n\n## 贡献代码\n\n1. Fork it ( https://github.com/[my-github-username]/xiaomi-push/fork )\n1. Create your feature branch (`git checkout -b my-new-feature`\\)\n1. Commit your changes (`git commit -am 'Add some feature'`\\)\n1. Push to the branch (`git push origin my-new-feature`\\)\n1. Create a new Pull Request\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficyleaf%2Fxiaomi-push","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ficyleaf%2Fxiaomi-push","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficyleaf%2Fxiaomi-push/lists"}