Class: GeeePay::Utils::HttpPost
- Inherits:
-
Object
- Object
- GeeePay::Utils::HttpPost
- Defined in:
- lib/geee_pay/utils/http_post.rb
Constant Summary collapse
- DEFAULT_ERR_MSG =
'{"code":"0","desc":"其他错误!"}'
Class Method Summary collapse
Class Method Details
.send_post(service_type, query_params, key) ⇒ Object
发送请求
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/geee_pay/utils/http_post.rb', line 10 def self.send_post(service_type, query_params, key) api_url = "#{GeeePay.api_base_url}/#{service_type}" # 对参数就行排序并签名 sign_data, sign_str = GeeePay::Utils::Md5.sign(query_params, key) # 加签名的查询参数 func_params = {"signData" => sign_data} func_all_params = query_params.merge(func_params) conn = Faraday.new(:url => api_url) # 设置超时时间 conn..timeout = 20 response = conn.post '', func_all_params html_response = response.body html_content = '' if GeeePay.debug_mode log_file = File.join(Rails.root, "log", "geee_pay.log") logger = Logger.new(log_file) logger.info('--------------GEEE PAY DEBUG--------------') logger.info("URL:#{api_url.to_s}") logger.info("PARAMS:#{func_all_params.to_s}") logger.info("SIGN_STR:#{sign_str}") logger.info("SIGN_DATA:#{sign_data}") logger.info("RESPONSE:#{html_response.force_encoding('UTF-8')}") end begin msg = JSON.parse(html_response) rescue JSON::ParserError => e html_content = html_response msg = JSON.parse(DEFAULT_ERR_MSG) end return msg, html_content end |