Sha256: dad0cc2e9114a98bd062eeb849e6b50b144a0c50b5d603f4db6ab31068e8e980

Contents?: true

Size: 622 Bytes

Versions: 4

Compression:

Stored size: 622 Bytes

Contents

module Alipay
  module Utils
    def self.stringify_keys(hash)
      new_hash = {}
      hash.each do |key, value|
        new_hash[(key.to_s rescue key) || key] = value
      end
      new_hash
    end

    # 退款批次号,支付宝通过此批次号来防止重复退款操作,所以此号生成后最好直接保存至数据库,不要在显示页面的时候生成
    # 共 24 位(8 位当前日期 + 9 位纳秒 + 1 位随机数)
    def self.generate_batch_no
      t = Time.now
      batch_no = t.strftime('%Y%m%d%H%M%S') + t.nsec.to_s
      batch_no.ljust(24, Random.new.rand(1..9).to_s)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
alipay-0.3.0 lib/alipay/utils.rb
alipay-0.2.0 lib/alipay/utils.rb
alipay-0.1.0 lib/alipay/utils.rb
alipay-0.0.5 lib/alipay/utils.rb