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
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
13 deletions
+58
-13
app/controllers/pushs_controller.rb
+11
-4
app/services/push.rb
+11
-2
app/services/push/igetui/push.rb
+16
-0
app/services/settings.rb
+17
-3
app/workers/push_worker.rb
+3
-4
No files found.
app/controllers/pushs_controller.rb
View file @
12ad5125
...
...
@@ -26,6 +26,7 @@ class PushsController < ApplicationController
param!
:igetui_opts
,
String
param!
:app_type
,
String
param!
:sync_push
,
String
param!
:device
,
String
,
required:
false
# optionals: 'android', 'ios'
igetui_opts
=
JSON
.
parse
(
params
[
:igetui_opts
])
rescue
{}
message
=
JSON
.
parse
(
params
[
:message
])
rescue
{}
...
...
@@ -33,15 +34,21 @@ class PushsController < ApplicationController
token
=
token_and_options
(
request
).
first
if
token
==
Token
.
token
(
params
[
:app_name
])
if
params
.
has_key?
(
:sync_push
)
Timeout
.
timeout
(
3
)
{
::
PushWorker
.
new
.
perform
(
device_ids_opts
,
message
,
igetui_opts
,
params
[
:app_type
])
}
timeout_seconds
=
$redis
.
get
(
'push_timeout'
).
to_i
if
timeout_seconds
>
0
Timeout
.
timeout
(
timeout_seconds
)
{
::
PushWorker
.
new
.
perform
(
device_ids_opts
,
message
,
igetui_opts
,
params
[
:app_type
],
device:
params
[
:device
])
}
else
::
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
])
::
PushWorker
.
perform_async
(
device_ids_opts
,
message
,
igetui_opts
,
params
[
:app_type
]
,
device:
params
[
:device
]
)
end
render
json:
{
code:
0
,
message:
'success'
,
describe:
'异步任务正在处理'
}
else
render
json:
{
code:
-
1
,
message:
'token 错误/过期'
}
end
end
end
app/services/push.rb
View file @
12ad5125
...
...
@@ -12,8 +12,8 @@ module Push
# xiaomi: [],
# huawei: []
# }
def
push
(
device_ids_opts
,
message
,
igetui_opts
=
{},
app_type
=
nil
)
Settings
.
platform
=
app_type
||
Settings
::
DEFAULT
def
push
(
device_ids_opts
,
message
,
igetui_opts
=
{},
app_type
=
nil
,
device:
nil
)
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
}
"
)
message
=
message
.
with_indifferent_access
igetui_opts
=
igetui_opts
.
with_indifferent_access
...
...
@@ -33,5 +33,14 @@ module Push
rescue
StandardError
=>
err
Push
::
Log
.
error
(
err
)
end
private
def
device_suffix
(
device
)
case
device
.
to_s
when
/android/i
then
'_android'
when
/ios/i
then
'_ios'
end
end
end
end
app/services/push/igetui/push.rb
View file @
12ad5125
...
...
@@ -49,6 +49,22 @@ module Push
)
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
@message
=
case
pusher_type
when
'push_message_to_single'
...
...
app/services/settings.rb
View file @
12ad5125
...
...
@@ -9,12 +9,27 @@ class Settings < Settingslogic
@platform
=
platform
if
PLATFORM
.
include?
platform
end
def
set_platform_device
(
platform
,
device_suffix:
''
)
if
PLATFORM
.
include?
(
platform
)
@platform
=
platform
end
@device_suffix
=
device_suffix
end
def
self
.
platform
@platform
||
DEFAULT
end
def
self
.
platform_with_device
"
#{
@platform
||
DEFAULT
}#{
@device_suffix
}
"
end
def
self
.
platform_settings
self
.
send
(
platform
)
if
Settings
[
platform_with_device
].
present?
self
.
send
(
platform_with_device
)
else
self
.
send
(
platform
)
end
end
end
\ No newline at end of file
end
app/workers/push_worker.rb
View file @
12ad5125
...
...
@@ -2,9 +2,9 @@ class PushWorker
include
Sidekiq
::
Worker
sidekiq_options
queue: :push
def
perform
(
device_ids_opts
,
message
,
igetui_opts
,
platform
=
nil
)
Push
.
push
(
device_ids_opts
,
message
,
igetui_opts
,
platform
)
def
perform
(
device_ids_opts
,
message
,
igetui_opts
,
platform
=
nil
,
device:
nil
)
Push
.
push
(
device_ids_opts
,
message
,
igetui_opts
,
platform
,
device:
device
)
rescue
StandardError
=>
e
ErrorLog
.
error
(
e
)
end
end
\ No newline at end of file
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