Commit f13bcb4c by yuzixun

Merge branch 'master' into release

parents a14652b3 5b2d80ce
......@@ -33,6 +33,7 @@
/config/push.yml
/config/settings.yml
/config/app.yml
/config/database.yml
/config/puma.rb.example
# Ignore master key for decrypting credentials and more.
......
......@@ -7,7 +7,7 @@ ruby '2.6.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.2', '>= 5.2.2.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
gem 'mysql2', '>= 0.3.18', '< 0.5'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
......
......@@ -133,6 +133,7 @@ GEM
minitest (5.11.3)
msgpack (1.2.10)
multi_xml (0.6.0)
mysql2 (0.4.10)
net-scp (1.2.1)
net-ssh (>= 2.6.5)
net-ssh (5.1.0)
......@@ -228,7 +229,6 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.4.1)
sshkit (1.18.0)
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
......@@ -272,6 +272,7 @@ DEPENDENCIES
igetui-ruby
jbuilder (~> 2.5)
listen (>= 3.0.5, < 3.2)
mysql2 (>= 0.3.18, < 0.5)
puma (~> 3.11)
rails (~> 5.2.2, >= 5.2.2.1)
rails_param (~> 0.10.2)
......@@ -282,7 +283,6 @@ DEPENDENCIES
sidekiq (~> 4.1, >= 4.1.2)
spring
spring-watcher-listen (~> 2.0.0)
sqlite3
turbolinks (~> 5)
tzinfo-data
uglifier (>= 1.3.0)
......@@ -292,4 +292,4 @@ RUBY VERSION
ruby 2.6.0p0
BUNDLED WITH
1.17.2
1.17.3
......@@ -32,6 +32,9 @@ class PushsController < ApplicationController
device_ids_opts = JSON.parse(params[:device_ids_opts]) rescue {}
token = token_and_options(request).first
if token == Token.token(params[:app_name])
# 写入记录
NotificationStatistic.create_by_params(igetui_opts, message, device_ids_opts, params[:app_type])
if params.has_key?(:sync_push)
timeout_seconds = $redis.get('push_timeout').to_i
if timeout_seconds > 0
......@@ -49,4 +52,17 @@ class PushsController < ApplicationController
render json: { code: -1, message: 'token 错误/过期'}
end
end
def received
param! :notification_id, Integer, required: true
param! :user_id, Integer, required: true
param! :app_type, String, required: true
param! :device_model, String, required: true
notification_stat = NotificationStatistic.find_by(user_id: params[:user_id], notification_id: params[:notification_id], app_type: params[:app_type])
notification_stat.update(device_model: params[:device_model], is_received: true) if notification_stat.present?
render json: { code: 0, message: "success" }
end
end
class NotificationStatistic < ApplicationRecord
# 当前app端传递的platform的值:
# android: igetui, xiaomi, huawei
# iso: igetui 目前还不清楚为啥不用apns,暂时不修改
enum platform: %i[igetui apns xiaomi huawei]
enum device_platform: %i[ios android]
# 用于区分当前的应用,为了推送准备, 因为推送需要根据不同的应用使用不同的 id,secret等。
enum app_type: %i[ik_duli lx_duli lx_yun aike_yun]
def self.create_by_params(igetui_opts, message, device_ids_opts, app_type)
igetui_opts = igetui_opts.with_indifferent_access
message = message.with_indifferent_access
device_ids_opts = device_ids_opts.with_indifferent_access
device_ids_opts.each do |platform, client_ids|
client_ids.each do |client_id|
next if message[:id].blank?
NotificationStatistic.create(
organization_id: igetui_opts[:organization_id],
user_id: message[:user_id] || igetui_opts[:user_id],
notification_id: message[:id],
client_id: client_id,
platform: platform,
device_platform: igetui_opts[:device_platform],
app_type: app_type,
ip: igetui_opts[:ip],
)
end
end
rescue => e
Rails.logger.info "exception is #{e}"
e.backtrace.each { |l| Rails.logger.info l }
end
end
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
default: &default
adapter: mysql2
encoding: utf8
pool: 3
host: rm-m5ef10gzq1n5e7b9abo.mysql.rds.aliyuncs.com
username: crm_dev
password: 4LwSJlWiM9Krlb8g
development:
<<: *default
database: crm_dev
production:
<<: *default
database: crm_dev
\ No newline at end of file
......@@ -5,7 +5,7 @@ set :rvm_type, :auto # Defaults to: :auto
set :rvm_ruby_version, '2.6.0'
set :god_sidekiq_group, 'push_service'
# 当前服务器有app 这个角色。
# 当前服务器有app 这个角色。
# gem capistrano-sidekiq 默认值 set :sidekiq_roles, fetch(:sidekiq_role, :app)
# 因此会造成执行cap sidekiq:start,但是生产环境因为使用了god,不需要执行这个任务
set :sidekiq_roles, 'sidekiq' #生产环境没有这个角色。
......@@ -17,6 +17,7 @@ set :linked_files, %w[
config/master.key
config/settings.yml
config/puma.rb
config/database.yml
]
set :linked_dirs, %w[
......
......@@ -2,6 +2,7 @@ Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
post 'api/v1/token', to: 'pushs#token'
post 'api/v1/push', to: 'pushs#push'
put 'api/v1/received', to: 'pushs#received'
require 'sidekiq/web'
mount Sidekiq::Web => '/sidekiq'
......
class CreateNotificationStatistics < ActiveRecord::Migration[5.2]
def change
create_table :notification_statistics do |t|
t.integer :organization_id, index: true, comment: "关联公司"
t.integer :user_id, index: true, comment: "关联用户" # user id
t.integer :notification_id, index: true, comment: "关联通知ID" # id
t.boolean :is_received, default: false, comment: "是否收到" # APP 上报
t.string :client_id, comment: "个推ClientID" # 接口调用
t.integer :platform, comment: "推送平台" #
t.integer :device_platform, comment: "系统" # device_platform
t.integer :app_type, comment: "版本" # 调用接口时 app_type
t.string :device_model, comment: "设备型号" # APP 上报
t.string :ip, comment: "IP地址" # 可能拿不到
t.datetime :created_at
t.datetime :updated_at
t.timestamps null: false
end
end
end
This source diff could not be displayed because it is too large. You can view the blob instead.
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