Sha256: 694f71f763501c7544e00c6230457762c31c37595302909f6104fcbe723b1223
Contents?: true
Size: 1.06 KB
Versions: 1
Compression:
Stored size: 1.06 KB
Contents
module Zhima class Request GATEWAY = 'https://zmopenapi.zmxy.com.cn/openapi.do' SYSTEM_OPTIONS = {charset: 'UTF-8', version: '1.0', channel: 'app'} attr_accessor :biz_params, :sys_options def initialize(biz_params, sys_options) @biz_params = biz_params @sys_options = SYSTEM_OPTIONS.merge(sys_options) end 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 def execute response = RestClient.get url parse_response(response.body) end private # 芝麻返回的json数据解析,结果为真正的业务参数 # TODO verify sign def parse_response(response_str) response_hash = JSON.parse(response_str) biz_response = response_hash["biz_response"] biz_response = Param.decrypt(biz_response) if response_hash["encrypted"] JSON.parse(biz_response) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
zhima-0.3.0 | lib/zhima/request.rb |