字典排序MD5生成代码
/*
* 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生成代码的更多相关文章
- 签名:实现参数字典排序,然后拼接为url参数形式
在很多地方请求参数需要做处理例如: 步骤 1.参数字典排序. 2.拼接字符. /// <summary> /// 生成签名 /// </summary> /// <par ...
- python进阶--字典排序
zip()函数 sorted() 要求对字典中,按值的大小排序 解决方案: 利用zip函数 zip函数介绍: zip函数可以将可迭代对象打包成一个个元组,在python3中返回一个对象,在python ...
- mybatis Generator生成代码及使用方式
本文原创,转载请注明:http://www.cnblogs.com/fengzheng/p/5889312.html 为什么要有mybatis mybatis 是一个 Java 的 ORM 框架,OR ...
- Python实现各种排序算法的代码示例总结
Python实现各种排序算法的代码示例总结 作者:Donald Knuth 字体:[增加 减小] 类型:转载 时间:2015-12-11我要评论 这篇文章主要介绍了Python实现各种排序算法的代码示 ...
- yii2使用Gii生成代码
本章节将介绍怎样使用 Gii 去自己主动生成 Web 网站经常使用功能的代码.使用 Gii 生成代码很easy,仅仅要依照 Gii 页面上的介绍输入正确的信息就可以. 贯穿本章节,你将会学到: 在你的 ...
- 经常使用MD5算法代码
经常使用的MD5算法代码日期: 2014年8月4日作者: 铁锚 MD5,全称为 Message Digest Algorithm 5(消息摘要算法第五版).详情请參考 维基百科:MD5 MD5加密后 ...
- python之gui-tkinter可视化编辑界面 自动生成代码
首先提供资源链接 http://pan.baidu.com/s/1kVLOrIn#list/path=%2F
- T4模板生成代码。 数据实体层与数据仓储层。备注
文件生成模板:TempleteManager.ttinclude <#@ assembly name="System.Core" #><#@ assembly n ...
- java的字典排序
按照教程上的代码还是报错 应该是字典排序的问题,不能是Arrays.sort()
随机推荐
- LNMP+memcached
部署LNMP+memcached网站平台,通过PHP页面实现对memcached服务器的数据操作,实现以下目标:部署LNMP实现PHP动态网站架构为PHP安装memcache扩展创建PHP页面,并编写 ...
- 最全BT磁力搜索引擎索引(整理分享,不断更新...)
最全BT磁力搜索引擎索引(整理分享,不断更新...) btkitty:http://cnbtkitty.com/(知名的BT磁力搜索,资源很多) idope.se:https://idope.se/( ...
- bzoj [SDOI2014]数表 莫比乌斯反演 BIT
bzoj [SDOI2014]数表 莫比乌斯反演 BIT 链接 bzoj luogu loj 思路 \[ \sum\limits_{i=1}^{n}\sum\limits_{j=1}^{m}a*[f[ ...
- haproxy 配置文件详解 之 global
配置示例: global log 127.0.0.1 local0 info maxconn user nobody group nobody daemon nbproc pidfile /usr/l ...
- Glimma 包
http://master.bioconductor.org/packages/3.9/bioc/html/Glimma.html 安装 if (!requireNamespace("Bio ...
- 淘宝IP地址库获取到省市IP地址
http://ip.aliyun.com/index.html https://ispip.clang.cn/ https://github.com/Pingze-github/local-ips 1 ...
- 疯了!同事又问我为什么不能用 isXXX
最近在做Code Review,写下了这篇文章:代码写成这样,老夫无可奈何!,说多了都是泪啊.. 最近又有人同事跑过来质疑我: 为什么变量名取名不能用 isXXX 这种方式,这样有什么问题?! 醉了, ...
- 免费https证书
https://certbot.eff.org/lets-encrypt/ubuntuother-nginx https://ruby-china.org/topics/31942 https://l ...
- JavaScript开发小技巧
总结一些能够提高开发效率的JS技巧 1.过滤唯一值 Set类型是在ES6中新增的,它类似于数组,但是成员的值都是唯一的,没有重复的值.结合扩展运算符(...)我们可以创建一个新的数组,达到过滤原数组重 ...
- 使用MobaXterm配置ssh隧道(port forwarding)
背景描述:如图所示,本地与远程服务器之间存在防火墙,防火墙只允许SSH端口通过,为访问远程服务器,我们可以借助MobaXterm来与SSH服务器建立隧道,使得防火墙外的用户能够访问远程服务器 具体配置 ...