修正了push不支持Redis队列的Bug,全面使用go rush作为推送中间件

This commit is contained in:
Easy 2022-02-08 01:28:22 +08:00
parent e0b359f2a1
commit d1d4566152
16 changed files with 156 additions and 14 deletions

View File

@ -67,7 +67,7 @@ function android_sender()
return $GLOBALS['PD_ANDROID_SENDER']; return $GLOBALS['PD_ANDROID_SENDER'];
} }
function android_send($is_clip, $device_token, $text, $desp = '', $dev = true) function android_send_no_queue($is_clip, $device_token, $text, $desp = '', $dev = true)
{ {
if (strlen($desp) < 1) { if (strlen($desp) < 1) {
$desp = $text; $desp = $text;
@ -125,3 +125,29 @@ function ios_send($is_clip, $device_token, $text, $desp = '', $dev = true)
error_log('push error'. $ret); error_log('push error'. $ret);
return $ret; return $ret;
} }
function android_send($is_clip, $device_token, $text, $desp = '', $dev = true)
{
$notification = new stdClass();
$notification->tokens = [ $device_token ];
$notification->platform = 4;
if (strlen($desp) > 1) {
$notification->title = $text;
$notification->message = $desp;
} else {
$notification->title = "PushDeer"; // title不能为空
$notification->message = $text;
}
$port = config('services.go_push.ios_port');
$json = ['notifications'=>[$notification]];
$client = new GuzzleHttp\Client();
$response = $client->post('http://'.config('services.go_push.address').':'. $port .'/api/push', [
GuzzleHttp\RequestOptions::JSON => $json
]);
$ret = $response->getBody()->getContents();
error_log('push error'. $ret);
return $ret;
}

BIN
docker/.DS_Store vendored

Binary file not shown.

BIN
docker/web/gorush Normal file → Executable file

Binary file not shown.

View File

@ -4,6 +4,7 @@ core:
shutdown_timeout: 30 # default is 30 second shutdown_timeout: 30 # default is 30 second
port: "8889" # ignore this port number if auto_tls is enabled (listen 443). port: "8889" # ignore this port number if auto_tls is enabled (listen 443).
sync: false sync: false
mode: "release"
max_notification: 1 max_notification: 1
cert_path: "cc.p12" cert_path: "cc.p12"
key_path: "" key_path: ""
@ -44,5 +45,18 @@ log:
error_level: "error" error_level: "error"
hide_token: true hide_token: true
queue:
engine: "local" # redis engine 没有实现
redis:
cluster: false
addr: "redis:6379" # if cluster is true, you may set this to "localhost:6379,localhost:6380,localhost:6381"
password: ""
db: 0
stat: stat:
engine: "memory" # support memory, redis, boltdb, buntdb or leveldb engine: "redis" # support memory, redis, boltdb, buntdb or leveldb
redis:
cluster: false
addr: "redis:6379" # if cluster is true, you may set this to "localhost:6379,localhost:6380,localhost:6381"
password: ""
db: 0

View File

@ -44,5 +44,18 @@ log:
error_level: "error" error_level: "error"
hide_token: true hide_token: true
queue:
engine: "local" # support memory, redis, boltdb, buntdb or leveldb
redis:
cluster: false
addr: "redis:6379" # if cluster is true, you may set this to "localhost:6379,localhost:6380,localhost:6381"
password: ""
db: 0
stat: stat:
engine: "memory" # support memory, redis, boltdb, buntdb or leveldb engine: "redis" # support memory, redis, boltdb, buntdb or leveldb
redis:
cluster: false
addr: "redis:6379" # if cluster is true, you may set this to "localhost:6379,localhost:6380,localhost:6381"
password: ""
db: 0

View File

@ -19,6 +19,6 @@ class RoboFile extends \Robo\Tasks
public function buildLinux() public function buildLinux()
{ {
$this->_exec("cd src && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ../bin/gorush"); $this->_exec("cd src && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ../../../docker/web/gorush");
} }
} }

