Sha256: 50e430bd659afc818a5dd098f37257fe9de394ef9857379d3ee0f37134698b06

Contents?: true

Size: 609 Bytes

Versions: 22

Compression:

Stored size: 609 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, rand(10).to_s)
    end
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
alipay-0.4.0 lib/alipay/utils.rb
alipay-0.3.1 lib/alipay/utils.rb