Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
app_push
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_server
app_push
Commits
12ad5125
Commit
12ad5125
authored
Oct 17, 2019
by
李福中
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enhance push service can push to android and ios by device
parent
ddb1aa07
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
7 deletions
+54
-7
app/controllers/pushs_controller.rb
+10
-3
app/services/push.rb
+11
-2
app/services/push/igetui/push.rb
+16
-0
app/services/settings.rb
+15
-0
app/workers/push_worker.rb
+2
-2
No files found.
app/controllers/pushs_controller.rb
View file @
12ad5125
...
@@ -26,6 +26,7 @@ class PushsController < ApplicationController
...
@@ -26,6 +26,7 @@ class PushsController < ApplicationController
param!
:igetui_opts
,
String
param!
:igetui_opts
,
String
param!
:app_type
,
String
param!
:app_type
,
String
param!
:sync_push
,
String
param!
:sync_push
,
String
param!
:device
,
String
,
required:
false
# optionals: 'android', 'ios'
igetui_opts
=
JSON
.
parse
(
params
[
:igetui_opts
])
rescue
{}
igetui_opts
=
JSON
.
parse
(
params
[
:igetui_opts
])
rescue
{}
message
=
JSON
.
parse
(
params
[
:message
])
rescue
{}
message
=
JSON
.
parse
(
params
[
:message
])
rescue
{}
...
@@ -33,15 +34,21 @@ class PushsController < ApplicationController
...
@@ -33,15 +34,21 @@ class PushsController < ApplicationController
token
=
token_and_options
(
request
).
first
token
=
token_and_options
(
request
).
first
if
token
==
Token
.
token
(
params
[
:app_name
])
if
token
==
Token
.
token
(
params
[
:app_name
])
if
params
.
has_key?
(
:sync_push
)
if
params
.
has_key?
(
:sync_push
)
Timeout
.
timeout
(
3
)
{
timeout_seconds
=
$redis
.
get
(
'push_timeout'
).
to_i
::
PushWorker
.
new
.
perform
(
device_ids_opts
,
message
,
igetui_opts
,
params
[
:app_type
])
if
timeout_seconds
>
0
Timeout
.
timeout
(
timeout_seconds
)
{
::
PushWorker
.
new
.
perform
(
device_ids_opts
,
message
,
igetui_opts
,
params
[
:app_type
],
device:
params
[
:device
])
}
}
else
else
::
PushWorker
.
perform_async
(
device_ids_opts
,
message
,
igetui_opts
,
params
[
:app_type
])
::
PushWorker
.
new
.
perform
(
device_ids_opts
,
message
,
igetui_opts
,
params
[
:app_type
],
device:
params
[
:device
])
end
else
::
PushWorker
.
perform_async
(
device_ids_opts
,
message
,
igetui_opts
,
params
[
:app_type
],
device:
params
[
:device
])
end
end
render
json:
{
code:
0
,
message:
'success'
,
describe:
'异步任务正在处理'
}
render
json:
{
code:
0
,
message:
'success'
,
describe:
'异步任务正在处理'
}
else
else
render
json:
{
code:
-
1
,
message:
'token 错误/过期'
}
render
json:
{
code:
-
1
,
message:
'token 错误/过期'
}
end
end
end
end
end
end
app/services/push.rb
View file @
12ad5125
...
@@ -12,8 +12,8 @@ module Push
...
@@ -12,8 +12,8 @@ module Push
# xiaomi: [],
# xiaomi: [],
# huawei: []
# huawei: []
# }
# }
def
push
(
device_ids_opts
,
message
,
igetui_opts
=
{},
app_type
=
nil
)
def
push
(
device_ids_opts
,
message
,
igetui_opts
=
{},
app_type
=
nil
,
device:
nil
)
Settings
.
platform
=
app_type
||
Settings
::
DEFAULT
Settings
.
set_platform_device
(
app_type
||
Settings
::
DEFAULT
,
device_suffix:
device_suffix
(
device
))
Push
::
Log
.
info
(
"*************** push_service ***************:
\n
device_ids_opts:
#{
device_ids_opts
}
, message:
#{
message
}
, igetui_opts:
#{
igetui_opts
}
platform:
#{
Settings
.
platform
}
"
)
Push
::
Log
.
info
(
"*************** push_service ***************:
\n
device_ids_opts:
#{
device_ids_opts
}
, message:
#{
message
}
, igetui_opts:
#{
igetui_opts
}
platform:
#{
Settings
.
platform
}
"
)
message
=
message
.
with_indifferent_access
message
=
message
.
with_indifferent_access
igetui_opts
=
igetui_opts
.
with_indifferent_access
igetui_opts
=
igetui_opts
.
with_indifferent_access
...
@@ -33,5 +33,14 @@ module Push
...
@@ -33,5 +33,14 @@ module Push
rescue
StandardError
=>
err
rescue
StandardError
=>
err
Push
::
Log
.
error
(
err
)
Push
::
Log
.
error
(
err
)
end
end
private
def
device_suffix
(
device
)
case
device
.
to_s
when
/android/i
then
'_android'
when
/ios/i
then
'_ios'
end
end
end
end
end
end
app/services/push/igetui/push.rb
View file @
12ad5125
...
@@ -49,6 +49,22 @@ module Push
...
@@ -49,6 +49,22 @@ module Push
)
)
end
end
def
android_pusher
@android_pusher
||=
IGeTui
.
pusher
(
Settings
.
platform_settings
.
igetui
[
'app_id'
],
Settings
.
platform_settings
.
igetui
[
'app_key'
],
Settings
.
platform_settings
.
igetui
[
'master_secret'
]
)
end
def
ios_pusher
@ios_pusher
||=
IGeTui
.
pusher
(
Settings
.
platform_settings
.
igetui
[
'app_id'
],
Settings
.
platform_settings
.
igetui
[
'app_key'
],
Settings
.
platform_settings
.
igetui
[
'master_secret'
]
)
end
def
set_message
def
set_message
@message
=
case
pusher_type
@message
=
case
pusher_type
when
'push_message_to_single'
when
'push_message_to_single'
...
...
app/services/settings.rb
View file @
12ad5125
...
@@ -9,12 +9,27 @@ class Settings < Settingslogic
...
@@ -9,12 +9,27 @@ class Settings < Settingslogic
@platform
=
platform
if
PLATFORM
.
include?
platform
@platform
=
platform
if
PLATFORM
.
include?
platform
end
end
def
set_platform_device
(
platform
,
device_suffix:
''
)
if
PLATFORM
.
include?
(
platform
)
@platform
=
platform
end
@device_suffix
=
device_suffix
end
def
self
.
platform
def
self
.
platform
@platform
||
DEFAULT
@platform
||
DEFAULT
end
end
def
self
.
platform_with_device
"
#{
@platform
||
DEFAULT
}#{
@device_suffix
}
"
end
def
self
.
platform_settings
def
self
.
platform_settings
if
Settings
[
platform_with_device
].
present?
self
.
send
(
platform_with_device
)
else
self
.
send
(
platform
)
self
.
send
(
platform
)
end
end
end
end
end
app/workers/push_worker.rb
View file @
12ad5125
...
@@ -2,8 +2,8 @@ class PushWorker
...
@@ -2,8 +2,8 @@ class PushWorker
include
Sidekiq
::
Worker
include
Sidekiq
::
Worker
sidekiq_options
queue: :push
sidekiq_options
queue: :push
def
perform
(
device_ids_opts
,
message
,
igetui_opts
,
platform
=
nil
)
def
perform
(
device_ids_opts
,
message
,
igetui_opts
,
platform
=
nil
,
device:
nil
)
Push
.
push
(
device_ids_opts
,
message
,
igetui_opts
,
platform
)
Push
.
push
(
device_ids_opts
,
message
,
igetui_opts
,
platform
,
device:
device
)
rescue
StandardError
=>
e
rescue
StandardError
=>
e
ErrorLog
.
error
(
e
)
ErrorLog
.
error
(
e
)
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment