1、生成中文字符串,主要是实现TextProducer
public class ChineseTextProducer implements TextProducer
{
privateString[] simplifiedChineseTexts=newString[]{
"包括焦点","新道消点","服分目搜","索姓名電","子郵件信","主旨請回","電子郵件","給我所有","討論區明","發表新文","章此討論","區所有文","章回主題",
"樹瀏覽搜"
};
/**
*@returnrandom Chinese text
*/
publicStringgetText()
{
returnsimplifiedChineseTexts[newRandom().nextInt(simplifiedChineseTexts.length)];
}
}
2、第二步是应用自定义的ChineseTextProducer
properties.setProperty("kaptcha.textproducer.impl","包名ChineseTextProducer ");
3、自己实现的数字相加的验证码
import com.google.code.kaptcha.text.TextProducer;
import java.util.Random;
public class ArithmeticTextProducerimplements TextProducer {
private int[]simplifiedNumber =new int[]{
0,1,2,3,4,5,6,7,8,9
};
private StringcreateNumberText(){
return Integer.toString(simplifiedNumber[new Random().nextInt(simplifiedNumber.length)]);
}
public StringgetText(){
return createNumberText()+"+"+createNumberText()+"=?";
}
}