shikeyin
2024-01-11 65da8373531677b1c37a98f53eaa30c892f35e5a
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
package com.iplatform.base;
 
import com.iplatform.base.captcha.BlockPuzzleCaptchaProvider;
import com.iplatform.base.captcha.JigsawResult;
import com.iplatform.base.util.VerifyImgUtil;
import org.junit.Test;
 
import java.io.File;
import java.util.concurrent.TimeUnit;
 
public class TestCaptcha {
 
//    @Test
    public void testBlockPuzzle() throws Exception{
        BlockPuzzleCaptchaProvider puzzleCaptchaProvider = new BlockPuzzleCaptchaProvider();
        this.runBlockPuzzleOnce(puzzleCaptchaProvider, "001");
        TimeUnit.SECONDS.sleep(3);
        long startTime = System.nanoTime();
        this.runBlockPuzzleOnce(puzzleCaptchaProvider, "002");
        System.out.println("total times = " + (System.nanoTime() - startTime));
    }
 
    private void runBlockPuzzleOnce(BlockPuzzleCaptchaProvider puzzleCaptchaProvider, String filePrefix){
        JigsawResult result = (JigsawResult) puzzleCaptchaProvider.generateCaptcha(null);
        VerifyImgUtil.writeBase64ToFile(result.getImageSourceBase64(), new File("d:/tmp/" + filePrefix + "_src.png"));
        VerifyImgUtil.writeBase64ToFile(result.getImageBlockBase64(), new File("d:/tmp/" + filePrefix + "_block.png"));
        System.out.println(result.getX() + ", " + result.getY());
    }
}