diff --git a/api/app/Http/Helpers.php b/api/app/Http/Helpers.php index bb3dd3f..af6d9c1 100644 --- a/api/app/Http/Helpers.php +++ b/api/app/Http/Helpers.php @@ -67,7 +67,7 @@ function 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) { $desp = $text; @@ -125,3 +125,29 @@ function ios_send($is_clip, $device_token, $text, $desp = '', $dev = true) error_log('push error'. $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; +} diff --git a/docker/.DS_Store b/docker/.DS_Store index e9dc435..103c7a7 100644 Binary files a/docker/.DS_Store and b/docker/.DS_Store differ diff --git a/docker/web/gorush b/docker/web/gorush old mode 100644 new mode 100755 index 52e916a..c5a2732 Binary files a/docker/web/gorush and b/docker/web/gorush differ diff --git a/push/clip.yml b/push/clip.yml index c39e855..21ba431 100755 --- a/push/clip.yml +++ b/push/clip.yml @@ -4,6 +4,7 @@ core: shutdown_timeout: 30 # default is 30 second port: "8889" # ignore this port number if auto_tls is enabled (listen 443). sync: false + mode: "release" max_notification: 1 cert_path: "cc.p12" key_path: "" @@ -44,5 +45,18 @@ log: error_level: "error" 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: - 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 diff --git a/push/clip.yml.sample b/push/clip.yml.sample index 700ccc2..889b581 100755 --- a/push/clip.yml.sample +++ b/push/clip.yml.sample @@ -44,5 +44,18 @@ log: error_level: "error" 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: - 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 diff --git a/push/gorush-with-mipush/RoboFile.php b/push/gorush-with-mipush/RoboFile.php index babcda9..8a56713 100644 --- a/push/gorush-with-mipush/RoboFile.php +++ b/push/gorush-with-mipush/RoboFile.php @@ -19,6 +19,6 @@ class RoboFile extends \Robo\Tasks 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"); } } diff --git a/push/gorush-with-mipush/bin/.gitignore b/push/gorush-with-mipush/bin/.gitignore new file mode 100644 index 0000000..f4bc27b --- /dev/null +++ b/push/gorush-with-mipush/bin/.gitignore @@ -0,0 +1 @@ +gorush* \ No newline at end of file diff --git a/push/gorush-with-mipush/src/core/core.go b/push/gorush-with-mipush/src/core/core.go index e75d172..b51bb96 100644 --- a/push/gorush-with-mipush/src/core/core.go +++ b/push/gorush-with-mipush/src/core/core.go @@ -7,8 +7,8 @@ const ( PlatFormAndroid // PlatFormHuawei constant is 3 for Huawei PlatFormHuawei - //PlaFormMI constant is 4 for MI - PlaFormMI + //PlatFormMI constant is 4 for MI + PlatFormMI ) const ( diff --git a/push/gorush-with-mipush/src/go.mod b/push/gorush-with-mipush/src/go.mod index 1e95ddd..7f6d919 100644 --- a/push/gorush-with-mipush/src/go.mod +++ b/push/gorush-with-mipush/src/go.mod @@ -17,8 +17,8 @@ require ( github.com/go-redis/redis/v8 v8.11.3 github.com/golang-queue/nats v0.0.4 github.com/golang-queue/nsq v0.0.6 - github.com/golang-queue/queue v0.0.10 - github.com/golang-queue/redisdb v0.0.5 + github.com/golang-queue/queue v0.0.11 + github.com/golang-queue/redisdb v0.0.6 github.com/golang/glog v0.0.0-20210429001901-424d2337a529 // indirect github.com/golang/protobuf v1.5.2 github.com/google/flatbuffers v2.0.0+incompatible // indirect diff --git a/push/gorush-with-mipush/src/go.sum b/push/gorush-with-mipush/src/go.sum index fadd6e8..be6bdf9 100644 --- a/push/gorush-with-mipush/src/go.sum +++ b/push/gorush-with-mipush/src/go.sum @@ -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/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.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/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-20210429001901-424d2337a529 h1:2voWjNECnrZRbfwXxHB1/j8wa6xdKn85B5NzgVL/pTU= github.com/golang/glog v0.0.0-20210429001901-424d2337a529/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= diff --git a/push/gorush-with-mipush/src/logx/log.go b/push/gorush-with-mipush/src/logx/log.go index b7b78b6..2f22437 100644 --- a/push/gorush-with-mipush/src/logx/log.go +++ b/push/gorush-with-mipush/src/logx/log.go @@ -123,6 +123,8 @@ func colorForPlatForm(platform int) string { return yellow case core.PlatFormHuawei: return green + case core.PlatFormMI: + return red default: return reset } @@ -136,6 +138,8 @@ func typeForPlatForm(platform int) string { return "android" case core.PlatFormHuawei: return "huawei" + case core.PlatFormMI: + return "xiaomi" default: return "" } diff --git a/push/gorush-with-mipush/src/main.go b/push/gorush-with-mipush/src/main.go index 84f380f..e6e3add 100644 --- a/push/gorush-with-mipush/src/main.go +++ b/push/gorush-with-mipush/src/main.go @@ -249,6 +249,41 @@ func main() { return } + // send MI notification + if opts.MI.Enabled { + cfg.MI.Enabled = opts.MI.Enabled + req := ¬ify.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 if opts.Ios.Enabled { 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 { return router.RunHTTPServer(ctx, cfg, q) }) diff --git a/push/gorush-with-mipush/src/notify/notification.go b/push/gorush-with-mipush/src/notify/notification.go index 8e19c2d..d23550f 100644 --- a/push/gorush-with-mipush/src/notify/notification.go +++ b/push/gorush-with-mipush/src/notify/notification.go @@ -196,8 +196,8 @@ func SetProxy(proxy string) error { // CheckPushConf provide check your yml config. func CheckPushConf(cfg *config.ConfYaml) error { - if !cfg.Ios.Enabled && !cfg.Android.Enabled && !cfg.Huawei.Enabled { - return errors.New("please enable iOS, Android or Huawei config in yml config") + if !cfg.Ios.Enabled && !cfg.Android.Enabled && !cfg.Huawei.Enabled && !cfg.MI.Enabled { + return errors.New("please enable iOS, Android, Huawei or Mi config in yml config") } if cfg.Ios.Enabled { @@ -248,7 +248,7 @@ func SendNotification(req queue.QueuedMessage, cfg *config.ConfYaml) (resp *Resp resp, err = PushToAndroid(v, cfg) case core.PlatFormHuawei: resp, err = PushToHuawei(v, cfg) - case core.PlaFormMI: + case core.PlatFormMI: resp, err = PushToMI(v, cfg) } @@ -267,6 +267,7 @@ func SendNotification(req queue.QueuedMessage, cfg *config.ConfYaml) (resp *Resp // Run send notification var Run = func(cfg *config.ConfYaml) 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) return err } diff --git a/push/gorush-with-mipush/src/router/server.go b/push/gorush-with-mipush/src/router/server.go index 7abada9..69de769 100644 --- a/push/gorush-with-mipush/src/router/server.go +++ b/push/gorush-with-mipush/src/router/server.go @@ -266,7 +266,7 @@ func handleNotification(ctx context.Context, cfg *config.ConfYaml, req notify.Re if !cfg.Huawei.Enabled { continue } - case core.PlaFormMI: + case core.PlatFormMI: if !cfg.MI.Enabled { continue } diff --git a/push/ios.yml b/push/ios.yml index f6f7b81..b787191 100755 --- a/push/ios.yml +++ b/push/ios.yml @@ -36,6 +36,12 @@ ios: key_id: "66M7BD2GCV" # KeyID from developer account (Certificates, Identifiers & Profiles -> Keys) 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: format: "string" # string or json access_log: "stdout" # stdout: output to console, or define log path like "log/access_log" @@ -44,5 +50,18 @@ log: error_level: "error" 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: - 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 diff --git a/push/ios.yml.smaple b/push/ios.yml.smaple index 6b06301..ed368a9 100755 --- a/push/ios.yml.smaple +++ b/push/ios.yml.smaple @@ -36,6 +36,12 @@ ios: key_id: "66M7BD2GCV" # KeyID from developer account (Certificates, Identifiers & Profiles -> Keys) 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: format: "string" # string or json access_log: "stdout" # stdout: output to console, or define log path like "log/access_log" @@ -44,5 +50,18 @@ log: error_level: "error" 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: - 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