1、验证码通过接口获取,接口返回为json,验证码为json中一个字段的值,该值为图片进行base64加密后的内容
返回值的形式如下:
{
"code": 200,
"msg": "",
"data": "iVBORw0KGgoAAAANSUhEUgAAAHgAAAAuCAYAAADjs904AAAQqUlEQVR4nOxcCVRUV5r+79tf7RRQBQKyKaiIG4pEUFGMW8yejmmnk57OMpme7qQ70+lMJst00pNJJ5M5WZxOOtOnpzOdM+N0Z1Gjxh1xQcUFFFlElFV2kKWgqt5++9xyw4CoBNFw+M5559Sr9x789333///v/+89xahNNQ0wihEL6lYbMIqbi1GCRzhGCR7hGCV4hGOU4BGOUYJHOEYJHuEYJXiEY5TgEY5Rgkc4rk3woXwOikrZYbFmFEOOAQnG6zaJ+Ad/H4wf/NvgANGj6AtNQ3h7joCf/scgPHW+G7/0hv1Wm9QbzIBXT1Wcv44xgmNFLMxOUYbJrtsfJ0pZ/OUGEW3JFqCjk770/edfifDK8x4wCfiW2ncBAxNsEi8b6fOjb172eCSqrLSBYRgaZsyMHvnkN7bQeO1GETZuE6CiKpC2erOIyOm9y/23C7nwbQiurW2n1/75sOnj3+ZYHvlBmnd8gluz2gTj5pl6i+CXEHy9XcDrt4hwpIADw+gz0cEVqqMVi/3w4N1+SIjXbomdV8E1CDZdIhj7fFTvkZUW1bMffpBtIZ9pmgJF0W+imcMLbBgIHTzKwtpNIs7eI4DX11eriIKBsjIl/MBdEkpPVYCibhuv7Y2BCTab+vXghvoO+jevb7SRz6lpcUpGZoIcHGL+7ntvVQ2DP/tKRJu2C7ipue+7QQjDrOkKuv8uPyxfLJFQ3Nedby8MSDAym41LDPt8gbH09MjUKy98YSckR0QG6XcunSzNSIlRh8PY6wYJo2u+FGHVg/5relaXh4L1WwT81WYRik6yABj1fqCK06ExItgYf+cyf8gjj/ioqDEDhmBd11HuwR38/Iyl0lANpz/UNbTTVbWtNM8zkDo9/qr65xoe3DsHS6i93Ud99P4Oy77d5bwosnjxsslS+rwE2e4QbzvvxTt2C4go/3de81yVZJ+E8NKHQ6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F8CVJnqED331QJDbEPObEXQdMMXrTgHn9dQw1DFPXsWZmy1WK/pd7b3SOhLzbkmQ4dq+BI5HpwxSz/8/+woicu2hVwiBvy4JuOugYadu7h8a59Ahw5xoGm9d84sdsMyEiTiVDDC+YqyDL41aIbhaZpqNPTTgEGcNiDjOESVwPhrf/cYN2Xd4pbed8d/nuXpEh22+XoensR3Bue7kDehuy9POzL46Gnp//NCUTJz5ymoIXzJFiyUIaw0JGzQfs6UdfQTgdW80LsfcZ++xLcG6qGcN5RDnbu5lFOLo8b+9mzDBfy9k+f6kHPPtUz7DbepvhuEPwN4NJyFm3fFSjByGeAXvvPo8dqaOeXNyUHfxfxnST4CjQ207B9N4+z9wpwto6GZ5/uQfcvH5ItMyMB332CRzEgRn/CYYTjrwEAAP//tgKSSeQYeI8AAAAASUVORK5CYII=",
"msgType": "success"
}
这个json中的data部分就是验证码进行base64加密后的内容
-
以图片形式保存验证码到本地
- 先用一个提取器,取出上述响应中的data,提取器任意,可以取出data的部分就可以了
- 添加一个BeanShell 后置处理程序,保存图片到本地D://code.png
使用的代码如下:
import org.apache.commons.codec.binary.Base64;
import java.io.*;
Base64 base64=new Base64();
byte[] data=base64.decode("${image}");
String file_name = "D://code.png"; //代表存放文件的位置和文件名,路径和文件名需要自定义,路径需要提前创建
File file = new File(file_name);
FileOutputStream out = new FileOutputStream(file);
out.write(data);
out.close();
vars.put("file_name",file_name);
-
对本地的图片进行加密
- 添加一个JSR223 后置处理程序,对上一步保存的图片进行加密
使用的代码如下:
import java.io.*;
import org.apache.commons.codec.binary.Base64;
String image=vars.get("file_name");
byte[] data = null;
try {
InputStream in = new FileInputStream(image);
data = new byte[in.available()];
in.read(data);
in.close();
} catch (IOException e) {
e.printStackTrace();
}
Base64 base64=new Base64();
vars.put("base64",base64.encodeToString(data));
加一个调试取样器,把上述的步骤运行一遍,会发现,变量base64等于image,因为这整个操作过程就是先把图片的base64解密保存为图片,然后再加密成base64,相当于转了一个圈圈
-
识别验证码
- 使用OcrServer工具进行识别
2、验证码通过接口获取,接口直接返回图片
返回的形式如下:
-
以图片形式保存验证码到本地
添加一个监听器-保存响应到文件,绿色的png是变量名,红色的图片保存的位置