class AlipayEscrow::Base

Constants

GATEWAY

Attributes

key[R]
options[RW]
params[R]
partner_id[R]

Public Class Methods

new(params, key, partner_id) click to toggle source
# File lib/alipay_escrow/base.rb, line 8
def initialize(params, key, partner_id)
  @params = params
  @key = key
  @partner_id = partner_id
  @options = {}
end

Public Instance Methods

verify() click to toggle source
# File lib/alipay_escrow/base.rb, line 15
def verify
  signature_verify && notification_verify
end

Private Instance Methods

encrypt(str) click to toggle source
# File lib/alipay_escrow/base.rb, line 38
def encrypt(str)
  Base64.strict_encode64(OpenSSL::PKey::RSA.new(key).sign('sha1', str))
end
notification_verify() click to toggle source
# File lib/alipay_escrow/base.rb, line 29
def notification_verify
  query_params = {
    'service' => 'notify_verify',
    'partner' => partner_id,
    'notify_id' => params['notify_id']
  }
  HTTParty.get("#{GATEWAY}#{query_params.to_query}")
end
signature_verify() click to toggle source
# File lib/alipay_escrow/base.rb, line 21
def signature_verify
  params.delete('sign_type')
  signature = params.delete('sign')
  data = params.sort.map { |item| item.join('=') }.join('&')
  rsa = OpenSSL::PKey::RSA.new(key)
  rsa.verify('sha1', Base64.strict_decode64(signature), data)
end