国税局验证码识别Java版

国税局验证码识别方法

在之前的博客中,我已经提供了国税局验证码识别的思路,但是很多小伙伴还是私信说自己用crnn还是训练不出来,我也表示很无奈。可以通过下面的代码白嫖哦。这个代码值还是之前的代码,还是熟悉的感觉吧。

请使用post,get不返回数据。

验证码识别

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Base64;


public class CaptchaRecognize {
     
    static String captcha_url = "http://ai1024.xyz:8808/captcha";

    public static String getBase64(String imgFile) {
     
        InputStream inputStream = null;
        byte[] data = null;
        try {
     
            inputStream = new FileInputStream(imgFile);
            data = new byte[inputStream.available()];
            inputStream.read(data);
            inputStream.close();

        } catch (IOException e) {
     
            e.printStackTrace();
        }
        Base64.Encoder encoder = Base64.getEncoder();
        assert data != null;
        return encoder.encodeToString(data);
    }

    public static void captchaPost() throws IOException {
     
        String imgBase64 = getBase64("./imgs/img001.jpg");
        String data = "{" + "\"image\":" + "\"" + imgBase64 + "\"" + "," + "\"key\":" + "\"03\"" + "}";
        URL url = new URL(captcha_url);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("POST");
        conn.setDoOutput(true);
        conn.setDoInput(true);
        conn.setRequestProperty("Content-Type", "application/json");
        conn.setRequestProperty("Accept", "application/json");
        OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream());
        out.write(data);
        out.flush();
        out.close();
        BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
        String line;
        while ((line = in.readLine()) != null) {
     
            System.out.println(line); // {"code": "Y2W"}
        }
    }
    public static void main(String[] args) throws IOException {
     
        captchaPost();
    }
}

你可能感兴趣的:(验证码识别,国税局验证码识别,深度学习)