From d97ced41403bad205bd515344f60195b156fac58 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Wed, 9 Oct 2019 15:16:28 +0800 Subject: [PATCH 1/4] modify wechat js sign --- .../wechats/js_sdk_signatures_controller.rb | 6 +++--- app/libs/wechat.rb | 2 ++ .../{util/wechat_store.rb => wechat/client.rb} | 8 +++----- app/libs/wechat/error.rb | 14 ++++++++++++++ .../{util/wechat.rb => wechat/official_account.rb} | 14 +++++--------- .../{util_wechat_init.rb => wechat_init.rb} | 4 ++-- 6 files changed, 29 insertions(+), 19 deletions(-) create mode 100644 app/libs/wechat.rb rename app/libs/{util/wechat_store.rb => wechat/client.rb} (92%) create mode 100644 app/libs/wechat/error.rb rename app/libs/{util/wechat.rb => wechat/official_account.rb} (58%) rename config/initializers/{util_wechat_init.rb => wechat_init.rb} (79%) diff --git a/app/controllers/wechats/js_sdk_signatures_controller.rb b/app/controllers/wechats/js_sdk_signatures_controller.rb index f6a01b0e2..4ed1680b0 100644 --- a/app/controllers/wechats/js_sdk_signatures_controller.rb +++ b/app/controllers/wechats/js_sdk_signatures_controller.rb @@ -2,10 +2,10 @@ class Wechats::JsSdkSignaturesController < ApplicationController def create timestamp = Time.now.to_i noncestr = ('A'..'z').to_a.sample(8).join - signature = Util::Wechat.js_sdk_signature(params[:url], noncestr, timestamp) + signature = Wechat::OfficialAccount.js_sdk_signature(params[:url], noncestr, timestamp) - render_ok(appid: Util::Wechat.appid, timestamp: timestamp, noncestr: noncestr, signature: signature) - rescue Util::WechatStore::Error => ex + render_ok(appid: Wechat::OfficialAccount.appid, timestamp: timestamp, noncestr: noncestr, signature: signature) + rescue Wechat::Error => ex render_error(ex.message) end end \ No newline at end of file diff --git a/app/libs/wechat.rb b/app/libs/wechat.rb new file mode 100644 index 000000000..68e2c06b8 --- /dev/null +++ b/app/libs/wechat.rb @@ -0,0 +1,2 @@ +module Wechat +end \ No newline at end of file diff --git a/app/libs/util/wechat_store.rb b/app/libs/wechat/client.rb similarity index 92% rename from app/libs/util/wechat_store.rb rename to app/libs/wechat/client.rb index a6f3ac76a..0d34b9dda 100644 --- a/app/libs/util/wechat_store.rb +++ b/app/libs/wechat/client.rb @@ -1,8 +1,6 @@ -class Util::WechatStore +class Wechat::Client BASE_SITE = 'https://api.weixin.qq.com'.freeze - Error = Class.new(StandardError) - attr_reader :appid, :secret def initialize(appid, secret) @@ -60,11 +58,11 @@ class Util::WechatStore Rails.logger.error("[wechat] response:#{response.status} #{result.inspect}") if response.status != 200 - raise Error, result.inspect + raise Wechat::Error.parse(result) end if result['errcode'].present? && result['errcode'].to_i.nonzero? - raise Error, result.inspect + raise Wechat::Error.parse(result) end result diff --git a/app/libs/wechat/error.rb b/app/libs/wechat/error.rb new file mode 100644 index 000000000..f693fb41b --- /dev/null +++ b/app/libs/wechat/error.rb @@ -0,0 +1,14 @@ +class Wechat::Error < StandardError + attr_reader :code + + def initialize(code, message) + super message + @code = code + end + + class << self + def parse(result) + new(result['errcode'], result['errmsg']) + end + end +end \ No newline at end of file diff --git a/app/libs/util/wechat.rb b/app/libs/wechat/official_account.rb similarity index 58% rename from app/libs/util/wechat.rb rename to app/libs/wechat/official_account.rb index cb7b9044d..320fbdba3 100644 --- a/app/libs/util/wechat.rb +++ b/app/libs/wechat/official_account.rb @@ -1,8 +1,4 @@ -module Util::Wechat - BASE_SITE = 'https://api.weixin.qq.com'.freeze - - Error = Class.new(StandardError) - +class Wechat::OfficialAccount class << self attr_accessor :appid, :secret @@ -13,15 +9,15 @@ module Util::Wechat end def access_token - wechat_store.access_token + client.access_token end def jsapi_ticket - wechat_store.jsapi_ticket + client.jsapi_ticket end - def wechat_store - @_wechat_store ||= ::Util::WechatStore.new(appid, secret) + def client + @_client ||= Wechat::Client.new(appid, secret) end end end \ No newline at end of file diff --git a/config/initializers/util_wechat_init.rb b/config/initializers/wechat_init.rb similarity index 79% rename from config/initializers/util_wechat_init.rb rename to config/initializers/wechat_init.rb index cb39afcaf..946e5f638 100644 --- a/config/initializers/util_wechat_init.rb +++ b/config/initializers/wechat_init.rb @@ -12,5 +12,5 @@ rescue => ex wechat_config = {} end -Util::Wechat.appid = wechat_config['appid'] -Util::Wechat.secret = wechat_config['secret'] +Wechat::OfficialAccount.appid = wechat_config['appid'] +Wechat::OfficialAccount.secret = wechat_config['secret'] From 2eb3259cb7cc9837d48c5f20dc9cd52af6c531a2 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Wed, 9 Oct 2019 15:22:21 +0800 Subject: [PATCH 2/4] ecs: modify api --- .../ecs/course_targets_controller.rb | 4 +-- .../with_achievement_methods.json.jbuilder | 32 ++++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/app/controllers/ecs/course_targets_controller.rb b/app/controllers/ecs/course_targets_controller.rb index e5ac4b36e..bcd09f64a 100644 --- a/app/controllers/ecs/course_targets_controller.rb +++ b/app/controllers/ecs/course_targets_controller.rb @@ -20,8 +20,8 @@ class Ecs::CourseTargetsController < Ecs::CourseBaseController def with_achievement_methods @course_targets = current_course.ec_course_targets - .includes(:ec_graduation_subitems, - ec_course_achievement_methods: [:ec_course_evaluation, :ec_course_evaluation_subitems]) + .includes(ec_course_achievement_methods: + [:ec_course_evaluation, ec_achievement_evaluation_relates: :ec_course_evaluation_subitem]) end private diff --git a/app/views/ecs/course_targets/with_achievement_methods.json.jbuilder b/app/views/ecs/course_targets/with_achievement_methods.json.jbuilder index 689504ec3..02a4efc6e 100644 --- a/app/views/ecs/course_targets/with_achievement_methods.json.jbuilder +++ b/app/views/ecs/course_targets/with_achievement_methods.json.jbuilder @@ -1,2 +1,32 @@ +json.course_targets @course_targets, + partial: 'ecs/course_targets/shared/ec_course_target_with_achievement_methods', + as: :ec_course_target +json.course_targets do + json.array! @course_targets do |course_target| + json.extract! course_target, :id, :position, :content -json.course_targets @course_targets, partial: 'ecs/course_targets/shared/ec_course_target_with_achievement_methods', as: :ec_course_target + json.course_achievement_methods do + json.array! course_target.ec_course_achievement_methods do |achievement_method| + evaluation = achievement_method.ec_course_evaluation + json.extract! achievement_method, :id, :score, :percentage + + json.course_evaluation do + json.partial! 'ecs/course_evaluations/shared/ec_course_evaluation_only', ec_course_evaluation: evaluation + end + + json.course_evaluation_relates do + json.array! achievement_method.ec_achievement_evaluation_relates do |relate| + json.extract! relate, :id, :position, :ec_course_evaluation_subitem_id + + subitem = relate.ec_course_evaluation_subitem + if evaluation.is_course_type? + json.name subitem&.name + else + json.name subitem&.name ? "#{evaluation.name}(#{relate.position}):#{subitem&.name}" : "#{evaluation.name}(#{relate.position})" + end + end + end + end + end + end +end \ No newline at end of file From 0f148ba145c23f8f31061a775a7c8ec9a0a00f9a Mon Sep 17 00:00:00 2001 From: p31729568 Date: Wed, 9 Oct 2019 15:28:50 +0800 Subject: [PATCH 3/4] ecs: fix --- .../ecs/course_targets/with_achievement_methods.json.jbuilder | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/views/ecs/course_targets/with_achievement_methods.json.jbuilder b/app/views/ecs/course_targets/with_achievement_methods.json.jbuilder index 02a4efc6e..210151499 100644 --- a/app/views/ecs/course_targets/with_achievement_methods.json.jbuilder +++ b/app/views/ecs/course_targets/with_achievement_methods.json.jbuilder @@ -1,6 +1,3 @@ -json.course_targets @course_targets, - partial: 'ecs/course_targets/shared/ec_course_target_with_achievement_methods', - as: :ec_course_target json.course_targets do json.array! @course_targets do |course_target| json.extract! course_target, :id, :position, :content From cb3fc13307a6e3768b0bd3762c61902ec4823694 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 9 Oct 2019 15:52:47 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=9F=A5=E7=9C=8B=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E6=88=90=E7=BB=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/homework_common.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 40de5a87c..abe254b28 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -136,7 +136,7 @@ class HomeworkCommon < ApplicationRecord # 作业查看最新成绩 def update_score identity - identity < Course::NORMAL && publish_time.present? && publish_time < Time.now && !course.is_end + identity < Course::NORMAL && publish_time.present? && publish_time < Time.now && !end_or_late_none_group end # 作业能否立即发布