/*
 * Project: payment.framework
 *
 * File Created at 2017年12月23日
 *
 * Copyright 2016 CMCC Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * ZYHY Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license.
 */
package com.cmcc.hybj.payment.framework.https;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Comparator;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Set;
import java.util.TreeSet;

/**
 * @author gy
 * @Type Sign.java
 * @Desc 支付签名
 * @date 2017年12月23日 上午9:56:04
 */
public class Sign {
    private static Logger log = LoggerFactory.getLogger(Sign.class);

/**
     * // 服务器端生成签名
     *
     * @param map
     * @return
     */
    public static String buildSign(Hashtable<String, String> map) {
        Set<String> keys = new TreeSet<String>(new MyComparator());
        Enumeration<String> enumeration = map.keys();
        while (enumeration.hasMoreElements()) {
            String keyss = enumeration.nextElement();
            keys.add(keyss);
        }
        // 拼接有序的参数名-值串
        StringBuilder stringBuilder = new StringBuilder();
        for (String key : keys) {
            String value = map.get(key);
            if (value == null) {
                continue;
            } else if ("".equals(value.trim())) {
                continue;
            } else if ("sign".equals(key.trim())) {
                continue;
            } else {
                stringBuilder.append(key).append("=").append(value).append("&");
            }
        }
        String s = stringBuilder.toString();
        s = s.substring(0, s.length() - 1);
        log.info("排序后的参数 :" + s);
        return s;
    }

/**
     * 内部类
     *
     * @author gy
     */
    public static class MyComparator implements Comparator<String> {

@Override
        public int compare(String o1, String o2) {

return o1.compareTo(o2);// 升序排列
        }

}
}

/**
 * Revision history
 * -------------------------------------------------------------------------
 * <p>
 * Date Author Note
 * -------------------------------------------------------------------------
 * 2017年12月23日 Administrator creat
 */

字典排序MD5生成代码的更多相关文章

  1. 签名:实现参数字典排序,然后拼接为url参数形式

    在很多地方请求参数需要做处理例如: 步骤 1.参数字典排序. 2.拼接字符. /// <summary> /// 生成签名 /// </summary> /// <par ...

  2. python进阶--字典排序

    zip()函数 sorted() 要求对字典中,按值的大小排序 解决方案: 利用zip函数 zip函数介绍: zip函数可以将可迭代对象打包成一个个元组,在python3中返回一个对象,在python ...

  3. mybatis Generator生成代码及使用方式

    本文原创,转载请注明:http://www.cnblogs.com/fengzheng/p/5889312.html 为什么要有mybatis mybatis 是一个 Java 的 ORM 框架,OR ...

  4. Python实现各种排序算法的代码示例总结

    Python实现各种排序算法的代码示例总结 作者:Donald Knuth 字体:[增加 减小] 类型:转载 时间:2015-12-11我要评论 这篇文章主要介绍了Python实现各种排序算法的代码示 ...

  5. yii2使用Gii生成代码

    本章节将介绍怎样使用 Gii 去自己主动生成 Web 网站经常使用功能的代码.使用 Gii 生成代码很easy,仅仅要依照 Gii 页面上的介绍输入正确的信息就可以. 贯穿本章节,你将会学到: 在你的 ...

  6. 经常使用MD5算法代码

    经常使用的MD5算法代码日期: 2014年8月4日作者: 铁锚 MD5,全称为 Message Digest Algorithm 5(消息摘要算法第五版).详情请參考 维基百科:MD5  MD5加密后 ...

  7. python之gui-tkinter可视化编辑界面 自动生成代码

    首先提供资源链接 http://pan.baidu.com/s/1kVLOrIn#list/path=%2F

  8. T4模板生成代码。 数据实体层与数据仓储层。备注

    文件生成模板:TempleteManager.ttinclude <#@ assembly name="System.Core" #><#@ assembly n ...

  9. java的字典排序

    按照教程上的代码还是报错 应该是字典排序的问题,不能是Arrays.sort()

随机推荐

  1. uniform

    float timeValue = glfwGetTime(); float greenValue = (sin(timeValue) / 2.0f) + 0.5f; int vertexColorL ...

  2. attribute和property的区别是什么?

          attribute                                       property 标签属性 对应html                       对象属 ...

  3. 编码格式检测chardet模块

    chardet模块: -->检测编码格式 未知编码的bytes,要把它转换成str,就需要知道该bytes的编码方式 #1.直接检测bytes >>> chardet.dete ...

  4. Python全栈--目录导航

    这里更新以Python语言作为基础,想要成为全栈工程师需要掌握的技能... Python基础语法 day01 初识Python day02 while循环 运算符和编码 day03 字符串 day04 ...

  5. 几句话总结一个算法之Q-Learning与Sarsa

    与Policy Gradients的不同之处在于,这两个算法评估某个状态s执行某个动作a的期望奖励,即Q(s,a) Q(s,a) 有两种方法计算方法,第一种直接查表或者模型预估,Q(s, a) = c ...

  6. 在WIN7操作系统下,如何显示文件夹里文件的数目

    在文件夹的“查看”选项中选择“状态栏”,那么在任务栏中可以显示windows7系统中文件夹中文件的数目.具体操作请参照以下步骤. 1.首先开启电脑,在电脑中进入到任意一个文件夹中. 2.然后在文件夹界 ...

  7. 微慕WordPress小程序增强版

    2017年1月9日,张小龙在2017微信公开课Pro上发布的微信小程序正式上线.在过去的2年多的时间里,微信小程序领头,各大互联网平台也不甘落后,陆续推出自己的小程序.2018年7月4日,百度智能小程 ...

  8. Linux 就该这么学 CH05 用户的身份和文件权限

    1 用户权限与能力 超级用户root拥有最高的系统所有权,能够管理系统的各项功能,如添加.删除用户:启动或关闭服务进程:开启或禁用硬件设备等. 用户身份分类: 系统管理员root :UID = 0; ...

  9. LinkedHashMap源码

    TreeMap是一颗红黑树做Map.HashMap是数组+链表+红黑树.HashTable是数组+链表. LinkedHashMap底层存储结构与HashMap一样,不同的是LinkedHashMap ...

  10. KB,MB,GB,TB,PB,EB,ZB,YB,BB

    1 Bit = Binary Digit 8 Bits = 1 Byte 1024 Bytes = 1 Kilobyte 1024 Kilobytes = 1 Megabyte 1024 Megaby ...