com.jfinal.weixin.sdk.kit.RandomKit Maven / Gradle / Ivy
package com.jfinal.weixin.sdk.kit;
import java.util.concurrent.ThreadLocalRandom;
/**
* 随机工具,用于生成 nonce_str 等随机字符串
*/
public class RandomKit {
private static final char[] CHAR_ARRAY = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
/**
* 生成指定长度的随机字符串
*/
public static String gen(int len) {
StringBuilder ret = new StringBuilder(len);
ThreadLocalRandom random = ThreadLocalRandom.current();
for (int i=0; i