Module: Allinpay::Service

Defined in:
lib/allinpay/service.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.connection(env, options) ⇒ Object

网关信息处理

Parameters:

  • env (String)

    所在环境

  • options (Hash)

    (see #set_signature_infomation)



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/allinpay/service.rb', line 7

def self.connection(env, options)
  set_signature_infomation(options)
  ssl_options = {}
  if env.to_s == "development" || env.to_s == "test"
    ssl_options = {verify: false} 
  end
  klass = Class.new do
    include Allinpay::Service
    attr_accessor :gateway_url, :conn

    def initialize(env, ssl_options)
      @gateway_url = set_gateway_url(env)
      @conn = Faraday.new gateway_url, ssl: ssl_options
    end
  end.new(env, ssl_options)
end

Instance Method Details

#request(params) ⇒ Hash

处理请求

Parameters:

  • params (Hash)

    将参数发送服务器

Returns:

  • (Hash)

    将处理后的结果转换成Hash



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/allinpay/service.rb', line 28

def request(params)
  params[:INFO][:SIGNED_MSG] = Signature.generate(parse_xml(params)).unpack('H*').first
  body = parse_xml(params)
  response = conn.post do |req|
    req.headers['Content-Type'] = 'text/xml'
    req.body = body
  end
  return raise "HTTP Connection has error." if response.status != 200
  result = response.body
  result_xml = Hash.from_xml(result)
  return raise "Signature verify failed." if !verify_signature?(result, result_xml)
  return result_xml['AIPG']
end