Commit 19abad6b authored by 周健威's avatar 周健威

Merge branch 'master-tiande' into dev-tiande

parents f6adba71 96084202
...@@ -14,7 +14,13 @@ import org.apache.http.HttpResponse; ...@@ -14,7 +14,13 @@ import org.apache.http.HttpResponse;
import org.apache.http.StatusLine; import org.apache.http.StatusLine;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import sun.misc.BASE64Encoder;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -127,6 +133,22 @@ public class XCFQPictureParsingImpl implements UserPictureParsing { ...@@ -127,6 +133,22 @@ public class XCFQPictureParsingImpl implements UserPictureParsing {
return null; return null;
} }
//身份证照片解析
private String imageParseBase64(String imageUrl) {
Map<String, String> headers = new HashMap<String, String>();
headers.put("Authorization", "APPCODE " + appcode2);
Map<String, String> querys = new HashMap<String, String>();
Map<String, String> bodys = new HashMap<String, String>();
String imgUrlToBase64 = getImgUrlToBase64(imageUrl);
bodys.put("image", imgUrlToBase64);
try {
return callExternalRequest(headers,querys,bodys,1);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return null;
}
private String callExternalRequest(Map<String, String> headers, private String callExternalRequest(Map<String, String> headers,
Map<String, String> querys, Map<String, String> querys,
...@@ -154,4 +176,54 @@ public class XCFQPictureParsingImpl implements UserPictureParsing { ...@@ -154,4 +176,54 @@ public class XCFQPictureParsingImpl implements UserPictureParsing {
return null; return null;
} }
/**
* 将网络图片转换成Base64编码字符串
*
* @param imgUrl 网络图片Url
* @return
*/
public static String getImgUrlToBase64(String imgUrl) {
InputStream inputStream = null;
ByteArrayOutputStream outputStream = null;
byte[] buffer = null;
try {
// 创建URL
URL url = new URL(imgUrl);
// 创建链接
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5000);
inputStream = conn.getInputStream();
outputStream = new ByteArrayOutputStream();
// 将内容读取内存中
buffer = new byte[1024];
int len = -1;
while ((len = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, len);
}
buffer = outputStream.toByteArray();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (inputStream != null) {
try {
// 关闭inputStream流
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (outputStream != null) {
try {
// 关闭outputStream流
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
// 对字节数组Base64编码
return new BASE64Encoder().encode(buffer);
}
} }
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