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
1f6f4b9b
Commit
1f6f4b9b
authored
May 28, 2019
by
zmj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改推送服务,按照机型分别推送
parent
2f365c2c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
12 deletions
+20
-12
app/controllers/pushs_controller.rb
+4
-3
app/services/push.rb
+13
-6
app/services/push/igetui.rb
+1
-1
app/workers/push_worker.rb
+2
-2
No files found.
app/controllers/pushs_controller.rb
View file @
1f6f4b9b
...
...
@@ -21,15 +21,16 @@ class PushsController < ApplicationController
# igetui_opts 个推推送的额外选项
def
push
param!
:app_name
,
String
,
required:
true
param!
:
user_device_ids
,
Array
,
required:
true
param!
:
device_ids_opts
,
String
,
required:
true
param!
:message
,
String
,
required:
true
param!
:igetui_opts
,
String
igetui_opts
=
JSON
.
parse
(
params
[
:igetui_opts
])
rescue
{}
message
=
JSON
.
parse
(
params
[
:message
])
message
=
JSON
.
parse
(
params
[
:message
])
rescue
{}
device_ids_opts
=
JSON
.
parse
(
params
[
:device_ids_opts
])
rescue
{}
token
=
token_and_options
(
request
).
first
if
token
==
Token
.
token
(
params
[
:app_name
])
::
PushWorker
.
perform_async
(
params
[
:user_device_ids
]
,
message
,
igetui_opts
)
::
PushWorker
.
perform_async
(
device_ids_opts
,
message
,
igetui_opts
)
render
json:
{
code:
0
,
message:
'success'
,
describe:
'异步任务正在处理'
}
else
render
json:
{
code:
-
1
,
message:
'token 错误/过期'
}
...
...
app/services/push.rb
View file @
1f6f4b9b
module
Push
class
<<
self
# 调用推送服务,推送信息
# user_device_ids, 用户设备信息,可以是字符串数组,也可以是字符串。
# message 要推送的具体信息
# opts 是hash类型,主要是一些其他的信息。
# 由于历史遗留问题,封装的不够好,这里主要用来处理个推的一些参数。
# 目前华为推送,小米推送不会用到这里的信息。
def
push
(
user_device_ids
,
message
,
igetui_opts
=
{})
Push
::
Log
.
info
(
"push: user_device_ids:
#{
user_device_ids
}
, message:
#{
message
}
, igetui_opts:
#{
igetui_opts
}
"
)
# device_ids_opts, 用户设备信息是hash数组。
# device_ids_opts = {
# igetui: [],
# apns: [],
# xiaomi: [],
# huawei: []
# }
def
push
(
device_ids_opts
,
message
,
igetui_opts
=
{})
Push
::
Log
.
info
(
"*************** push_service ***************:
\n
device_ids_opts:
#{
device_ids_opts
}
, message:
#{
message
}
, igetui_opts:
#{
igetui_opts
}
"
)
message
=
message
.
with_indifferent_access
igetui_opts
=
igetui_opts
.
with_indifferent_access
# igetui
Push
::
Igetui
.
push
(
user_device_ids
,
message
,
igetui_opts
)
Push
::
Igetui
.
push
(
device_ids_opts
[
'igetui'
],
message
,
igetui_opts
)
if
device_ids_opts
[
'igetui'
].
present?
Push
::
Igetui
.
push
(
device_ids_opts
[
'apns'
],
message
,
igetui_opts
)
if
device_ids_opts
[
'apns'
].
present?
# xiaomi
# https://dev.mi.com/console/doc/detail?pId=1163 文档中心
Push
::
Xiaomi
.
push
(
user_device_ids
,
message
)
Push
::
Xiaomi
.
push
(
device_ids_opts
[
'xiaomi'
],
message
)
if
device_ids_opts
[
'xiaomi'
].
present?
# huawei
# https://developer.huawei.com/consumer/cn/service/hms/catalog/huaweipush_agent.html?page=hmssdk_huaweipush_api_reference_agent_s1 接入文档
Push
::
Huawei
.
push
(
user_device_ids
,
message
)
Push
::
Huawei
.
push
(
device_ids_opts
[
'huawei'
],
message
)
if
device_ids_opts
[
'huawei'
].
present?
# etc
rescue
StandardError
=>
err
...
...
app/services/push/igetui.rb
View file @
1f6f4b9b
...
...
@@ -71,7 +71,7 @@ module Push
opts
=
HashWithIndifferentAccess
.
new
(
opts
)
igetui
=
Igetui
::
Push
.
new
(
template_data
,
opts
)
result
=
igetui
.
push_message_to
(
user_device_ids
)
::
Push
::
Log
.
info
(
"igetui_push:
\n
template_data:
#{
template_data
}
\n
opts:
#{
opts
}
\n
user_device_ids:
#{
user_device_ids
}
\n
res
ult
:
#{
result
}
"
)
::
Push
::
Log
.
info
(
"igetui_push:
\n
template_data:
#{
template_data
}
\n
opts:
#{
opts
}
\n
user_device_ids:
#{
user_device_ids
}
\n
res
ponse
:
#{
result
}
"
)
end
end
end
...
...
app/workers/push_worker.rb
View file @
1f6f4b9b
...
...
@@ -2,8 +2,8 @@ class PushWorker
include
Sidekiq
::
Worker
sidekiq_options
queue: :push
def
perform
(
user_device_id
s
,
message
,
igetui_opts
)
Push
.
push
(
user_device_id
s
,
message
,
igetui_opts
)
def
perform
(
device_ids_opt
s
,
message
,
igetui_opts
)
Push
.
push
(
device_ids_opt
s
,
message
,
igetui_opts
)
rescue
StandardError
=>
e
ErrorLog
.
error
(
e
)
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