Пример #1
0
// onMessage receives messages, logs them, and echoes a response.
func onMessage(cm gcm.CcsMessage) error {
	toylog.Infoln("Message, from:", cm.From, "with:", cm.Data)
	// Echo the message with a tag.
	cm.Data["echoed"] = true
	m := gcm.HttpMessage{To: cm.From, Data: cm.Data}
	r, err := gcm.SendHttp(*serverKey, m)
	if err != nil {
		toylog.Errorln("Error sending message.", err)
		return err
	}
	toylog.Infof("Sent message. %+v -> %+v", m, r)
	return nil
}
Пример #2
0
// onMessage receives messages, logs them, and echoes a response.
func onMessage(from string, d gcm.Data) error {
	toylog.Infoln("Message, from:", from, "with:", d)
	// Echo the message with a tag.
	d["echoed"] = true
	m := gcm.HttpMessage{To: from, Data: d}
	r, err := gcm.SendHttp(*serverKey, m)
	if err != nil {
		toylog.Errorln("Error sending message.", err)
		return err
	}
	toylog.Infof("Sent message. %+v -> %+v", m, r)
	return nil
}
Пример #3
0
func main() {
	toylog.Infoln("GCM Logger, starting.")
	gcm.DebugMode = true

	go gcm.Listen("362865506329", "AIzaSyBzLWgu7eJssFcUi1imbohV7hwWn00XFWM", onMessage, nil)

	for {
		fmt.Print("Text: ")
		reader := bufio.NewReader(os.Stdin)
		text, _ := reader.ReadString('\n')
		dataMap := gcm.Data{"message": text}
		dataMap["url"] = "http://www.amazon.de/BenQ-DLP-Projektor-Triple-1920x1080-Kontrast/dp/B00HR2PII8/ref=sr_1_1?ie=UTF8&qid=1446955299&sr=8-1&keywords=Beamer"
		dataMap["title"] = "BenQ TH681 Full HD 3D DLP-Projektor "
		dataMap["price"] = "635"
		dataMap["shop"] = "Amazon.de"
		dataMap["discount"] = "20%"
		dataMap["msrp"] = "762"
		dataMap["imgURL"] = "http://www.presse-citron.net/wordpress_prod/wp-content/uploads/2014/06/benq-th681-01.jpg"
		sendMessagetoAll(dataMap)
	}
}
Пример #4
0
func registerClient(cm gcm.CcsMessage) {
	//		stmt.Exec(cm.Data["registration_token"], cm.Data["stringIdentifier"])
	toylog.Infoln(cm.Data)

}
Пример #5
0
func main() {
	toylog.Infoln("GCM Logger, starting.")
	kingpin.Parse()
	gcm.Listen(*senderId, *serverKey, onMessage, nil)
}