腾讯信鸽push Golang lib
信鸽v3版API的简单封装
$ go get github.com/FrontMage/xinge
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)
}
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)
}
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)
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)
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)
}
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)
}
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。