package com.bcxin.tenant.domain.utils.encry;

import java.util.Map;
import java.util.Random;
import java.util.TreeMap;

public class CreatRandomStr {

    public static String CreatenNonce_str() {
        String[] strs = new String[]{"a", "b", "c", "d", "e", "f",
                "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
                "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F",
                "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S",
                "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5",
                "6", "7", "8", "9"};
        Random r = new Random();
        StringBuilder sb = new StringBuilder();
        int length = strs.length;
        for (int i = 0; i < 32; i++) {
            sb.append(strs[r.nextInt(length - 1)]);
        }
        return sb.toString();
    }

    public static String createStr(Map params, String secret) {
        Map treeMap = new TreeMap(params);// treeMap默认会以key值升序排序
        StringBuilder sb = new StringBuilder();
        for (Object key : treeMap.keySet()) {
            sb.append(key).append("=").append(treeMap.get(key)).append("&");
        }
        sb.append("clientSecret=" + secret);
        return sb.toString();
    }



    public static String noncert_str() {
        String[] strs = new String[]{ "0", "1", "2", "3", "4", "5",
                "6", "7", "8", "9"};
        Random r = new Random();
        StringBuilder sb = new StringBuilder();
        int length = strs.length;
        for (int i = 0; i < 8; i++) {
            sb.append(strs[r.nextInt(length - 1)]);
        }
        return sb.toString();
    }


    public static String createStr(Map params) {
        Map treeMap = new TreeMap(params);// treeMap默认会以key值升序排序
        StringBuilder sb = new StringBuilder();
        for (Object key : treeMap.keySet()) {
            sb.append(key).append("=").append(treeMap.get(key)).append("&");
        }
        return sb.toString().substring(0,sb.toString().length()-1);
    }



}
