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
9f860ac4
Commit
9f860ac4
authored
Jan 10, 2020
by
liangyuzhe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
向下兼容
parent
baaabb06
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
74 additions
and
37 deletions
+74
-37
app/controllers/pushs_controller.rb
+38
-26
app/services/push_tool_client.rb
+34
-10
config/puma.rb
+1
-1
config/routes.rb
+1
-0
No files found.
app/controllers/pushs_controller.rb
View file @
9f860ac4
class
PushsController
<
ApplicationController
include
ActionController
::
HttpAuthentication
::
Token
# skip_before_action :verify_authenticity_token
def
token
param!
:app_name
,
String
,
required:
true
...
...
@@ -23,18 +22,16 @@ class PushsController < ApplicationController
param!
:app_type
,
String
param!
:sync_push
,
:boolean
param!
:user_id
,
String
,
required:
true
param!
:db_role
,
String
,
in:
%w(dev test staging production)
param!
:db_role
,
String
,
required:
true
,
in:
%w(dev test staging production)
igetui_opts
=
JSON
.
parse
(
params
[
:igetui_opts
])
rescue
{}
message
=
JSON
.
parse
(
params
[
:message
])
rescue
{}
db_role
=
fetch_db_role
db_role
=
params
[
:db_role
].
to_sym
user_device_exist
=
false
ActiveRecord
::
Base
.
connected_to
(
role:
db_role
)
do
user_device_exist
=
UserDevice
.
where
(
user_id:
params
[
:user_id
]).
exists?
byebug
stale?
(
last_modified:
UserDevice
.
where
(
user_id:
params
[
:user_id
]).
last
.
updated_at
)
end
unless
user_device_exist
...
...
@@ -43,15 +40,17 @@ class PushsController < ApplicationController
token_array
=
token_and_options
(
request
)
if
token_array
.
blank?
return
render
json:
{
code:
-
1
,
message:
'token错误'
}
return
render
json:
{
code:
40
1
,
message:
'token错误'
}
end
params
[
:sync_push
]
||=
false
if
validate_token
(
params
[
:app_name
],
token_array
.
first
)
push_sync
(
params
[
:sync_push
],
{
db_role:
db_role
,
user_ids:
Array
(
params
[
:user_id
]),
message:
message
,
app_type:
params
[
:app_type
],
igetui_opts:
igetui_opts
.
merge
(
pusher_type:
'push_message_to_single'
)})
render
json:
{
code:
0
,
message:
'success'
,
describe:
'异步任务正在处理'
}
else
render
json:
{
code:
-
1
,
message:
'token 错误/过期'
}
render
json:
{
code:
40
1
,
message:
'token 错误/过期'
}
end
end
...
...
@@ -62,7 +61,7 @@ class PushsController < ApplicationController
param!
:message
,
String
,
required:
true
param!
:igetui_opts
,
String
param!
:app_type
,
String
param!
:sync_push
,
String
param!
:sync_push
,
:boolean
param!
:user_ids
,
Array
,
required:
true
param!
:db_role
,
String
,
in:
%w(dev test staging production)
...
...
@@ -70,7 +69,7 @@ class PushsController < ApplicationController
message
=
JSON
.
parse
(
params
[
:message
])
rescue
{}
user_ids
=
params
[
:user_ids
]
rescue
[]
db_role
=
fetch_db_role
db_role
=
params
[
:db_role
].
to_sym
user_device_exist
=
false
ActiveRecord
::
Base
.
connected_to
(
role:
db_role
)
do
user_device_exist
=
UserDevice
.
where
(
user_id:
user_ids
).
exists?
...
...
@@ -81,19 +80,47 @@ class PushsController < ApplicationController
token_array
=
token_and_options
(
request
)
if
token_array
.
blank?
return
render
json:
{
code:
-
1
,
message:
'token错误'
}
return
render
json:
{
code:
40
1
,
message:
'token错误'
}
end
params
[
:sync_push
]
||=
false
if
validate_token
(
params
[
:app_name
],
token_array
.
first
)
push_sync
(
params
[
:sync_push
],
{
db_role:
db_role
,
user_ids:
user_ids
,
message:
message
,
app_type:
params
[
:app_type
],
igetui_opts:
igetui_opts
.
merge
(
pusher_type:
'push_message_to_list'
)})
render
json:
{
code:
0
,
message:
'success'
,
describe:
'异步任务正在处理'
}
else
render
json:
{
code:
-
1
,
message:
'token 错误/过期'
}
render
json:
{
code:
40
1
,
message:
'token 错误/过期'
}
end
end
def
push
param!
:app_name
,
String
,
required:
true
param!
:device_ids_opts
,
String
,
required:
true
param!
:message
,
String
,
required:
true
param!
:sync_push
,
:boolean
param!
:igetui_opts
,
String
param!
:app_type
,
String
igetui_opts
=
JSON
.
parse
(
params
[
:igetui_opts
])
rescue
{}
message
=
JSON
.
parse
(
params
[
:message
])
rescue
{}
device_ids_opts
=
JSON
.
parse
(
params
[
:device_ids_opts
])
rescue
{}
token_array
=
token_and_options
(
request
)
if
token_array
.
blank?
return
render
json:
{
code:
401
,
message:
'token错误'
}
end
if
validate_token
(
params
[
:app_name
],
token_array
.
first
)
params
[
:sync_push
]
||=
false
push_sync
(
params
[
:sync_push
],
{
device_ids_opts:
device_ids_opts
,
message:
message
,
app_type:
params
[
:app_type
],
igetui_opts:
igetui_opts
.
merge
(
pusher_type:
'push_message_to_list'
)})
render
json:
{
code:
0
,
message:
'success'
,
data:
{
remind:
"请使用新的api,此api近期将不再维护,请尽快迁移到新的api,新api地址 http://apidoc.weiwenjia.com/docs/internal-dev-api/internal-dev-api-1boq6ctdm8m57"
}}
else
render
json:
{
code:
401
,
message:
'token 错误/过期'
}
end
end
private
...
...
@@ -111,19 +138,4 @@ class PushsController < ApplicationController
::
PushWorker
.
perform_async
(
opts
)
end
end
def
fetch_db_role
return
params
[
:db_role
].
to_sym
if
params
[
:db_role
].
present?
case
request
.
host
when
'lxcrm-dev.weiwenjia.com'
,
'ik-dev.ikcrm.com'
:dev
when
'lxcrm-test.weiwenjia.com'
,
'ik-test.weiwenjia.com'
:test
when
'lxcrm-staging.weiwenjia.com'
,
'ik-staging.weiwenjia.com'
:staging
else
:production
end
end
end
app/services/push_tool_client.rb
View file @
9f860ac4
...
...
@@ -9,7 +9,37 @@ class PushToolClient
def
do_push
Settings
.
platform
=
@opts
[
:app_type
]
||
Settings
::
DEFAULT
push_device_collections
||=
{}
igetui_android_client_ids
,
igetui_ios_client_ids
,
xiaomi_client_ids
,
huawei_client_ids
=
fetch_client_ids
Igetui
::
Pusher
.
new
(
igetui_android_client_ids
,
@opts
.
merge
(
device_platform:
'android'
)).
perform
if
igetui_android_client_ids
.
present?
Igetui
::
Pusher
.
new
(
igetui_ios_client_ids
,
@opts
.
merge
(
device_platform:
'ios'
)).
perform
if
igetui_ios_client_ids
.
present?
#现在好像不用了
# Push::IgetuiIos.push(@push_collections[:igetui_ios], @opts) if @push_collections[:apns].present?
# Push::IgetuiAndroid.push(@push_collections[:igetui_android], @opts) if @push_collections[:apns].present?
Xiaomi
::
Pusher
.
new
(
xiaomi_client_ids
,
@opts
[
:message
]).
perform
if
xiaomi_client_ids
.
present?
Huawei
::
Pusher
.
new
(
huawei_client_ids
,
@opts
[
:message
]).
perform
if
huawei_client_ids
.
present?
end
def
fetch_client_ids
igetui_android_client_ids
=
igetui_ios_client_ids
=
xiaomi_client_ids
=
huawei_client_ids
=
[]
if
(
@opts
[
:device_ids_opts
].
is_a?
Hash
)
&&
@user_ids
.
blank?
push_devices
=
@opts
[
:device_ids_opts
].
keys
.
map
(
&
:to_s
)
if
push_devices
.
include?
"igetui"
igetui_android_client_ids
=
@opts
[
:device_ids_opts
][
:igetui
]
if
@opts
[
:igetui_opts
][
:device_platform
]
==
'android'
igetui_ios_client_ids
=
@opts
[
:device_ids_opts
][
:igetui
]
if
@opts
[
:igetui_opts
][
:device_platform
]
==
'ios'
end
huawei_client_ids
=
@opts
[
:device_ids_opts
][
:huawei
]
if
push_devices
.
include?
"huawei"
xiaomi_client_ids
=
@opts
[
:device_ids_opts
][
:xiaomi
]
if
push_devices
.
include?
"xiaomi"
if
@opts
[
:igetui_opts
].
is_a?
Hash
@opts
[
:igetui_opts
][
:device_platform
]
end
else
push_device_collections
=
{}
ActiveRecord
::
Base
.
connected_to
(
role:
@opt
[
:db_role
].
to_sym
)
do
push_device_collections
=
UserDevice
.
where
(
user_id:
@user_ids
).
group_by
(
&
:platform
)
...
...
@@ -21,17 +51,10 @@ class PushToolClient
igetui_ios_client_ids
=
igetui_push_device_collections
[
'ios'
].
map
(
&
:client_id
)
if
igetui_push_device_collections
[
'ios'
].
is_a?
Array
end
Igetui
::
Pusher
.
new
(
igetui_android_client_ids
,
@opts
.
merge
(
device_platform:
'android'
)).
perform
if
igetui_android_client_ids
.
present?
Igetui
::
Pusher
.
new
(
igetui_ios_client_ids
,
@opts
.
merge
(
device_platform:
'ios'
)).
perform
if
igetui_ios_client_ids
.
present?
#现在好像不用了
# Push::IgetuiIos.push(@push_collections[:igetui_ios], @opts) if @push_collections[:apns].present?
# Push::IgetuiAndroid.push(@push_collections[:igetui_android], @opts) if @push_collections[:apns].present?
xiaomi_client_ids
=
push_device_collections
[
'xiaomi'
].
map
(
&
:client_id
)
if
push_device_collections
[
'xiaomi'
].
is_a?
Array
huawei_client_ids
=
push_device_collections
[
'huawei'
].
map
(
&
:client_id
)
if
push_device_collections
[
'huawei'
].
is_a?
Array
end
Xiaomi
::
Pusher
.
new
(
xiaomi_client_ids
,
@opts
[
:message
]).
perform
if
xiaomi_client_ids
.
present?
Huawei
::
Pusher
.
new
(
huawei_client_ids
,
@opts
[
:message
]).
perform
if
huawei_client_ids
.
present?
[
igetui_android_client_ids
,
igetui_ios_client_ids
,
xiaomi_client_ids
,
huawei_client_ids
]
end
end
\ No newline at end of file
config/puma.rb
View file @
9f860ac4
...
...
@@ -3,7 +3,7 @@ unless ENV['RAILS_ENV'] == 'development'
deploy_config
=
JSON
.
parse
(
file
)
port
deploy_config
[
'http_port'
]
environment
'production'
workers
2
workers
4
threads
0
,
16
bind
"unix://
#{
deploy_config
[
'deploy_to'
]
}
/shared/tmp/sockets/push-puma.sock"
pidfile
"
#{
deploy_config
[
'deploy_to'
]
}
/shared/tmp/pids/puma.pid"
...
...
config/routes.rb
View file @
9f860ac4
...
...
@@ -3,6 +3,7 @@ Rails.application.routes.draw do
post
'api/v1/token'
,
to:
'pushs#token'
post
'api/v1/single'
,
to:
'pushs#single'
post
'api/v1/batch'
,
to:
'pushs#batch'
post
'api/v1/push'
,
to:
'pushs#push'
require
'sidekiq/web'
...
...
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