Commit 1f6f4b9b by zmj

修改推送服务,按照机型分别推送

parent 2f365c2c
......@@ -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 错误/过期'}
......
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
......
......@@ -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 result: #{result}")
::Push::Log.info("igetui_push: \n template_data: #{template_data}\n opts: #{opts}\n user_device_ids: #{user_device_ids}\n response: #{result}")
end
end
end
......
......@@ -2,8 +2,8 @@ class PushWorker
include Sidekiq::Worker
sidekiq_options queue: :push
def perform(user_device_ids, message, igetui_opts)
Push.push(user_device_ids, message, igetui_opts)
def perform(device_ids_opts, message, igetui_opts)
Push.push(device_ids_opts, message, igetui_opts)
rescue StandardError => e
ErrorLog.error(e)
end
......
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