module Tools
class Sign
'''
参数从小到大排序
'''
def self.sort_param(data)
data = data.sort{ |a,b| a.to_s <=> b.to_s }.to_h
end
'''
hash转url参数格式化
'''
def self.to_query(param)
format = []
param.each_with_index do |value|
if value[1].present?
format << "#{value[0]}=#{value[1]}"
end
end
format.join('&')
end
'''
hash转xml
'''
def self.to_wx_xml(hash)
xml = "<xml>"
hash.each_with_index do |value, key|
xml += "<#{value[0].to_s}><![CDATA[#{value[1].to_s}]]></#{value[0].to_s}>"
end
xml += "</xml>"
end
end
end