support android push log.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2016-04-08 18:11:36 +08:00
parent 44b7e2c187
commit 1fd41ca503
2 changed files with 12 additions and 12 deletions

View File

@ -150,7 +150,7 @@ func colorForPlatForm(platform int) string {
case PlatFormIos: case PlatFormIos:
return blue return blue
case PlatFormAndroid: case PlatFormAndroid:
return cyan return yellow
default: default:
return reset return reset
} }

View File

@ -2,11 +2,11 @@ package gopush
import ( import (
"errors" "errors"
"fmt"
"github.com/google/go-gcm" "github.com/google/go-gcm"
apns "github.com/sideshow/apns2" apns "github.com/sideshow/apns2"
"github.com/sideshow/apns2/certificate" "github.com/sideshow/apns2/certificate"
"github.com/sideshow/apns2/payload" "github.com/sideshow/apns2/payload"
"log"
) )
type ExtendJSON struct { type ExtendJSON struct {
@ -96,7 +96,7 @@ func InitAPNSClient() error {
CertificatePemIos, err = certificate.FromPemFile(PushConf.Ios.PemKeyPath, "") CertificatePemIos, err = certificate.FromPemFile(PushConf.Ios.PemKeyPath, "")
if err != nil { if err != nil {
log.Println("Cert Error:", err) LogError.Error("Cert Error:", err.Error())
return err return err
} }
@ -310,22 +310,22 @@ func PushToAndroid(req RequestPushNotification) bool {
res, err := gcm.SendHttp(PushConf.Android.ApiKey, notification) res, err := gcm.SendHttp(PushConf.Android.ApiKey, notification)
log.Printf("Success count: %d, Failure count: %d", res.Success, res.Failure)
if err != nil { if err != nil {
log.Println("GCM Server Error Message: " + err.Error()) // GCM server error
LogError.Error("GCM server error: " + err.Error())
return false return false
} }
if res.Error != "" { LogAccess.Debug(fmt.Sprintf("Android Success count: %d, Failure count: %d", res.Success, res.Failure))
log.Println("GCM Http Error Message: " + res.Error)
return false for k, result := range res.Results {
if result.Error != "" {
LogPush(StatusFailedPush, req.Tokens[k], req, errors.New(result.Error))
continue
} }
if res.Success > 0 { LogPush(StatusSucceededPush, req.Tokens[k], req, nil)
return true
} }
return true return true