// Path: ssopay-qywx-common/src/main/java/com/ssopay/qywx/base/Exceptions.java
// public class Exceptions extends RuntimeException {
// 	private static final long serialVersionUID = -6695188947450520803L;
// 	private String key;
// 
// 	private Object[] values;
// 
// 	public Exceptions() {
// 		super();
// 	}
// 
// 	public Exceptions(String message, Throwable throwable) {
// 		super(message, throwable);
// 	}
// 
// 	public Exceptions(String message) {
// 		super(message);
// 	}
// 
// 	public Exceptions(Throwable throwable) {
// 		super(throwable);
// 	}
// 
// 	public Exceptions(String message,String key){
// 		super(message);
// 		this.key = key;
// 	}
// 
// 	public Exceptions(String message,String key,Object value){
// 		super(message);
// 		this.key = key;
// 		this.values = new Object[]{value};
// 	}
// 
// 	public Exceptions(String message,String key,Object[] values){
// 		super(message);
// 		this.key = key;
// 		this.values = values;
// 	}
// 
// 	public String getKey() {
// 		return key;
// 	}
// 
// 	public Object[] getValues() {
// 		return values;
// 	}
// 
// }


import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.lang3.StringEscapeUtils;
import com.ssopay.qywx.base.Exceptions;
/**
 * Copyright (c) 2005-2012 springside.org.cn
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package com.ssopay.qywx.util;




/**
 * 封装各种格式的编码解码工具类.
 * 
 * 1.Commons-Codec的 hex/base64 编码
 * 2.自制的base62 编码
 * 3.Commons-Lang的xml/html escape
 * 4.JDK提供的URLEncoder
 * 
 * @author calvin
 */
public class Encodes {

	private static final String DEFAULT_URL_ENCODING = "UTF-8";
	private static final char[] BASE62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray();

	/**
	 * Hex编码.
	 */
	public static String encodeHex(byte[] input) {
		return Hex.encodeHexString(input);
	}

	/**
	 * Hex解码.
	 */
	public static byte[] decodeHex(String input) {
		try {
			return Hex.decodeHex(input.toCharArray());
		} catch (DecoderException e) {
// Path: ssopay-qywx-common/src/main/java/com/ssopay/qywx/base/Exceptions.java
// public class Exceptions extends RuntimeException {
// 	private static final long serialVersionUID = -6695188947450520803L;
// 	private String key;
// 
// 	private Object[] values;
// 
// 	public Exceptions() {
// 		super();
// 	}
// 
// 	public Exceptions(String message, Throwable throwable) {
// 		super(message, throwable);
// 	}
// 
// 	public Exceptions(String message) {
// 		super(message);
// 	}
// 
// 	public Exceptions(Throwable throwable) {
// 		super(throwable);
// 	}
// 
// 	public Exceptions(String message,String key){
// 		super(message);
// 		this.key = key;
// 	}
// 
// 	public Exceptions(String message,String key,Object value){
// 		super(message);
// 		this.key = key;
// 		this.values = new Object[]{value};
// 	}
// 
// 	public Exceptions(String message,String key,Object[] values){
// 		super(message);
// 		this.key = key;
// 		this.values = values;
// 	}
// 
// 	public String getKey() {
// 		return key;
// 	}
// 
// 	public Object[] getValues() {
// 		return values;
// 	}
// 
// }


// Path: ssopay-qywx-common/src/main/java/com/ssopay/qywx/util/Encodes.java
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.lang3.StringEscapeUtils;
import com.ssopay.qywx.base.Exceptions;

/**
 * Copyright (c) 2005-2012 springside.org.cn
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package com.ssopay.qywx.util;




/**
 * 封装各种格式的编码解码工具类.
 * 
 * 1.Commons-Codec的 hex/base64 编码
 * 2.自制的base62 编码
 * 3.Commons-Lang的xml/html escape
 * 4.JDK提供的URLEncoder
 * 
 * @author calvin
 */
public class Encodes {

	private static final String DEFAULT_URL_ENCODING = "UTF-8";
	private static final char[] BASE62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray();

	/**
	 * Hex编码.
	 */
	public static String encodeHex(byte[] input) {
		return Hex.encodeHexString(input);
	}

	/**
	 * Hex解码.
	 */
	public static byte[] decodeHex(String input) {
		try {
			return Hex.decodeHex(input.toCharArray());
		} catch (DecoderException e) {
			throw new Exceptions("未经检查的异常。");