Commit 99849644 by zmj

修改添加支持多平台

fix 默认值的bug

处理华为token 异常问题
parent 69595ea1
......@@ -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
......@@ -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 错误/过期'}
......
......@@ -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 || Settings::DEFAULT
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
......
......@@ -11,8 +11,13 @@ module Push
def push(device_tokens, message)
handle_token_res if access_token.blank?
device_tokens.each_slice(BATCH_PUSH_MAX) do |device_token_array|
res = res_push(message, device_token_array)
# 容错处理,华为的token异常问题,重新获取发送。
if res['code'] == '80300002'
handle_token_res
res_push(message, device_token_array)
end
end
rescue StandardError => err
Push::Log.error(err)
end
......@@ -22,7 +27,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 +72,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
......
......@@ -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)
......
......@@ -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}")
......
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
......@@ -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
......
......@@ -6,7 +6,10 @@ defaults: &defaults
job_db: 1
cache_db: 2
timeout: 5000
crm:
app_id: 'ba9936cf01aaf888'
app_secret: 'cd855e8ea1ff27034425e502d974eb3a'
ik_duli:
igetui:
app_id: "Xz8goKcReVA530Skeex4G6"
app_key: "uqesFB0v4u7lQP5BnOpwy9"
......@@ -28,9 +31,49 @@ defaults: &defaults
app_secret: 'tQWrpyjb+47hdH/MSmfMGQ==' # 请求的header中用到了
package_name: 'com.vcooline.aike'
crm:
app_id: 'ba9936cf01aaf888'
app_secret: 'cd855e8ea1ff27034425e502d974eb3a'
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: '100860035'
app_secret: 'd9afda45c37b604fac74885ad67efa6a1c47b552910fbc6e180389d6e59c2b82'
development:
<<: *defaults
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment