class Zhima::Request
Constants
- GATEWAY
- SYSTEM_OPTIONS
Attributes
biz_params[RW]
sys_options[RW]
Public Class Methods
new(biz_params, sys_options)
click to toggle source
# File lib/zhima/request.rb, line 8 def initialize(biz_params, sys_options) @biz_params = biz_params @sys_options = SYSTEM_OPTIONS.merge(sys_options) end
Public Instance Methods
execute()
click to toggle source
# File lib/zhima/request.rb, line 21 def execute response = RestClient.get url parse_response(response.body) end
url()
click to toggle source
# File lib/zhima/request.rb, line 13 def url params_value, sign = Param.encrypt(biz_params) opts = SYSTEM_OPTIONS.merge(sys_options) .merge(params: params_value, sign: sign, app_id: Config.app_id) query_str = Util.to_query(opts) [GATEWAY, query_str].join('?') end
Private Instance Methods
parse_response(response_str)
click to toggle source
芝麻返回的json数据解析,结果为真正的业务参数
# File lib/zhima/request.rb, line 29 def parse_response(response_str) response_hash = JSON.parse(response_str) biz_response_sign = response_hash['biz_response_sign'] biz_response = response_hash['biz_response'] biz_response = Param.decrypt(biz_response) if response_hash["encrypted"] if response_hash["encrypted"] && !Sign.verify?(biz_response_sign, biz_response) raise VerifySignError.new('sign解签错误') else JSON.parse(biz_response) end end