Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/frontmage/xinge
腾讯信鸽push Golang lib
https://github.com/frontmage/xinge
push push-notifications tencent xinge
Last synced: 30 days ago
JSON representation
腾讯信鸽push Golang lib
- Host: GitHub
- URL: https://github.com/frontmage/xinge
- Owner: FrontMage
- License: apache-2.0
- Created: 2018-06-29T05:03:40.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-09-28T04:52:31.000Z (over 6 years ago)
- Last Synced: 2024-06-20T10:18:55.636Z (7 months ago)
- Topics: push, push-notifications, tencent, xinge
- Language: Go
- Size: 14.6 KB
- Stars: 26
- Watchers: 2
- Forks: 12
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# xinge
[![Go Report Card](https://goreportcard.com/badge/github.com/FrontMage/xinge)](https://goreportcard.com/report/github.com/FrontMage/xinge)
[![GoDoc](https://godoc.org/github.com/FrontMage/xinge?status.svg)](https://godoc.org/github.com/FrontMage/xinge)腾讯信鸽push Golang lib
`信鸽v3版API的简单封装`
## 用法
### 安装
`$ go get github.com/FrontMage/xinge`### 安卓单账号push
```go
import (
"net/http"
"io/ioutil"
"encoding/json"
"fmt"
"github.com/FrontMage/xinge"
"github.com/FrontMage/xinge/req"
"github.com/FrontMage/xinge/auth"
)func main() {
auther := auth.Auther{AppID: "AppID", SecretKey: "SecretKey"}
pushReq, _ := req.NewSingleAndroidAccountPush("account", "title", "content")
auther.Auth(pushReq)c := &http.Client{}
rsp, _ := c.Do(pushReq)
defer rsp.Body.Close()
body, _ := ioutil.ReadAll(rsp.Body)r := &xinge.CommonRsp{}
json.Unmarshal(body, r)
fmt.Printf("%+v", r)
}
```### 苹果单账号push
```go
import (
"net/http"
"io/ioutil"
"encoding/json"
"fmt"
"github.com/FrontMage/xinge/req"
"github.com/FrontMage/xinge/auth"
)func main() {
auther := auth.Auther{AppID: "AppID", SecretKey: "SecretKey"}
pushReq, _ := req.NewSingleIOSAccountPush("account", "title", "content")
auther.Auth(pushReq)c := &http.Client{}
rsp, _ := c.Do(pushReq)
defer rsp.Body.Close()
body, _ := ioutil.ReadAll(rsp.Body)r := &xinge.CommonRsp{}
json.Unmarshal(body, r)
fmt.Printf("%+v", r)
}
```### 安卓多账号push
```go
auther := auth.Auther{AppID: "AppID", SecretKey: "SecretKey"}
pushReq, _ := req.NewPushReq(
&xinge.Request{},
req.Platform(xinge.PlatformAndroid),
req.AudienceType(xinge.AdAccountList),
req.MessageType(xinge.MsgTypeNotify),
req.AccountList([]string{"10000031", "10000034"}),
req.PushID("0"),
req.Message(xinge.Message{
Title: "haha",
Content: "hehe",
}),
)
auther.Auth(pushReq)c := &http.Client{}
rsp, _ := c.Do(pushReq)
defer rsp.Body.Close()
body, _ := ioutil.ReadAll(rsp.Body)r := &xinge.CommonRsp{}
json.Unmarshal(body, r)
fmt.Printf("%+v", r)
```### iOS多账号push
```go
auther := auth.Auther{AppID: "AppID", SecretKey: "SecretKey"}
pushReq, _ := req.NewPushReq(
&xinge.Request{},
req.Platform(xinge.PlatformiOS),
req.EnvDev(),
req.AudienceType(xinge.AdAccountList),
req.MessageType(xinge.MsgTypeNotify),
req.AccountList([]string{"10000031", "10000034"}),
req.PushID("0"),
req.Message(xinge.Message{
Title: "haha",
Content: "hehe",
}),
)
auther.Auth(pushReq)c := &http.Client{}
rsp, _ := c.Do(pushReq)
defer rsp.Body.Close()
body, _ := ioutil.ReadAll(rsp.Body)r := &xinge.CommonRsp{}
json.Unmarshal(body, r)
fmt.Printf("%+v", r)
```### 单设备push
```go
auther := auth.Auther{AppID: "AppID", SecretKey: "SecretKey"}
pushReq, _ := req.NewPushReq(
&xinge.Request{},
req.Platform(xinge.PlatformiOS),
req.EnvDev(),
req.AudienceType(xinge.AdToken),
req.MessageType(xinge.MsgTypeNotify),
req.TokenList([]string{"10000031", "10000034"}),
req.PushID("0"),
req.Message(xinge.Message{
Title: "haha",
Content: "hehe",
}),
)
auther.Auth(pushReq)c := &http.Client{}
rsp, _ := c.Do(pushReq)
defer rsp.Body.Close()
body, _ := ioutil.ReadAll(rsp.Body)r := &xinge.CommonRsp{}
json.Unmarshal(body, r)
fmt.Printf("%+v", r)
if r.RetCode != 0 {
t.Errorf("Failed rsp=%+v", r)
}
```### 多设备push
```go
auther := auth.Auther{AppID: "AppID", SecretKey: "SecretKey"}
pushReq, _ := req.NewPushReq(
&xinge.Request{},
req.Platform(xinge.PlatformiOS),
req.EnvDev(),
req.AudienceType(xinge.AdTokenList),
req.MessageType(xinge.MsgTypeNotify),
req.TokenList([]string{"10000031", "10000034"}),
req.PushID("0"),
req.Message(xinge.Message{
Title: "haha",
Content: "hehe",
}),
)
auther.Auth(pushReq)c := &http.Client{}
rsp, _ := c.Do(pushReq)
defer rsp.Body.Close()
body, _ := ioutil.ReadAll(rsp.Body)r := &xinge.CommonRsp{}
json.Unmarshal(body, r)
fmt.Printf("%+v", r)
if r.RetCode != 0 {
t.Errorf("Failed rsp=%+v", r)
}
```### 标签push
```go
auther := auth.Auther{AppID: "AppID", SecretKey: "SecretKey"}
pushReq, _ := req.NewPushReq(
&xinge.Request{},
req.Platform(xinge.PlatformiOS),
req.EnvDev(),
req.AudienceType(xinge.AdTag),
req.MessageType(xinge.MsgTypeNotify),
req.TagList(&xinge.TagList{
Tags: []string{"new", "active"},
Operation: xinge.TagListOpAnd,
}),
req.PushID("0"),
req.Message(xinge.Message{
Title: "haha",
Content: "hehe",
}),
)
auther.Auth(pushReq)c := &http.Client{}
rsp, _ := c.Do(pushReq)
defer rsp.Body.Close()
body, _ := ioutil.ReadAll(rsp.Body)r := &xinge.CommonRsp{}
json.Unmarshal(body, r)
fmt.Printf("%+v", r)
if r.RetCode != 0 {
t.Errorf("Failed rsp=%+v", r)
}
```## 贡献代码指南
目前的设计是通过`ReqOpt`函数来扩展各种请求参数,尽量请保持代码风格一致,使用`gofmt`来格式化代码。贡献代码时可先从项目中的`TODO`开始,同时也欢迎提交新feature的PR和bug issue。