Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_hjm_a
杨树林 5 years ago
commit 86e1d4d815

@ -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

@ -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

@ -0,0 +1,2 @@
module Wechat
end

@ -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

@ -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

@ -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

@ -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
# 作业能否立即发布

@ -1,2 +1,29 @@
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

@ -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']
Loading…
Cancel
Save