package org.springblade.gateway.goods_gateway.generator;

import cn.hutool.captcha.generator.AbstractGenerator;
import org.apache.commons.lang3.StringUtils;

/**
 * @Author: Silent
 * @Description 中文生成器
 * @Date: Created in 14:13 2022/1/5
 * @Modified By:
 */
public class ChineseGenerator extends AbstractGenerator {
	/**
	 * 构造方法
	 *
	 * @param count
	 */
	public ChineseGenerator(int count) {
		super(count);
	}

	/**
	 * 生成中文字符串
	 *
	 * @return
	 */
	@Override
	public String generate() {
		StringBuilder stringBuilder = new StringBuilder();
		for (int i = 0; i < this.length; i++) {
			stringBuilder.append((char) (0x4e00 + (int) (Math.random() * (0x9fa5 - 0x4e00 + 1))));
		}
		return stringBuilder.toString();
	}

	/**
	 * 校验器
	 *
	 * @param code
	 * @param userInputCode
	 * @return
	 */
	@Override
	public boolean verify(String code, String userInputCode) {
		return StringUtils.equals(code, userInputCode);
	}
}
