|
|
@ -1,4 +1,16 @@
|
|
|
|
#encoding=utf-8
|
|
|
|
#encoding=utf-8
|
|
|
|
|
|
|
|
# 云启训练场(EduCoder)个人版 产品编码(appId) 9200108
|
|
|
|
|
|
|
|
# 产品名称 计费类型 套餐编码
|
|
|
|
|
|
|
|
# 云启训练场(EduCoder)个人版 固定包月 9200108001
|
|
|
|
|
|
|
|
# 固定包月 9200108002
|
|
|
|
|
|
|
|
# 固定包月 9200108003
|
|
|
|
|
|
|
|
# ---------------------------------------------------
|
|
|
|
|
|
|
|
# 产品名称 计费类型 套餐编码
|
|
|
|
|
|
|
|
# 云启训练场(EduCoder))院校版 包月+按license 9200109001
|
|
|
|
|
|
|
|
# 包月+按license 9200109002
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 云启训练场(EduCoder))院校版 产品编码(appId) 9200109
|
|
|
|
|
|
|
|
|
|
|
|
require 'net/http'
|
|
|
|
require 'net/http'
|
|
|
|
require 'digest'
|
|
|
|
require 'digest'
|
|
|
|
|
|
|
|
|
|
|
@ -6,6 +18,7 @@ class EcloudController < ApplicationController
|
|
|
|
skip_before_filter :verify_authenticity_token
|
|
|
|
skip_before_filter :verify_authenticity_token
|
|
|
|
|
|
|
|
|
|
|
|
# before_filter :check_sign, only: [:ps_new, :ps_update, :bs_new, :bs_update]
|
|
|
|
# before_filter :check_sign, only: [:ps_new, :ps_update, :bs_new, :bs_update]
|
|
|
|
|
|
|
|
before_filter :save_para
|
|
|
|
|
|
|
|
|
|
|
|
before_filter :user_setup
|
|
|
|
before_filter :user_setup
|
|
|
|
# before_filter :require_login, only: [:authorize]
|
|
|
|
# before_filter :require_login, only: [:authorize]
|
|
|
@ -33,21 +46,64 @@ class EcloudController < ApplicationController
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 企业开通
|
|
|
|
# 企业/个人业务开通
|
|
|
|
# applyno 申请单号,唯一
|
|
|
|
# applyno 申请单号,唯一
|
|
|
|
# ecordercode 唯一标志一个企业的订购关系
|
|
|
|
# ecordercode 唯一标志一个企业的订购关系
|
|
|
|
|
|
|
|
# params['opttype']:操作类型。0开通;1变更;2试用转商用;4再次开通
|
|
|
|
def bs_new
|
|
|
|
def bs_new
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
ecloud = Ecloud.create!(applyno: params['applyno'], ecordercode: params['ecordercode'], opttype: params['opttype'],
|
|
|
|
ecloud_id = 0
|
|
|
|
trial: params['trial'], bossorderid: params['bossorderid'], custid: params['custid'], custtype: params['custtype'],
|
|
|
|
if params['opttype'] == 0 # 开通企业/个人业务
|
|
|
|
custcode: params['custcode'], registersource: params['registersource'], custname: params['custname'],
|
|
|
|
ecloud = Ecloud.create!(eloud_params)
|
|
|
|
userid: params['userid'], username: params['username'], useralias: params['useralias'], mobile: params['mobile'],
|
|
|
|
ecloud_id = ecloud.try(:id)
|
|
|
|
email: params['email'], productcode: params['productcode'], begintime: params['begintime'],
|
|
|
|
elsif params['opttype'] == 2 # 试用转商用 # 变更企业/个人业务
|
|
|
|
endtime: params['endtime'])
|
|
|
|
ecloud = Ecloud.where(custid: params['custid'], custcode: params['custcode']).first
|
|
|
|
services = params['services'].first
|
|
|
|
ecloud.update_attributes!(eloud_params)
|
|
|
|
EcloudService.create(opttype: services['opttype'], code: services['code'], begintime: services['begintime'],
|
|
|
|
ecloud.ecloud_productparas.destroy
|
|
|
|
endtime: services['endtime'], ecloud_id: ecloud.try(:id))
|
|
|
|
ecloud.ecloud_services.destroy
|
|
|
|
|
|
|
|
ecloud_id = ecloud.try(:id)
|
|
|
|
|
|
|
|
elsif params['opttype'] == 1 # 业务变更
|
|
|
|
|
|
|
|
ecloud = Ecloud.where(bossorderid: params['bossorderid']).first
|
|
|
|
|
|
|
|
ecloud.update_attributes!(eloud_params)
|
|
|
|
|
|
|
|
ecloud.ecloud_productparas.destroy
|
|
|
|
|
|
|
|
ecloud.ecloud_services.destroy
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ecloud_id = ecloud.try(:id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elsif params['opttype'] == 4 # 再次重复开通
|
|
|
|
|
|
|
|
REDO
|
|
|
|
|
|
|
|
ecloud = Ecloud.where(bossorderid: params['bossorderid']).first
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 业务列表
|
|
|
|
|
|
|
|
services = params['services']
|
|
|
|
|
|
|
|
if services.present?
|
|
|
|
|
|
|
|
services.each do |service|
|
|
|
|
|
|
|
|
es = EcloudService.create(opttype: service['opttype'], code: service['code'], begintime: service['begintime'],
|
|
|
|
|
|
|
|
endtime: service['endtime'], ecloud_id: ecloud_id)
|
|
|
|
|
|
|
|
if service['serviceparas'].present?
|
|
|
|
|
|
|
|
service['serviceparas'].each do |servicepara|
|
|
|
|
|
|
|
|
EcloudServieceServicepara.create!(ecloud_service_id: es.id, key: servicepara['key'], value: servicepara['value'])
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 应用开通参数
|
|
|
|
|
|
|
|
productparas = params['productparas']
|
|
|
|
|
|
|
|
if productparas.present?
|
|
|
|
|
|
|
|
productparas.each do |productpara|
|
|
|
|
|
|
|
|
EcloudProductpara.create!(key: productpara['key'], value: productpara['value'], ecloud_id: ecloud_id)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 非试用情况下,为管理员单独创建一条账号,企业账号
|
|
|
|
|
|
|
|
unless params['trial']
|
|
|
|
|
|
|
|
EcloudUser.create!(ecloud_id: ecloud.try(:id), opttype: params['opttype'], userid: params['userid'],
|
|
|
|
|
|
|
|
username: params['username'], useralias: params['useralias'],
|
|
|
|
|
|
|
|
mobile: params['mobile'], email: params['email'])
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
render :json => {result: true, errmsg: ""}
|
|
|
|
render :json => {result: true, errmsg: ""}
|
|
|
|
rescue Exception => e
|
|
|
|
rescue Exception => e
|
|
|
@ -58,11 +114,11 @@ class EcloudController < ApplicationController
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# 企业更新
|
|
|
|
# 企业/个人业务变更、注销
|
|
|
|
def bs_update
|
|
|
|
def bs_update
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
ecloud = Ecloud.where(applyno: params['applyno']).first
|
|
|
|
ecloud = Ecloud.where(custid: params['custid'], custcode: params['custcode']).first
|
|
|
|
ecloud.update_attributes!(applyno: params['applyno'], ecordercode: params['ecordercode'], opttype: params['opttype'],
|
|
|
|
ecloud.update_attributes!(applyno: params['applyno'], ecordercode: params['ecordercode'], opttype: params['opttype'],
|
|
|
|
custid: params['custid'], custcode: params['custcode'], productcode: params['productcode'],
|
|
|
|
custid: params['custid'], custcode: params['custcode'], productcode: params['productcode'],
|
|
|
|
operatime: params['operatime'], effecttime: params['effecttime'])
|
|
|
|
operatime: params['operatime'], effecttime: params['effecttime'])
|
|
|
@ -79,17 +135,16 @@ class EcloudController < ApplicationController
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# 用户业务开通与变更接口
|
|
|
|
# 用户业务开通与变更接口
|
|
|
|
|
|
|
|
# 授权statu为1,取消授权status为0
|
|
|
|
def ps_new
|
|
|
|
def ps_new
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
user_param = params['users'].first
|
|
|
|
user_params = params['users']
|
|
|
|
# ecloud_user = EcloudUser.where(:custid => params['custid'], :userid => user_param['userid']).first
|
|
|
|
user_params.each do |user_param|
|
|
|
|
# if ecloud_user.present?
|
|
|
|
EcloudUser.create!(custid: params['custid'], opttype: user_param['opttype'], userid: user_param['userid'],
|
|
|
|
# render :json => {code: 500, msg: "你已开通过该业务"}
|
|
|
|
username: user_param['username'], useralias: user_param['useralias'],
|
|
|
|
# else
|
|
|
|
mobile: user_param['mobile'], email: user_param['email'], begintime: user_param['begintime'].to_s,
|
|
|
|
EcloudUser.create!(custid: params['custid'], opttype: user_param['opttype'], userid: user_param['userid'],
|
|
|
|
endtime: user_param['endtime'].to_s, status: 1)
|
|
|
|
username: user_param['username'], useralias: user_param['useralias'],
|
|
|
|
end
|
|
|
|
mobile: user_param['mobile'], email: user_param['email'], begintime: user_param['begintime'].to_s,
|
|
|
|
|
|
|
|
endtime: user_param['endtime'].to_s, status: 1)
|
|
|
|
|
|
|
|
render :json => {success: true, errmsg: ""}
|
|
|
|
render :json => {success: true, errmsg: ""}
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
rescue Exception => e
|
|
|
|
rescue Exception => e
|
|
|
@ -99,13 +154,15 @@ class EcloudController < ApplicationController
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# 用户业务状态变更
|
|
|
|
# 用户业务状态变更
|
|
|
|
|
|
|
|
# 授权statu为1,取消授权status为0
|
|
|
|
def ps_update
|
|
|
|
def ps_update
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
ecloud = Ecloud.where(applyno: params['applyno']).first
|
|
|
|
user_params = params['users']
|
|
|
|
user_param = params['users'].first
|
|
|
|
user_params.each do |user_param|
|
|
|
|
ecloud_user = EcloudUser.where(userid: user_param['userid'], status: 1).first
|
|
|
|
ecloud_user = EcloudUser.where(userid: user_param['userid'], status: 1).first
|
|
|
|
|
|
|
|
ecloud_user.update_attributes(opttype: user_param['opttype'], userid: user_param['userid'], status: 0)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
ecloud_user.update_attributes(opttype: user_param['opttype'], userid: user_param['userid'], status: 0)
|
|
|
|
|
|
|
|
render :json => {success: true, errmsg: ""}
|
|
|
|
render :json => {success: true, errmsg: ""}
|
|
|
|
# else
|
|
|
|
# else
|
|
|
|
# render :json => {code: 404, msg: "企业ID不存在"}
|
|
|
|
# render :json => {code: 404, msg: "企业ID不存在"}
|
|
|
@ -156,28 +213,30 @@ class EcloudController < ApplicationController
|
|
|
|
private
|
|
|
|
private
|
|
|
|
def get(url)
|
|
|
|
def get(url)
|
|
|
|
uri = URI(url)
|
|
|
|
uri = URI(url)
|
|
|
|
res = Net::HTTP.start(uri.host, uri.port, use_ssl: url.start_with?('https')) do |http|
|
|
|
|
|
|
|
|
req = Net::HTTP::Get.new(uri)
|
|
|
|
|
|
|
|
#req['Content-Type'] = 'application/json'
|
|
|
|
|
|
|
|
# The body needs to be a JSON string, use whatever you know to parse Hash to JSON
|
|
|
|
|
|
|
|
#req.body = {a: 1}.to_json
|
|
|
|
|
|
|
|
http.request(req)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
res.body
|
|
|
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
|
|
|
|
|
|
http.use_ssl = url.start_with?('https')
|
|
|
|
|
|
|
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
|
|
|
|
|
|
request = Net::HTTP::Get.new(uri.request_uri)
|
|
|
|
|
|
|
|
request['Content-Type'] = 'application/json'
|
|
|
|
|
|
|
|
request['Accept'] = 'application/json'
|
|
|
|
|
|
|
|
response = http.request(request)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
response.body
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def post(url)
|
|
|
|
def post(url)
|
|
|
|
uri = URI(url)
|
|
|
|
uri = URI(url)
|
|
|
|
res = Net::HTTP.start(uri.host, uri.port, use_ssl: url.start_with?('https')) do |http|
|
|
|
|
|
|
|
|
req = Net::HTTP::Post.new(uri)
|
|
|
|
|
|
|
|
#req['Content-Type'] = 'application/json'
|
|
|
|
|
|
|
|
# The body needs to be a JSON string, use whatever you know to parse Hash to JSON
|
|
|
|
|
|
|
|
#req.body = {a: 1}.to_json
|
|
|
|
|
|
|
|
http.request(req)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
res.body
|
|
|
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
|
|
|
|
|
|
http.use_ssl = url.start_with?('https')
|
|
|
|
|
|
|
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
|
|
|
|
|
|
request = Net::HTTP::Post.new(uri.request_uri)
|
|
|
|
|
|
|
|
request['Content-Type'] = 'application/json'
|
|
|
|
|
|
|
|
request['Accept'] = 'application/json'
|
|
|
|
|
|
|
|
response = http.request(request)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
response.body
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def decode(s)
|
|
|
|
def decode(s)
|
|
|
@ -189,6 +248,16 @@ class EcloudController < ApplicationController
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
private
|
|
|
|
|
|
|
|
def eloud_params
|
|
|
|
|
|
|
|
return {applyno: params['applyno'], ecordercode: params['ecordercode'], opttype: params['opttype'],
|
|
|
|
|
|
|
|
trial: params['trial'], bossorderid: params['bossorderid'], custid: params['custid'], custtype: params['custtype'],
|
|
|
|
|
|
|
|
custcode: params['custcode'], registersource: params['registersource'], custname: params['custname'],
|
|
|
|
|
|
|
|
userid: params['userid'], username: params['username'], useralias: params['useralias'], mobile: params['mobile'],
|
|
|
|
|
|
|
|
email: params['email'], productcode: params['productcode'], begintime: params['begintime'],
|
|
|
|
|
|
|
|
endtime: params['endtime']}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check_sign
|
|
|
|
def check_sign
|
|
|
|
sign = sign(params['timestamp'])
|
|
|
|
sign = sign(params['timestamp'])
|
|
|
|
if sign != params['sign']
|
|
|
|
if sign != params['sign']
|
|
|
@ -197,4 +266,8 @@ class EcloudController < ApplicationController
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def save_para
|
|
|
|
|
|
|
|
EcloudLog.create(url: request.url, para_value: params, applyno: params['applyno'], custid: params['custid'], custcode: params['custcode'])
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|