Commit 1416a0ea authored by 黎博's avatar 黎博

修复jar包里获取不到文件

parent 983bab95
...@@ -8,22 +8,24 @@ import com.alibaba.fastjson.JSON; ...@@ -8,22 +8,24 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ResourceUtils; import org.springframework.core.io.ClassPathResource;
import springfox.documentation.spring.web.json.Json;
import java.io.*; import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@Slf4j @Slf4j
public class Vcc { public class Vcc {
public static String readTxt(File file) throws IOException { public static String readTxt(String file) throws IOException {
String str = ""; String str = "";
InputStreamReader in = new InputStreamReader(new FileInputStream(file), "UTF-8"); ClassPathResource resource = new ClassPathResource(file);
BufferedReader br = new BufferedReader(in); InputStream in = resource.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(in));
StringBuffer content = new StringBuffer(); StringBuffer content = new StringBuffer();
while ((str=br.readLine()) != null) { while ((str=br.readLine()) != null) {
content = content.append(str); content = content.append(str);
...@@ -95,7 +97,7 @@ public class Vcc { ...@@ -95,7 +97,7 @@ public class Vcc {
map.put("msg", "OCR获取成功"); map.put("msg", "OCR获取成功");
map.put("name", "张三"); map.put("name", "张三");
map.put("sex", "男"); map.put("sex", "男");
String frontBase64Str = Vcc.readTxt(ResourceUtils.getFile("classpath:front.txt")); String frontBase64Str = Vcc.readTxt("front.txt");
map.put("base64Str", frontBase64Str); map.put("base64Str", frontBase64Str);
params.put("idCard", JSON.toJSONString(map)); params.put("idCard", JSON.toJSONString(map));
JSONObject result = HttpClientUtils.doPost(url, params, headers); JSONObject result = HttpClientUtils.doPost(url, params, headers);
...@@ -124,7 +126,7 @@ public class Vcc { ...@@ -124,7 +126,7 @@ public class Vcc {
map.put("type", "xyqb"); map.put("type", "xyqb");
map.put("warning", "00010000"); map.put("warning", "00010000");
map.put("multiWarning", "00010000"); map.put("multiWarning", "00010000");
String backBase64Str = Vcc.readTxt(ResourceUtils.getFile("classpath:back.txt")); String backBase64Str = Vcc.readTxt("back.txt");
map.put("base64Str", backBase64Str); map.put("base64Str", backBase64Str);
params.put("idCard", JsonTransUtils.mapToJson(map)); params.put("idCard", JsonTransUtils.mapToJson(map));
JSONObject result = HttpClientUtils.doPost(url, params, headers); JSONObject result = HttpClientUtils.doPost(url, params, headers);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment