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
d1cc9b5e
Commit
d1cc9b5e
authored
Jun 26, 2019
by
zmj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改添加支持多平台
parent
69595ea1
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
100 additions
and
36 deletions
+100
-36
.gitignore
+2
-0
app/controllers/pushs_controller.rb
+2
-1
app/services/push.rb
+3
-2
app/services/push/huawei.rb
+3
-3
app/services/push/igetui/push.rb
+4
-4
app/services/push/xiaomi.rb
+2
-2
app/services/settings.rb
+17
-0
app/workers/push_worker.rb
+2
-2
config/settings.yml.example
+65
-22
No files found.
.gitignore
View file @
d1cc9b5e
...
...
@@ -32,6 +32,7 @@
/config/push.yml
/config/settings.yml
/config/app.yml
/config/puma.rb.example
# Ignore master key for decrypting credentials and more.
/config/master.key
\ No newline at end of file
app/controllers/pushs_controller.rb
View file @
d1cc9b5e
...
...
@@ -24,13 +24,14 @@ class PushsController < ApplicationController
param!
:device_ids_opts
,
String
,
required:
true
param!
:message
,
String
,
required:
true
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
=
token_and_options
(
request
).
first
if
token
==
Token
.
token
(
params
[
:app_name
])
::
PushWorker
.
perform_async
(
device_ids_opts
,
message
,
igetui_opts
)
::
PushWorker
.
perform_async
(
device_ids_opts
,
message
,
igetui_opts
,
params
[
:app_type
]
)
render
json:
{
code:
0
,
message:
'success'
,
describe:
'异步任务正在处理'
}
else
render
json:
{
code:
-
1
,
message:
'token 错误/过期'
}
...
...
app/services/push.rb
View file @
d1cc9b5e
...
...
@@ -12,8 +12,9 @@ module Push
# 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
}
"
)
def
push
(
device_ids_opts
,
message
,
igetui_opts
=
{},
app_type
=
nil
)
Settings
.
platform
=
app_type
if
app_type
.
present?
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
# igetui
...
...
app/services/push/huawei.rb
View file @
d1cc9b5e
...
...
@@ -22,7 +22,7 @@ module Push
nsp_ctx
=
{
ver:
'1'
,
appId:
Settings
.
huawei
[
'app_id'
]
appId:
Settings
.
platform_settings
.
huawei
[
'app_id'
]
}
url
=
PUSH_URL
+
"?nsp_ctx=
#{
CGI
::
escape
(
nsp_ctx
.
to_json
)
}
"
post
(
url
,
body
)
...
...
@@ -67,8 +67,8 @@ module Push
def
req_token
body
=
{
grant_type:
'client_credentials'
,
client_id:
Settings
.
huawei
[
'app_id'
],
client_secret:
Settings
.
huawei
[
'app_secret'
]
client_id:
Settings
.
platform_settings
.
huawei
[
'app_id'
],
client_secret:
Settings
.
platform_settings
.
huawei
[
'app_secret'
]
}
post
(
TOKEN_URL
,
body
)
end
...
...
app/services/push/igetui/push.rb
View file @
d1cc9b5e
...
...
@@ -43,9 +43,9 @@ module Push
def
pusher
@pusher
||=
IGeTui
.
pusher
(
Settings
.
igetui
[
'app_id'
],
Settings
.
igetui
[
'app_key'
],
Settings
.
igetui
[
'master_secret'
]
Settings
.
platform_settings
.
igetui
[
'app_id'
],
Settings
.
platform_settings
.
igetui
[
'app_key'
],
Settings
.
platform_settings
.
igetui
[
'master_secret'
]
)
end
...
...
@@ -64,7 +64,7 @@ module Push
@template
=
"IGeTui::
#{
template_type
}
"
.
constantize
.
new
case
template_type
when
'NotificationTemplate'
,
'NotyPopLoadTemplate'
,
'LinkTemplate'
@template_data
.
reverse_merge!
(
Settings
.
igetui
[
'template_base'
])
@template_data
.
reverse_merge!
(
Settings
.
platform_settings
.
igetui
[
'template_base'
])
@template_data
.
each
do
|
k
,
v
|
@template
.
send
(
"
#{
k
}
="
,
v
)
...
...
app/services/push/xiaomi.rb
View file @
d1cc9b5e
...
...
@@ -30,7 +30,7 @@ module Push
# 0 表示通知栏消息, 1 表示透传消息
def
config
{
restricted_package_name:
Settings
.
xiaomi
[
'package_name'
],
restricted_package_name:
Settings
.
platform_settings
.
xiaomi
[
'package_name'
],
pass_through:
1
,
title:
'xiaomi push'
,
description:
'xiaomi push'
,
...
...
@@ -42,7 +42,7 @@ module Push
response
=
HTTParty
.
post
(
PUSH_URL
,
query:
params
,
headers:
{
'Accept'
=>
'application/json;'
,
"Authorization"
:
"key=
#{
Settings
.
xiaomi
[
'app_secret'
]
}
"
"Authorization"
:
"key=
#{
Settings
.
platform_settings
.
xiaomi
[
'app_secret'
]
}
"
},
timeout:
5
)
Push
::
Log
.
info
(
"xiaomi_push:
\n
url:
#{
PUSH_URL
}
\n
params:
#{
params
}
\n
response:
#{
response
}
"
)
...
...
app/services/settings.rb
View file @
d1cc9b5e
class
Settings
<
Settingslogic
source
"
#{
Rails
.
root
}
/config/settings.yml"
namespace
Rails
.
env
PLATFORM
=
%w[ik_duli lx_duli lx_yun]
DEFAULT
=
'ik_duli'
.
freeze
def
self
.
platform
=
(
platform
)
@platform
=
platform
if
PLATFORM
.
include?
platform
end
def
self
.
platform
@platform
||
DEFAULT
end
def
self
.
platform_settings
self
.
send
(
platform
)
end
end
\ No newline at end of file
app/workers/push_worker.rb
View file @
d1cc9b5e
...
...
@@ -2,8 +2,8 @@ class PushWorker
include
Sidekiq
::
Worker
sidekiq_options
queue: :push
def
perform
(
device_ids_opts
,
message
,
igetui_opts
)
Push
.
push
(
device_ids_opts
,
message
,
igetui_opts
)
def
perform
(
device_ids_opts
,
message
,
igetui_opts
,
platform
=
nil
)
Push
.
push
(
device_ids_opts
,
message
,
igetui_opts
,
platform
)
rescue
StandardError
=>
e
ErrorLog
.
error
(
e
)
end
...
...
config/settings.yml.example
View file @
d1cc9b5e
...
...
@@ -6,31 +6,74 @@ defaults: &defaults
job_db: 1
cache_db: 2
timeout: 5000
igetui:
app_id: "Xz8goKcReVA530Skeex4G6"
app_key: "uqesFB0v4u7lQP5BnOpwy9"
app_secret: "epBoJk7Z4bAOk1XZIzSHl7"
master_secret: "NlQSSDyPjR7ElA6YYLtgI9"
template_base:
logo: "ik_logo.png"
logo_url: "http://www.ikcrm.com/assets/img/ik_logo.png"
title: ""
text: ""
huawei:
app_id: "10471990"
app_secret: "ocr55sr7xj88oky93xlv0pkuuykx060j"
xiaomi:
app_id: '2882303761517266621'
app_key: '5881726643621'
app_secret: 'tQWrpyjb+47hdH/MSmfMGQ==' # 请求的header中用到了
package_name: 'com.vcooline.aike'
crm:
app_id: 'ba9936cf01aaf888'
app_secret: 'cd855e8ea1ff27034425e502d974eb3a'
ik_duli:
igetui:
app_id: "Xz8goKcReVA530Skeex4G6"
app_key: "uqesFB0v4u7lQP5BnOpwy9"
app_secret: "epBoJk7Z4bAOk1XZIzSHl7"
master_secret: "NlQSSDyPjR7ElA6YYLtgI9"
template_base:
logo: "ik_logo.png"
logo_url: "http://www.ikcrm.com/assets/img/ik_logo.png"
title: ""
text: ""
huawei:
app_id: "10471990"
app_secret: "ocr55sr7xj88oky93xlv0pkuuykx060j"
xiaomi:
app_id: '2882303761517266621'
app_key: '5881726643621'
app_secret: 'tQWrpyjb+47hdH/MSmfMGQ==' # 请求的header中用到了
package_name: 'com.vcooline.aike'
lx_duli:
igetui:
app_id: '0Lb0X5wR8mA8zvWKEvSOt5'
app_key: 'ydenLcgxCMA5ASn0fY4zR4'
app_secret: 'ITYqKmAY3z8C4f5tapkux4'
master_secret: 'bbG9qFnBBc6f9NcZ4ed5n1'
template_base:
logo: "ik_logo.png"
logo_url: "http://www.ikcrm.com/assets/img/ik_logo.png"
title: ""
text: ""
huawei:
app_id: '100718719'
app_secret: '184cba3098abcc4fd38f834be2c876bb'
xiaomi:
app_id: '2882303761518023796'
app_key: '5231802388796'
app_secret: 'P3oxeBrHDPnBQ4s3HrrgFg=='
package_name: 'com.lxcrm.aike'
lx_yun:
igetui:
app_id: 'w4SrLQgujP8Kq0nrhgs6Z6'
app_key: '0J8wXewzYk7CepWIgWq9WA'
app_secret: '9LRUkS5rDvAo0DcCAvJp49'
master_secret: 'C6MYYIInS3AFAHaBbvQER2'
template_base:
logo: "ik_logo.png"
logo_url: "http://www.ikcrm.com/assets/img/ik_logo.png"
title: ""
text: ""
xiaomi:
app_id: '2882303761518026475'
app_key: '5881802642475'
app_secret: 'W9xzBYu3xfd3+DsF1WKd4Q=='
package_name: 'com.lixiaoyun.aike'
huawei:
app_id: 'com.lixiaoyun.aike'
app_secret: 'd9afda45c37b604fac74885ad67efa6a1c47b552910fbc6e180389d6e59c2b82'
development:
<<: *defaults
...
...
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