国家税务总局全国增值税发票查验平台验证码
查验验证码图片如下面所示:
1.验证码识别Python版
import base64
import requests
with open('./tmp.jpg', 'rb') as f:
img_bytes = f.read()
img_base64 = base64.b64encode(img_bytes)
data = {'image': str(img_base64, 'utf-8'), 'key': '01'}
result = requests.post('http://47.99.174.98:8808/captcha', json=data)
print(result.text)
print(result.json())
2.验证码识别Java版
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Base64;
public class CaptchaRecognize {
static String captcha_url = "http://47.99.174.98: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);
}
}
public static void main(String[] args) throws IOException {
captchaPost();
}
}
3.免验证码发票查验Python版
import requests
data = {'fpdm': '044001505121', 'fphm': '38507145', 'rq': '20180926', 'jym': '865375'}
result = requests.post('http://47.99.174.98:8808/fp', json=data)
print(result.json())