test
This commit is contained in:
parent
580be0b34b
commit
0c29701f9b
|
@ -38,45 +38,32 @@ class Panel::Ask::BackEnd::AskRepliesController < OrbitBackendController
|
|||
require 'net/http'
|
||||
require 'uri'
|
||||
require 'json'
|
||||
|
||||
uri_path = "/panel/ask/back_end/ask_requests/auth_request"
|
||||
|
||||
uri_path = "/panel/ask/back_end/ask_requests/transfer_request"
|
||||
uri = URI.parse("http://" + dep_dns + uri_path)
|
||||
|
||||
body = {
|
||||
'auth_token' => '3kjlfksjDFJ'
|
||||
}
|
||||
|
||||
http = Net::HTTP.new(uri.host, uri.port)
|
||||
request = Net::HTTP::Post.new(uri.request_uri)
|
||||
body = {
|
||||
# 'auth_token' => '3kjlfksjDFJ',
|
||||
'name' => current_question.name,
|
||||
'title' => current_question.title,
|
||||
'identity' => current_question.identity,
|
||||
'email' => current_question.email,
|
||||
'phone' => current_question.phone,
|
||||
'tax' => current_question.tax,
|
||||
'content' => current_question.content,
|
||||
}
|
||||
request.set_form_data(body)
|
||||
request.add_field 'X-Auth-Token', '3kjlfksjDFJ'
|
||||
response = http.request(request)
|
||||
puts "Response #{response.code} #{response.message}: #{response.body}"
|
||||
|
||||
if response.code == "200"
|
||||
uri_path = "/panel/ask/back_end/ask_requests/transfer_request"
|
||||
uri = URI.parse("http://" + dep_dns + uri_path)
|
||||
http = Net::HTTP.new(uri.host, uri.port)
|
||||
request = Net::HTTP::Post.new(uri.request_uri)
|
||||
body = {
|
||||
'name' => current_question.name,
|
||||
'title' => current_question.title,
|
||||
'identity' => current_question.identity,
|
||||
'email' => current_question.email,
|
||||
'phone' => current_question.phone,
|
||||
'tax' => current_question.tax,
|
||||
'content' => current_question.content,
|
||||
}
|
||||
request.set_form_data(body)
|
||||
response = http.request(request)
|
||||
|
||||
if response.code != "200"
|
||||
new_status = "轉介其他單位" + "(" + response.code + ")"
|
||||
current_reply.update_attributes(status: new_status)
|
||||
else
|
||||
new_status = "轉介其他單位" + "(" + "success!" + ")"
|
||||
current_reply.update_attributes(status: new_status)
|
||||
end
|
||||
end
|
||||
# binding.pry
|
||||
if response.code != "200"
|
||||
new_status = "轉介其他單位" + "(" + response.code + ")"
|
||||
current_reply.update_attributes(status: new_status)
|
||||
else
|
||||
new_status = "轉介其他單位" + "(" + "success!" + ")"
|
||||
current_reply.update_attributes(status: new_status)
|
||||
end
|
||||
|
||||
puts "Response #{response.code} #{response.message}: #{response.body}"
|
||||
# flash[:notice] = response.body
|
||||
|
|
|
@ -1,35 +1,33 @@
|
|||
# encoding: utf-8
|
||||
class Panel::Ask::BackEnd::AskRequestsController < OrbitBackendController
|
||||
|
||||
include AdminHelper
|
||||
include OrbitControllerLib::DivisionForDisable
|
||||
|
||||
def auth_request
|
||||
render :json => "#{params}"
|
||||
end
|
||||
|
||||
# skip_before_filter :verify_authenticity_token
|
||||
|
||||
def transfer_request
|
||||
|
||||
if !AskCategory.where(key: "transfered_question").any?
|
||||
@ask_category = AskCategory.new(name: "transfered_question", key: "transfered_question")
|
||||
@ask_category.save!
|
||||
|
||||
if request.headers["HTTP_X_AUTH_TOKEN"] == '3kjlfksjDFJ'
|
||||
if !AskCategory.where(key: "transfered_question").any?
|
||||
@ask_category = AskCategory.new(name: "transfered_question", key: "transfered_question")
|
||||
@ask_category.save!
|
||||
end
|
||||
category = AskCategory.where(key: "transfered_question")
|
||||
@transfered_question = AskQuestion.new(
|
||||
name: params['name'],
|
||||
identity: params['identity'],
|
||||
email: params['email'],
|
||||
phone: params['phone'],
|
||||
tax: params['tax'],
|
||||
title: params['title'],
|
||||
content: params['content'],
|
||||
ask_category_id: category.first.id)
|
||||
@transfered_question.ask_reply = AskReply.new
|
||||
@transfered_question.ask_reply.update_attributes(status: "待處理(轉)")
|
||||
@transfered_question.save
|
||||
render :nothing => true
|
||||
else
|
||||
render :status => 500
|
||||
end
|
||||
category = AskCategory.where(key: "transfered_question")
|
||||
|
||||
@transfered_question = AskQuestion.new(
|
||||
name: params['name'],
|
||||
identity: params['identity'],
|
||||
email: params['email'],
|
||||
phone: params['phone'],
|
||||
tax: params['tax'],
|
||||
title: params['title'],
|
||||
content: params['content'],
|
||||
ask_category_id: category.first.id)
|
||||
@transfered_question.ask_reply = AskReply.new
|
||||
@transfered_question.ask_reply.update_attributes(status: "待處理(轉)")
|
||||
@transfered_question.save
|
||||
|
||||
render :json => "#{params}"
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue