Sha256: f5cf3db13cf5bebe611036b89f3dbddf431c579c06b56a0d52961d111bdafef3

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

require 'erb'

module Alipay
  module App
    module Sign
      def self.verify?(params, options = {})
        params = ::Alipay::Utils.stringify_keys(params)

        sign_type = params.delete('sign_type').upcase
        unless options[:sign_type].to_s.upcase == sign_type
          raise "sign_type not match: params: #{params[:sign_type]} options: #{options[:sign_type]}"
        end

        sign = params.delete('sign')
        string = ::Alipay::Sign.params_to_string(params)

        case sign_type
        when 'RSA'
          ::Alipay::Sign::RSA.verify?(options[:key], string, sign)
        when 'RSA2'
          ::Alipay::Sign::RSA2.verify?(options[:key], string, sign)
        else
          false
        end
      end

      def self.params_to_sorted_string(params)
        params.sort.map { |key, value| %Q(#{key}=#{value.to_s}) }.join('&')
      end

      def self.params_to_encoded_string(params)
        params.sort.map { |key, value| %Q(#{key}=#{ERB::Util.url_encode(value.to_s)}) }.join('&')
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
yl_alipay-0.15.3 lib/alipay/app/sign.rb
yl_alipay-0.15.2 lib/alipay/app/sign.rb