{"id":42107303,"url":"https://github.com/douchunrong/jpush-client","last_synced_at":"2026-01-26T13:20:07.683Z","repository":{"id":57538087,"uuid":"96523537","full_name":"douchunrong/jpush-client","owner":"douchunrong","description":null,"archived":false,"fork":false,"pushed_at":"2017-07-07T09:37:34.000Z","size":19,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-14T01:31:39.509Z","etag":null,"topics":["golang","jpush"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/douchunrong.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-07T09:36:12.000Z","updated_at":"2018-06-16T06:38:58.000Z","dependencies_parsed_at":"2022-08-29T00:41:47.664Z","dependency_job_id":null,"html_url":"https://github.com/douchunrong/jpush-client","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/douchunrong/jpush-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/douchunrong%2Fjpush-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/douchunrong%2Fjpush-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/douchunrong%2Fjpush-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/douchunrong%2Fjpush-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/douchunrong","download_url":"https://codeload.github.com/douchunrong/jpush-client/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/douchunrong%2Fjpush-client/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28779298,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T11:46:04.308Z","status":"ssl_error","status_checked_at":"2026-01-26T11:46:02.664Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["golang","jpush"],"created_at":"2026-01-26T13:20:07.064Z","updated_at":"2026-01-26T13:20:07.671Z","avatar_url":"https://github.com/douchunrong.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"JPush API Go Client\n====================\n\n[![GoDoc](https://godoc.org/github.com/douchunrong/jpush-client?status.svg)](https://godoc.org/github.com/douchunrong/jpush-client) [![Build Status](https://travis-ci.org/douchunrong/jpush-client.svg?branch=master)](https://travis-ci.org/douchunrong/jpush-client)\n\n# 概述\n\n这是 JPush REST API 的 Golang 版本封装开发包，**非官方实现**，只支持 v3 版本。\n\n官方 REST API 文档： [http://docs.jpush.cn/display/dev/REST+API](http://docs.jpush.cn/display/dev/REST+API)\n\n# 安装\n\n使用 go get 安装，无任何第三方依赖：\n\n```sh\ngo get github.com/douchunrong/jpush-client\n```\n\n# 使用方法\n\n## 1. 创建 JPushClient\n\n```go\nimport \"github.com/douchunrong/jpush-client\"\n\nconst (\n    appKey = \"\"\n    masterSecret = \"\"\n)\n\njclient := jpush.NewJPushClient(appKey, masterSecret)\n```\n\n## 2. 逐步构建消息体\n\n与推送有关的数据结构都在 push 包里\n\n```go\nimport \"github.com/douchunrong/jpush-client/push\"\n```\n\n### 2.1 创建 Platform 对象\n\n```go\nplatform := push.NewPlatform()\n\n// 用 Add() 方法添加具体平台参数，可选: \"all\", \"ios\", \"android\"\nplatform.Add(\"ios\", \"android\")\n\n// 或者用 All() 方法设置所有平台\n// platform.All()\n```\n\n### 2.2 创建 Audience 对象\n\n```go\naudience := push.NewAudience()\naudience.SetTag([]string{\"广州\", \"深圳\"})   // 设置 tag\n// audience.SetTagAnd([]string{\"北京\", \"女\"}) // 设置 tag_and\n// audience.SetAlias([]string{\"alias1\", \"alias2\"})  // 设置 alias\n// audience.SetRegistrationId([]string{\"id1\", \"id2\"})   // 设置 registration_id\n// audience.All()   和 platform 一样，可以调用 All() 方法设置所有受众\n```\n\n### 2.3 创建 Notification 对象\n\n#### 2.3.1 创建 AndroidNotification 对象\n\n```go\n// android 平台专有的 notification，用 alert 属性初始化\nandroidNotification := push.NewAndroidNotification(\"Android Notification Alert\")\nandroidNotification.Title = \"title\"\n// androidNotification.BuilderId = 10086\nandroidNotification.AddExtra(\"key\", \"value\")\n```\n\n#### 2.3.2 创建 IosNotification 对象\n\n```go\n// iOS 平台专有的 notification，用 alert 属性初始化\niosNotification := push.NewIosNotification(\"iOS Notification Alert\")\n// iosNotification.Sound = \"/paht/to/sound\"\niosNotification.Badge = 1   // 只支持 int 类型的 badge\n// iosNotification.ContentAvailable = true\n// iosNotification.Category = \"category_name\"\n// iosNotification.AddExtra(\"key\", \"value\")\n\n// Validate 方法可以验证 iOS notification 是否合法\n// 一般情况下，开发者不需要直接调用此方法，这个方法会在构造 PushObject 时自动调用\n// iosNotification.Validate()\n```\n\n#### 2.3.3 创建 WinphoneNotification 对象\n\n```go\n// Windows Phone 平台专有的 notification，用 alert 属性初始化\nwpNotification := push.NewWinphoneNotification(\"Winphone Notification Alert\")\n// wpNotification.Title = \"Winphone Notification Title\"\n// wpNotification.OpenPage = \"some page\"\n\n// 所有平台的专有 notification 都有 AddExtra 方法，用于添加 extra 信息\nwpNotification.AddExtra(\"extra_key\", \"extra_value\")\n```\n\n#### 2.3.4 创建 Notification 对象\n\nAndroidNotification, IosNotification, WinphoneNotification 三个分别是三种平台专有的 notification。\n\nNotification 是极光推送的“通知”，包含一个 alert 属性，和可选的三个平台属性。\n\n```go\n// notification 对象，表示 通知，传递 alert 属性初始化\nnotification := push.NewNotification(\"Notification Alert\")\nnotification.Android = androidNotification\nnotification.Ios = iosNotification\nnotification.Winphone = wpNotification\n```\n\n### 2.4 创建 Message 对象\n\nMessage 是极光推送的“消息”，也叫透传消息\n\n```go\n// message 对象，表示 透传消息，用 content 属性初始化\nmessage := push.NewMessage(\"Message Content must not be empty\")\n// message.Title = \"Message Title\"\n// message.ContentType = \"application/json\"\n\n// 可以调用 AddExtra 方法，添加额外信息\n// message.AddExtra(\"key\", 123)\n```\n\n### 2.5 创建 Options 对象\n\n```go\n// option 对象，表示推送可选项\noptions := push.NewOptions()\n// options.SendNo = 12345\n// options.OverrideMsgId = 123333333\n\n// Options 的 Validate 方法会对 time_to_live 属性做范围限制，以满足 JPush 的规范\noptions.TimeToLive = 10000000\n\n// iOS 平台，是否推送生产环境，false 表示开发环境；如果不指定，就是生产环境\noptions.ApnsProduction = true\n\n// Options 的 Validate 方法会对 big_push_duration 属性做范围限制，以满足 JPush 的规范\noptions.BigPushDuration = 1500\n\n// Options 对象有 Validate 方法，但实际上这里并不会返回错误，\n// 而是对 time_to_live 和 big_push_duration 两个值做了范围限制\n// 开发者不需要手动调用此方法，在构建 PushObject 时会自动调用\n// err := options.Validate()\n```\n\n### 2.6 创建 PushObject 对象\n\n```go\npayload := push.NewPushObject()\npayload.Platform = platform\npayload.Audience = audience\npayload.Notification = notification\npayload.Message = message\npayload.Options = options\n\n// 打印查看 json 序列化的结果，也就是 POST 请求的 body\n// data, err := json.Marshal(payload)\n// if err != nil {\n//    fmt.Println(\"json.Marshal PushObject failed:\", err)\n// } else {\n//    fmt.Println(\"payload:\", string(data), \"\\n\")\n// }\n```\n\n## 3. 推送/推送验证\n\n```go\n// result, err := jclient.Push(payload)\nresult, err := jclient.PushValidate(payload)\nif err != nil {\n    fmt.Print(\"PushValidate failed:\", err)\n} else {\n    fmt.Println(\"PushValidate result:\", result)\n}\n```\n\n## 4. 更多示例\n\n更多例子可以看这里：[jpush_test.go](jpush_test.go)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdouchunrong%2Fjpush-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdouchunrong%2Fjpush-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdouchunrong%2Fjpush-client/lists"}