frontmage / xinge Goto Github PK
View Code? Open in Web Editor NEW腾讯信鸽push Golang lib
License: Apache License 2.0
腾讯信鸽push Golang lib
License: Apache License 2.0
Android可以正常收发,IOS,retcode是0,但是客户端收不到,麻烦帮忙看下,多谢
`func PushIOSMessage(rids []int, title, content, appID, secretKey string) error {
accounts := make([]string, len(rids))
for i, rid := range(rids) {
accounts[i] = strconv.Itoa(rid)
}
var pushReq *http.Request
if gin.Mode() == "debug" {
pushReq, _ = req.NewPushReq(
&xinge.Request{},
req.Platform(xinge.PlatformiOS),
req.EnvDev(),
req.AudienceType(xinge.AdAccountList),
req.MessageType(xinge.MsgTypeNotify),
req.AccountList(accounts),
req.PushID("0"),
req.Message(xinge.Message{
Title: title,
Content: content,
}),
)
} else {
pushReq, _ = req.NewPushReq(
&xinge.Request{},
req.Platform(xinge.PlatformiOS),
req.AudienceType(xinge.AdAccountList),
req.MessageType(xinge.MsgTypeNotify),
req.AccountList(accounts),
req.PushID("0"),
req.Message(xinge.Message{
Title: title,
Content: content,
}),
)
}
return pushMessage(pushReq, appID, secretKey)
}
func pushMessage(pushReq* http.Request, appID, secretKey string) error {
auther := auth.Auther{AppID: appID, SecretKey: secretKey}
auther.Auth(pushReq)
c := &http.Client{}
rsp, err := c.Do(pushReq)
if err != nil {
log.Error(err)
return err
}
defer rsp.Body.Close()
body, _ := ioutil.ReadAll(rsp.Body)
r := &xinge.CommonRsp{}
json.Unmarshal(body, r)
if r.RetCode != 0 {
msg := fmt.Sprintf("%+v", r)
log.Error(msg)
return errors.New(msg)
}
return nil
}
`
目前push的response的result字段已改成string类型,不再是map[string]string
// Aps 通知栏iOS消息的aps字段,详情请参照苹果文档
type Aps struct {
Alert map[string]string json:"alert,omitempty"
Badge int json:"badge,omitempty"
Category string json:"category,omitempty"
ContentAvailable int json:"content-available,omitempty"
Sound string json:"sound,omitempty"
}
Badge 应该对应badge_type,应该参考腾讯信鸽文档。如果写成badge角标没反应
我的使用安卓推送没有问题,但是使用ios推送,收不到自定义的消息,在后台历史推送里面也看不到
这是我的代码
auther := auth.Auther{AppID: "", SecretKey: ""}
pushReq, _ = req.NewPushReq(
&xinge.Request{},
req.Platform(xinge.PlatformiOS),
req.EnvDev(),
req.AudienceType(xinge.AdToken),
req.MessageType(xinge.MsgTypeNotify),
req.TokenList([]string{NotificationId}),
req.PushID("0"),
req.Message(xinge.Message{
Title: "",
Content: "",
Android: &xinge.AndroidParams{},
IOS: &xinge.IOSParams{},
}),
req.CustomContent(custom),
)
custom 是一个map[string]string
代码基本和安卓的一模一样
因为 http.Client.Do() 的错误没有处理, 直接defer Close() 了
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.