lib/reapal/http/communicate.rb in reapal-0.2.2 vs lib/reapal/http/communicate.rb in reapal-0.3.0

- old
+ new

@@ -4,21 +4,22 @@ SIGN_TYPE = '0' # 0 表示 md5 VERSION = '1.0' # 版本号 def self.post(service, params, config, post_path, version=VERSION) + version = VERSION if version.nil? post_body = get_body(service, params, config, version) uri = URI(config[:server_url] + post_path) Reapal.logger.info "[#{service}] 请求内容为:\n#{params}\n" Reapal.logger.info "[#{service}(#{uri})] 最终发送内容为:\n#{post_body}\n" result = nil begin response = Net::HTTP.post_form(uri, post_body) - Reapal.logger.info "[#{service}] 返回的报文为:\n#{response.body}" + Reapal.logger.info "[#{service}] 返回的报文为:\n#{response.body.force_encoding('utf-8')}" if response.is_a?(Net::HTTPSuccess) response_raw_body = unpack_body(response.body, config) result = Reapal::Http::Response.new(service: service, flow_id: params[:orderNo], @@ -93,11 +94,11 @@ data end private - + def self.unpack_body(body_string, config) begin # 返回是 json 字符串格式 body = Utils.symbolize_keys(JSON.parse(body_string)) rescue @@ -117,11 +118,11 @@ self.decode_data(body[:encryptkey], body[:data], config) end # 正确的返回字符串例子: # 'version=1.0&service=reapal.trust.onekeyContract&signType=0&sign=cdab41a05d595d6a5f5a818af2b39398&resData={"contracts":"RB1711167FYG9U29","userName":"王五","userIdentity":"330602198711160034","userMobile":"18357101332","orderNo":"5a0d488fe0c016049a000001","resultCode":"0007","processTime":"2017-11-16 16:13:04"}' - # + # # 异常的返回字符串例子: # '{"orderNo":"FFSS1","errorCode":"0107","service":"reapal.trust.onekeyContract","errorMsg":"姓名不能为空"}' def self.parse_data_string(data_string) result = {} arr = data_string.split('&') @@ -132,10 +133,10 @@ arr.each{ |sub_str| sub_arr = sub_str.split('=') result[sub_arr[0].to_sym] = sub_arr[1] } end - + result end end end