java中对map的字典序排序
来源:互联网 发布:程序员怎么赚钱 编辑:程序博客网 时间:2024/06/06 03:36
java中对map的字典序排序,算法验证比对微信官网https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN,搜索关键字“附录1-JS-SDK使用权限签名算法”
import java.util.ArrayList;import java.util.Collection;import java.util.Collections;import java.util.HashMap;import java.util.List;import org.apache.commons.codec.digest.DigestUtils;import com.opensymphony.xwork2.ActionSupport;public class Test extends ActionSupport {//测试页面public String test(){return SUCCESS;}public static void main(String [] args){String jsapi_ticket="kgt8ON7yVITDhtdwci0qef4Fd1u2d2iWwTE-nt2tSR7Me3FmWAhtxJa3QQCiMdLper4cUrqpDxkDJ6ljLgc7PA";int timestamp=1460637652;String nonceStr="C1WNnEpCwq4wa158";String url="http://qq.test.com/test/index.html";//字典序排序HashMap<String,String> map=new HashMap<String,String>();map.put("jsapi_ticket", jsapi_ticket);map.put("timestamp", timestamp+"");map.put("nonceStr", nonceStr);map.put("url", url);Collection<String> keyset= map.keySet(); List list=new ArrayList<String>(keyset);Collections.sort(list);//这种打印出的字符串顺序和微信官网提供的字典序顺序是一致的for(int i=0;i<list.size();i++){System.out.println(list.get(i)+"="+map.get(list.get(i)));}//微信官网写的按照字典序排序后的字符串String sign="jsapi_ticket="+jsapi_ticket+"&noncestr="+nonceStr+"×tamp="+timestamp+"&url="+url;//System.out.println(DigestUtils.shaHex("jsapi_ticket=sM4AOVdWfPE4DxkXGEs8VMCPGGVi4C3VM0P37wVUCFvkVAy_90u5h9nbSlYy3-Sl-HhTdfl2fzFy1AOcHKP7qg&noncestr=Wm3WZYTPz0wzccnW×tamp=1414587457&url=http://mp.weixin.qq.com?params=value"));//微信返回的加密串String signature=DigestUtils.shaHex(sign);//sha1加密System.out.println(signature);}}
2 0
- java中对map的字典序排序
- 如何对Map进行字典排序Java
- java对map中value的排序
- Java中对Map的排序时间
- java 对map的排序
- Java中对Map(HashMap,TreeMap,Hashtable等)的排序
- Java中对Map(HashMap,TreeMap,Hashtable等)的排序
- 对n以内的数字进行字典序排序(java)
- java 对 Map 排序
- Java对Map排序
- Java 对Map排序
- Java对Map排序
- Java对Map排序
- Java对Map排序
- Java对Map排序
- Java对Map排序
- Java对Map排序
- Java中Map的排序
- java图片与base64字符串互转
- iOS开发bug调试技巧之Debug View Hierarchy
- 解决 Ubuntu gedit 显示汉字乱码问题
- .net http发送put、delete请求报405错误解决办法
- iOS开发:code signing is required for product type 'Application' in SDK 'iOS 9.2'
- java中对map的字典序排序
- loadrunner中C函数(带例子)
- Selenium2 Python 自动化测试实战学习笔记(五)
- LinkedList
- Android API Guides---Resource Types
- scons tips
- 路由器tomato固件上搭建svn
- uva 1396 Slim Span
- Linux系统的磁盘内存CPU网络测试工具