Administrator
2022-09-14 58d006e05dcf2a20d0ec5367dd03d66a61db6849
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.mandi.system.utils;
 
import java.util.Random;
 
import com.google.code.kaptcha.text.TextProducer;
 
public class KaptchaTextutil implements TextProducer {
    
    private static int[] numarr={0,1,2,3,4,5,6,7,8,9};
    private static String[] operchar={"+","-","×"};
    @Override
    public String getText() {
        Random rd=new Random();
        int oper_R=rd.nextInt(operchar.length);
        String retStr="";
        String ff=operchar[oper_R];
        if(oper_R==0){
            retStr=numarr[rd.nextInt(numarr.length)]+ff+numarr[rd.nextInt(numarr.length)]+"=";
        }else if(oper_R==1){
            int aa=numarr[rd.nextInt(numarr.length)];
            int bb=aa+rd.nextInt((numarr.length-aa));
            retStr=numarr[bb]+ff+numarr[aa]+"=";
        }else{
            retStr=numarr[rd.nextInt(numarr.length)]+ff+numarr[rd.nextInt(numarr.length)]+"=";
        }
        return retStr;
    }
    
    
    public static int calculateNum(String code){
        if(code==null)
            return -1;
        if(code.length()!=4)
            return -1;
        int a=Integer.parseInt(code.substring(0, 1));
        String b=code.substring(1, 2);;
        int c=Integer.parseInt(code.substring(2, 3));
        if(operchar[0].equals(b)){
            return a+c;
        }else if(operchar[1].equals(b)){
            return a-c;
        }else{
            return a*c;
        }
    }
 
}