View File

@ -0,0 +1 @@
gorush*

View File

@ -7,8 +7,8 @@ const (
PlatFormAndroid PlatFormAndroid
// PlatFormHuawei constant is 3 for Huawei // PlatFormHuawei constant is 3 for Huawei
PlatFormHuawei PlatFormHuawei
//PlaFormMI constant is 4 for MI //PlatFormMI constant is 4 for MI
PlaFormMI PlatFormMI
) )
const ( const (

View File

@ -17,8 +17,8 @@ require (
github.com/go-redis/redis/v8 v8.11.3 github.com/go-redis/redis/v8 v8.11.3
github.com/golang-queue/nats v0.0.4 github.com/golang-queue/nats v0.0.4
github.com/golang-queue/nsq v0.0.6 github.com/golang-queue/nsq v0.0.6
github.com/golang-queue/queue v0.0.10 github.com/golang-queue/queue v0.0.11
github.com/golang-queue/redisdb v0.0.5 github.com/golang-queue/redisdb v0.0.6
github.com/golang/glog v0.0.0-20210429001901-424d2337a529 // indirect github.com/golang/glog v0.0.0-20210429001901-424d2337a529 // indirect
github.com/golang/protobuf v1.5.2 github.com/golang/protobuf v1.5.2
github.com/google/flatbuffers v2.0.0+incompatible // indirect github.com/google/flatbuffers v2.0.0+incompatible // indirect

View File

@ -169,8 +169,12 @@ github.com/golang-queue/nsq v0.0.6 h1:GXk9Dx9ex3/rQDSaK78RK2B0CBNc0ym45hclEjNDNE
github.com/golang-queue/nsq v0.0.6/go.mod h1:oKhZjEiAZ4scaQTePCSSnsmvyHb6ID0AsqE5rtKrAOE= github.com/golang-queue/nsq v0.0.6/go.mod h1:oKhZjEiAZ4scaQTePCSSnsmvyHb6ID0AsqE5rtKrAOE=
github.com/golang-queue/queue v0.0.10 h1:cGqMgHMf2eamwdd3hmOzGcSQogGu9tMhhVYPQMrMC1g= github.com/golang-queue/queue v0.0.10 h1:cGqMgHMf2eamwdd3hmOzGcSQogGu9tMhhVYPQMrMC1g=
github.com/golang-queue/queue v0.0.10/go.mod h1:ku8iyjYffqYY6Duts+xl+QYfN3/KDK4MEvXMZUkHyio= github.com/golang-queue/queue v0.0.10/go.mod h1:ku8iyjYffqYY6Duts+xl+QYfN3/KDK4MEvXMZUkHyio=
github.com/golang-queue/queue v0.0.11 h1:qaE7rOYUh+11NcO6U9zZ7NazglIwEp0j7Dn0sSoavcI=
github.com/golang-queue/queue v0.0.11/go.mod h1:ku8iyjYffqYY6Duts+xl+QYfN3/KDK4MEvXMZUkHyio=
github.com/golang-queue/redisdb v0.0.5 h1:kW+zXopFVtBmd0/19aD3fZCWc1OoRbOV+MpXo2OBp+s= github.com/golang-queue/redisdb v0.0.5 h1:kW+zXopFVtBmd0/19aD3fZCWc1OoRbOV+MpXo2OBp+s=
github.com/golang-queue/redisdb v0.0.5/go.mod h1:3LzXV4ldTCNKT0LsZXiKEhbrOM5gGISLQjYuPip+geM= github.com/golang-queue/redisdb v0.0.5/go.mod h1:3LzXV4ldTCNKT0LsZXiKEhbrOM5gGISLQjYuPip+geM=
github.com/golang-queue/redisdb v0.0.6 h1:e2qmL41iSSHHQqOwrS/+sCU2z0EPbIf6suLS+CqHGmU=
github.com/golang-queue/redisdb v0.0.6/go.mod h1:XHyGozqrYoxI96nFrrkYdx+HHV2K/zH10ZjojM183Mc=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/glog v0.0.0-20210429001901-424d2337a529 h1:2voWjNECnrZRbfwXxHB1/j8wa6xdKn85B5NzgVL/pTU= github.com/golang/glog v0.0.0-20210429001901-424d2337a529 h1:2voWjNECnrZRbfwXxHB1/j8wa6xdKn85B5NzgVL/pTU=
github.com/golang/glog v0.0.0-20210429001901-424d2337a529/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/glog v0.0.0-20210429001901-424d2337a529/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=

View File

@ -123,6 +123,8 @@ func colorForPlatForm(platform int) string {
return yellow return yellow
case core.PlatFormHuawei: case core.PlatFormHuawei:
return green return green
case core.PlatFormMI:
return red
default: default:
return reset return reset
} }
@ -136,6 +138,8 @@ func typeForPlatForm(platform int) string {
return "android" return "android"
case core.PlatFormHuawei: case core.PlatFormHuawei:
return "huawei" return "huawei"
case core.PlatFormMI:
return "xiaomi"
default: default:
return "" return ""
} }

View File

@ -249,6 +249,41 @@ func main() {
return return
} }
// send MI notification
if opts.MI.Enabled {
cfg.MI.Enabled = opts.MI.Enabled
req := &notify.PushNotification{
Platform: core.PlatFormMI,
Message: message,
Title: title,
}
// send message to single device
if token != "" {
req.Tokens = []string{token}
}
// send topic message
if topic != "" {
req.To = topic
}
err := notify.CheckMessage(req)
if err != nil {
logx.LogError.Fatal(err)
}
if err := status.InitAppStatus(cfg); err != nil {
return
}
if _, err := notify.PushToMI(req, cfg); err != nil {
return
}
return
}
// send ios notification // send ios notification
if opts.Ios.Enabled { if opts.Ios.Enabled {
if opts.Ios.Production { if opts.Ios.Production {
@ -387,6 +422,12 @@ func main() {
} }
} }
if cfg.MI.Enabled {
if _, err = notify.InitMIPUSHClient(cfg, cfg.MI.AppSecret, cfg.MI.Package ); err != nil {
logx.LogError.Fatal(err)
}
}
g.AddRunningJob(func(ctx context.Context) error { g.AddRunningJob(func(ctx context.Context) error {
return router.RunHTTPServer(ctx, cfg, q) return router.RunHTTPServer(ctx, cfg, q)
}) })

View File

@ -196,8 +196,8 @@ func SetProxy(proxy string) error {
// CheckPushConf provide check your yml config. // CheckPushConf provide check your yml config.
func CheckPushConf(cfg *config.ConfYaml) error { func CheckPushConf(cfg *config.ConfYaml) error {
if !cfg.Ios.Enabled && !cfg.Android.Enabled && !cfg.Huawei.Enabled { if !cfg.Ios.Enabled && !cfg.Android.Enabled && !cfg.Huawei.Enabled && !cfg.MI.Enabled {
return errors.New("please enable iOS, Android or Huawei config in yml config") return errors.New("please enable iOS, Android, Huawei or Mi config in yml config")
} }
if cfg.Ios.Enabled { if cfg.Ios.Enabled {
@ -248,7 +248,7 @@ func SendNotification(req queue.QueuedMessage, cfg *config.ConfYaml) (resp *Resp
resp, err = PushToAndroid(v, cfg) resp, err = PushToAndroid(v, cfg)
case core.PlatFormHuawei: case core.PlatFormHuawei:
resp, err = PushToHuawei(v, cfg) resp, err = PushToHuawei(v, cfg)
case core.PlaFormMI: case core.PlatFormMI:
resp, err = PushToMI(v, cfg) resp, err = PushToMI(v, cfg)
} }
@ -267,6 +267,7 @@ func SendNotification(req queue.QueuedMessage, cfg *config.ConfYaml) (resp *Resp
// Run send notification // Run send notification
var Run = func(cfg *config.ConfYaml) func(ctx context.Context, msg queue.QueuedMessage) error { var Run = func(cfg *config.ConfYaml) func(ctx context.Context, msg queue.QueuedMessage) error {
return func(ctx context.Context, msg queue.QueuedMessage) error { return func(ctx context.Context, msg queue.QueuedMessage) error {
logx.LogAccess.Debug("in queue")
_, err := SendNotification(msg, cfg) _, err := SendNotification(msg, cfg)
return err return err
} }

View File

@ -266,7 +266,7 @@ func handleNotification(ctx context.Context, cfg *config.ConfYaml, req notify.Re
if !cfg.Huawei.Enabled { if !cfg.Huawei.Enabled {
continue continue
} }
case core.PlaFormMI: case core.PlatFormMI:
if !cfg.MI.Enabled { if !cfg.MI.Enabled {
continue continue
} }

View File

@ -36,6 +36,12 @@ ios:
key_id: "66M7BD2GCV" # KeyID from developer account (Certificates, Identifiers & Profiles -> Keys) key_id: "66M7BD2GCV" # KeyID from developer account (Certificates, Identifiers & Profiles -> Keys)
team_id: "HUJ6HAE4VU" # TeamID from developer account (View Account -> Membership) team_id: "HUJ6HAE4VU" # TeamID from developer account (View Account -> Membership)
mi:
enabled: true
appsecret: ""
package: ""
max_retry: 3 # resend fail notification, default value zero is disabled
log: log:
format: "string" # string or json format: "string" # string or json
access_log: "stdout" # stdout: output to console, or define log path like "log/access_log" access_log: "stdout" # stdout: output to console, or define log path like "log/access_log"
@ -44,5 +50,18 @@ log:
error_level: "error" error_level: "error"
hide_token: true hide_token: true
queue:
engine: "local" # support memory, redis, boltdb, buntdb or leveldb
redis:
cluster: false
addr: "redis:6379" # if cluster is true, you may set this to "localhost:6379,localhost:6380,localhost:6381"
password: ""
db: 0
stat: stat:
engine: "memory" # support memory, redis, boltdb, buntdb or leveldb engine: "redis" # support memory, redis, boltdb, buntdb or leveldb
redis:
cluster: false
addr: "redis:6379" # if cluster is true, you may set this to "localhost:6379,localhost:6380,localhost:6381"
password: ""
db: 0

View File

@ -36,6 +36,12 @@ ios:
key_id: "66M7BD2GCV" # KeyID from developer account (Certificates, Identifiers & Profiles -> Keys) key_id: "66M7BD2GCV" # KeyID from developer account (Certificates, Identifiers & Profiles -> Keys)
team_id: "HUJ6HAE4VU" # TeamID from developer account (View Account -> Membership) team_id: "HUJ6HAE4VU" # TeamID from developer account (View Account -> Membership)
mi:
enabled: true
appsecret: ""
package: ""
max_retry: 3 # resend fail notification, default value zero is disabled
log: log:
format: "string" # string or json format: "string" # string or json
access_log: "stdout" # stdout: output to console, or define log path like "log/access_log" access_log: "stdout" # stdout: output to console, or define log path like "log/access_log"
@ -44,5 +50,18 @@ log:
error_level: "error" error_level: "error"
hide_token: true hide_token: true
queue:
engine: "local" # support memory, redis, boltdb, buntdb or leveldb
redis:
cluster: false
addr: "redis:6379" # if cluster is true, you may set this to "localhost:6379,localhost:6380,localhost:6381"
password: ""
db: 0
stat: stat:
engine: "memory" # support memory, redis, boltdb, buntdb or leveldb engine: "redis" # support memory, redis, boltdb, buntdb or leveldb
redis:
cluster: false
addr: "redis:6379" # if cluster is true, you may set this to "localhost:6379,localhost:6380,localhost:6381"
password: ""
db: 0