package com.library.util;

import java.lang.reflect.Type;
import java.security.MessageDigest;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

/**
 * 工具类
 * @author cyy
 *
 */
public class Tools {
	public static Gson gson=new Gson();
	
	public static Type IntegerListType=new TypeToken<List<Integer>>(){}.getType();
	public static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm");
	public static SimpleDateFormat format2 = new SimpleDateFormat("yy/MM/dd");
	public static SimpleDateFormat format3 = new SimpleDateFormat("yyy-MM-dd hh:mm");
	

	
	
	/**
     * 保留小数点后两位
     */
    public static double SaveTwoPoint(double value){
        DecimalFormat df=new  DecimalFormat("#.##");
        return Double.parseDouble(df.format(value));
    }
    
	//获得授权地址
	public static String getAddress(String state) {
		String url="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb8fe9657eb40e99f&redirect_uri=http%3a%2f%2fxm-fzw.com%2fUserController%2fwechat_LoginRegist.do&response_type=code&scope=snsapi_userinfo&state="+state+"#wechat_redirect";//首页
		return url;
	}

	//无需授权获得openid
	public static String getAddress2(String state) {
		String url="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb8fe9657eb40e99f&redirect_uri=http%3a%2f%2fxm-fzw.com%2fUserController%2fwechat_LoginRegist.do&response_type=code&scope=snsapi_base&state="+state+"#wechat_redirect";//首页
		return url;
	}
	
	
	/**
	 * MD5加密
	 */
	public static String md5(String password) {
		try {
			StringBuffer buffer = new StringBuffer();
			char[] chars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
					'A', 'B', 'C', 'D', 'E', 'F' };
			byte[] bytes = password.getBytes();
			MessageDigest md = MessageDigest.getInstance("MD5");
			byte[] targ = md.digest(bytes);
			for (byte b : targ) {
				buffer.append(chars[(b >> 4) & 0x0F]);
				buffer.append(chars[b & 0x0F]);
			}
			return buffer.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	
}
