From 1a01c2887f916c9d4b784bd4b1284ec354c25857 Mon Sep 17 00:00:00 2001 From: mjkhan21 Date: Wed, 30 Oct 2024 16:15:08 +0900 Subject: [PATCH] =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EB=8B=A4=EC=9A=B4?= =?UTF-8?q?=EB=A1=9C=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 5 + .../cokr/xit/interfaces/saeol/SOHNN00011.java | 10 +- .../saeol/service/bean/Configuration.java | 19 +- .../saeol/service/bean/EPeople.java | 271 +++++++++++------- .../saeol/service/bean/EPeople2.java | 164 +++++++++++ .../saeol/service/bean/MinwonBean.java | 106 ++----- src/main/resources/intf-conf/xit-saeol.conf | 4 + src/main/resources/xit-crypto.conf | 13 + .../interfaces/saeol/SaeolMessageTest.java | 16 +- 9 files changed, 415 insertions(+), 193 deletions(-) create mode 100644 src/main/java/cokr/xit/interfaces/saeol/service/bean/EPeople2.java create mode 100644 src/main/resources/xit-crypto.conf diff --git a/pom.xml b/pom.xml index 5ec0ccf..4cb4ee0 100644 --- a/pom.xml +++ b/pom.xml @@ -51,6 +51,11 @@ xit-file 23.04.01-SNAPSHOT + + cokr.xit.base + xit-crypto + 23.04.01-SNAPSHOT + cokr.xit.interfaces diff --git a/src/main/java/cokr/xit/interfaces/saeol/SOHNN00011.java b/src/main/java/cokr/xit/interfaces/saeol/SOHNN00011.java index 9b8e179..c58521e 100644 --- a/src/main/java/cokr/xit/interfaces/saeol/SOHNN00011.java +++ b/src/main/java/cokr/xit/interfaces/saeol/SOHNN00011.java @@ -15,6 +15,7 @@ import lombok.Setter; public class SOHNN00011 extends SaeolMessage { public static final String INF_TYPE = "011"; + private ArrayList fileInfos; private ArrayList converted; @@ -110,6 +111,13 @@ public class SOHNN00011 extends SaeolMessage { public List getFileinfo_p() { return ifEmpty(fileinfo_p, Collections::emptyList); } + + public List getAllFileinfo() { + ArrayList fileinfo = new ArrayList<>(); + fileinfo.addAll(getFileinfo_m()); + fileinfo.addAll(getFileinfo_p()); + return fileinfo; + } } @Getter @@ -256,7 +264,7 @@ public class SOHNN00011 extends SaeolMessage { private String pre_minwon_yn; public String infoKey() { - return getCnsl_qna_no() + "-" + getMsg_key(); + return getCnsl_qna_no(); // + "-" + getMsg_key(); } } diff --git a/src/main/java/cokr/xit/interfaces/saeol/service/bean/Configuration.java b/src/main/java/cokr/xit/interfaces/saeol/service/bean/Configuration.java index fe780a3..2764658 100644 --- a/src/main/java/cokr/xit/interfaces/saeol/service/bean/Configuration.java +++ b/src/main/java/cokr/xit/interfaces/saeol/service/bean/Configuration.java @@ -30,7 +30,12 @@ public class Configuration extends AbstractComponent { sido, sigungu, logXml, - attachmentDir; + attachmentDir, + + k_anc_code, + k_anc_id, + k_anc_passwd; + private List deptCodes; private boolean logToDatabase; @@ -66,6 +71,18 @@ public class Configuration extends AbstractComponent { return conf.attachmentDir; } + public static String k_anc_code() { + return conf.k_anc_code; + } + + public static String k_anc_id() { + return conf.k_anc_id; + } + + public static String k_anc_passwd() { + return conf.k_anc_passwd; + } + public static List sources() { return ifEmpty(conf.sources, Collections::emptyList); } diff --git a/src/main/java/cokr/xit/interfaces/saeol/service/bean/EPeople.java b/src/main/java/cokr/xit/interfaces/saeol/service/bean/EPeople.java index f8ce993..e519089 100644 --- a/src/main/java/cokr/xit/interfaces/saeol/service/bean/EPeople.java +++ b/src/main/java/cokr/xit/interfaces/saeol/service/bean/EPeople.java @@ -14,28 +14,33 @@ import java.net.URI; import java.net.URLConnection; import java.net.http.HttpClient; import java.net.http.HttpResponse; +import java.util.ArrayList; import java.util.Date; +import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.function.Function; import javax.imageio.ImageIO; +import cokr.xit.base.crypto.Cryptography; +import cokr.xit.base.crypto.bean.XitAria; import cokr.xit.base.file.FileInfo; import cokr.xit.foundation.AbstractComponent; +import cokr.xit.foundation.data.DataObject; import cokr.xit.foundation.util.DateFormats; import cokr.xit.foundation.web.WebClient; +import cokr.xit.interfaces.saeol.SOHNN00011; public class EPeople extends AbstractComponent { - private static String HOST = "https://www.epeople.go.kr"; - - public static boolean supports(String url) { - return url.contains(HOST); - } + protected static String HOST = "https://www.epeople.go.kr"; + private static XitAria crypto = ((XitAria)Cryptography.get("xit-aria")) + .setKey(new String(new byte[] {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F})); private WebClient webClient; private CookieHandler cookies; - private WebClient hclient() throws Exception { + protected WebClient hclient() throws Exception { if (webClient == null) { CookieManager cm = new CookieManager(); cm.setCookiePolicy(CookiePolicy.ACCEPT_ALL); @@ -50,21 +55,39 @@ public class EPeople extends AbstractComponent { return webClient; } - public FileInfo download(String filepath, String phoneNo) { + public List download(SOHNN00011.Resp00011 resp) { + SOHNN00011.Item item = resp.getResult(); + List fileItems = resp.getAllFileinfo(); + + List files = download(item.getMw_org_code(), item.getInet_qna_no()); + files.forEach(fileInfo -> { + String filename = fileInfo.getName(); + Optional match = fileItems.stream() + .filter(fileItem -> filename.equals(fileItem.getSys_file_nm())).findFirst(); + match.ifPresent(fileItem -> { + String file_type = fileItem.getFile_type(); + fileInfo + .setSubType(file_type) + .setSubCode("M".equals(file_type) ? fileItem.getFile_id_m() : fileItem.getFile_id_p()); + }); + }); + + return files; + } + + public List download(String mw_org_code, String inet_qna_no) { try { - Info info = getInfo(filepath); + Info info = getInfo(mw_org_code, inet_qna_no); - addCookie("fileDownloadToken", "TRUE"); addCookie("XSRF-TOKEN", info.csrf); -// compare(info, phoneNo); return download(info); } catch (Exception e) { throw runtimeException(e); } } - private void addCookie(String name, String value) throws Exception { + protected void addCookie(String name, String value) throws Exception { HttpCookie cookie = new HttpCookie(name, value); cookie.setPath("/"); cookie.setVersion(1); @@ -72,76 +95,83 @@ public class EPeople extends AbstractComponent { ((CookieManager)cookies).getCookieStore().add(new URI(HOST), cookie); } - private Info getInfo(String url) throws Exception { + private static Map commonParams = Map.of( + "k_anc_code", crypto.encrypt(Configuration.k_anc_code()), + "k_anc_id", crypto.encrypt(Configuration.k_anc_id()), + "k_anc_passwd", crypto.encrypt(Configuration.k_anc_passwd()) + ); + + private Info getInfo(String mw_org_code, String inet_qna_no) throws Exception { + String url = HOST + ":8055/jsp/other/ic/local/AIcDecryptExtPetiFileList.jsp"; HttpResponse hresp = hclient().get(req -> req.uri(url.replace("http://www.epeople.go.kr", HOST)) .noCache() - ); - Info info = Info.parse(hresp.body()); - log().debug("EPeople.Info:\n{}", info.toString().replace(", ", "\n")); - return info; - } + .data(commonParams) + .data("k_local_anc_code_v", crypto.encrypt(mw_org_code.trim())) + .data("k_local_peti_no_c", crypto.encrypt(inet_qna_no.trim())) - private void compare(Info info, String phoneNo) throws Exception { - HttpResponse hresp = hclient().post(req -> - req.uri(HOST + "/paid/syscmmn/fileDwldCompare.npaid") - .noCache() - .contentType(WebClient.Request.ContentType.FORM) - .header("Accept", "application/json, text/javascript, */*; q=0.01") - .header("X-Requested-With", "XMLHttpRequest") - .header("AJAX", "true") - .header("X-CSRF-TOKEN", info.csrf) - - .data(info.asParams()) - .data("encryptValue", phoneNo) ); - System.out.println(hresp.body()); + return Info.parse(hresp.body()); } - private FileInfo download(Info info) throws Exception { - HttpResponse hresp = hclient().post(req -> - req.uri(HOST + "/paid/syscmmn/fileDwld.npaid") - .noCache() - .contentType(WebClient.Request.ContentType.FORM) - .header("X-CSRF-TOKEN", info.csrf) + private ArrayList download(Info info) throws Exception { + String url = HOST + ":8055/paid/syscmmn/fileDwldForCntc.npaid"; + Function getFileInfo = download -> { + try { + HttpResponse hresp = hclient().post(req -> + req.uri(url) + .noCache() + .contentType(WebClient.Request.ContentType.FORM) - .data(info.asParams()) + .data(info.common) + .data(download.asParams().set("_csrf", info.csrf)) - .download(true) - ); - InputStream downloaded = hresp.body(); - if (WebClient.Request.SUCCESS != hresp.statusCode()) { - if (info.retry()) { - log().debug("Retrying to download the attachment"); - return download(info); - } - - log().debug(hclient().toString(downloaded).trim()); - return null; - } + .download(true) + ); + InputStream downloaded = hresp.body(); + if (WebClient.Request.SUCCESS != hresp.statusCode()) { + log().debug(hclient().toString(downloaded).trim()); + return null; + } - String filename = info.filename; - Optional header = hresp.headers().firstValue("content-length"); - long length = header.isPresent() ? Long.parseLong(header.get()) : 0; + String filename = download.filename; + Optional header = hresp.headers().firstValue("content-length"); + long length = header.isPresent() ? Long.parseLong(header.get()) : 0; - FileInfo fileInfo = new FileInfo(); - fileInfo.setName(filename); - fileInfo.setInputStream(downloaded); + FileInfo fileInfo = new FileInfo(); + fileInfo.setName(filename); + fileInfo.setInputStream(downloaded); - String mimeType = URLConnection.guessContentTypeFromName(filename); - if (isEmpty(mimeType)) - mimeType = URLConnection.guessContentTypeFromStream(downloaded); - fileInfo.setMimeType(mimeType); + String mimeType = URLConnection.guessContentTypeFromName(filename); + if (isEmpty(mimeType)) + mimeType = URLConnection.guessContentTypeFromStream(downloaded); + fileInfo.setMimeType(mimeType); - if (length > 0) - fileInfo.setSize(length); + if (length > 0) + fileInfo.setSize(length); - log().debug("{} downloaded", filename); + log().debug("{} downloaded", filename); - return fileInfo; + return fileInfo; + } catch (Exception e) { + throw runtimeException(e); + } + }; + + ArrayList result = new ArrayList<>(); + for (Download download: info.downloads) { + FileInfo fileInfo = getFileInfo.apply(download); + if (fileInfo == null && download.retry()) + fileInfo = getFileInfo.apply(download); + if (fileInfo != null) { + fileInfo.setSortOrder(result.size() + 1); + result.add(fileInfo); + } + } + return result; } - private static String parseValue(String body, String head, String tail) { + protected static String parseValue(String body, String head, String tail) { int start = body.indexOf(head); if (start < 0) return ""; @@ -204,51 +234,92 @@ public class EPeople extends AbstractComponent { } } - public static class Info { - private String - csrf, - atchFileGrpId, - atchFileId, - oldAtchFileId, - doc_id, - filename; - private int attempt = 1; + private static class Download { + static Download parse(int start, String str) { + String token = "doSubmit('"; + int pos = str.indexOf(token, start); + if (pos < 0) return null; - public static Info parse(String str) { - Info info = new Info(); + pos += token.length(); - info.csrf = parseValue(str, "\"_csrf\" content=\"", "\"").trim(); - info.atchFileGrpId = parseValue(str, "atchFileGrpId\" value=\"", "\"").trim(); - info.atchFileId = parseValue(str, "atchFileId\" value=\"", "\"").trim(); - info.oldAtchFileId = parseValue(str, "oldAtchFileId\" value=\"", "\"").trim(); - info.doc_id = parseValue(str, "doc_id\" value=\"", "\"").trim(); - info.filename = parseValue(str, "filename\" value=\"", "\"").trim(); + token = ","; + int end = str.indexOf(token, pos); + if (end < 0) return null; - return info; + Download download = new Download(); + download.fileId = str.substring(pos, end); + + token = ",'"; + pos = str.indexOf(token, end); + if (pos > -1) { + pos += token.length(); + token = "')"; + end = str.indexOf(token, pos); + download.fileGrpId = str.substring(pos, end); + } + + token = ""; + pos = str.indexOf(token, end); + if (pos > -1) { + pos += token.length(); + token = ""; + end = str.indexOf(token, pos); + download.filename = str.substring(pos, end); + } + download.next = ++end; + + return download; } - public Map asParams() { - return Map.of( - "atchFileGrpId", atchFileGrpId, - "atchFileId", atchFileId, - "oldAtchFileId", "oldAtchFileId", - "doc_id", doc_id, - "filename", filename, - "_csrf", csrf - ); + private String + fileGrpId, + fileId, + filename; + private int + next, + attempt = 1; + + DataObject asParams() { + return new DataObject() + .set("atchFileGrpId", fileGrpId) + .set("atchFileId", fileId); } - public boolean retry() { - ++attempt; - return attempt < 6; + boolean retry() { + return ++attempt < 6; } + } - @Override - public String toString() { - return String.format( - "csrf: %s, atchFileGrpId: %s, atchFileId: %s, oldAtchFileId: %s, doc_id: %s, filename: %s", - csrf, atchFileGrpId, atchFileId, oldAtchFileId, doc_id, filename - ); + private static class Info { + private DataObject common = new DataObject(); + private String csrf; + private ArrayList downloads = new ArrayList<>(); + + static Info parse(String body) { + log(EPeople2.class).debug(body); + Info info = new Info(); + + info.csrf = parseValue(body, "\"_csrf\" content=\"", "\"").trim(); + info.common + .set("k_local_anc_code_v", parseValue(body, "k_local_anc_code_v : \"", "\",")) + .set("k_local_peti_no_c", parseValue(body, "k_local_peti_no_c :\"", "\",")) + .set("k_anc_code", parseValue(body, "k_anc_code : \"", "\",")) + .set("k_anc_id", parseValue(body, "k_anc_id : \"", "\",")) + .set("k_anc_passwd", parseValue(body, "k_anc_passwd : \"", "\",")); + + int start = 0; + while (start > -1) { + Download download = Download.parse(start, body); + if (download == null) { + start = -1; + break; + } + + info.downloads.add(download); + start = download.next; + } + + return info; } } } \ No newline at end of file diff --git a/src/main/java/cokr/xit/interfaces/saeol/service/bean/EPeople2.java b/src/main/java/cokr/xit/interfaces/saeol/service/bean/EPeople2.java new file mode 100644 index 0000000..d9757b2 --- /dev/null +++ b/src/main/java/cokr/xit/interfaces/saeol/service/bean/EPeople2.java @@ -0,0 +1,164 @@ +package cokr.xit.interfaces.saeol.service.bean; + +import java.io.InputStream; +import java.net.URLConnection; +import java.net.http.HttpResponse; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import cokr.xit.base.file.FileInfo; +import cokr.xit.foundation.web.WebClient; +import cokr.xit.interfaces.saeol.SOHNN00011; + +public class EPeople2 extends EPeople { + @Override + public List download(SOHNN00011.Resp00011 resp) { + SOHNN00011.Item item = resp.getResult(); + String phoneNo = ifEmpty(item.getTelno_m(), item::getHpno_m); + + return resp.getAllFileinfo().stream() + .map(file -> { + FileInfo fileInfo = downloadFrom(file.getFile_path(), phoneNo); + if (fileInfo != null) { + String file_type = file.getFile_type(); + fileInfo.setSubType(file_type); + fileInfo.setSubCode("M".equals(file_type) ? file.getFile_id_m() : file.getFile_id_p()); + } + return fileInfo; + }) + .filter(fileInfo -> fileInfo != null) + .toList(); + } + + public FileInfo downloadFrom(String filepath, String phoneNo) { + try { + Info info = getInfo(filepath); + + addCookie("fileDownloadToken", "TRUE"); + addCookie("XSRF-TOKEN", info.csrf); + +// compare(info, phoneNo); + return download(info); + } catch (Exception e) { + throw runtimeException(e); + } + } + + private Info getInfo(String url) throws Exception { + HttpResponse hresp = hclient().get(req -> + req.uri(url.replace("http://www.epeople.go.kr", HOST)) + .noCache() + ); + Info info = Info.parse(hresp.body()); + log().debug("EPeople.Info:\n{}", info.toString().replace(", ", "\n")); + return info; + } + + private void compare(Info info, String phoneNo) throws Exception { + HttpResponse hresp = hclient().post(req -> + req.uri(HOST + "/paid/syscmmn/fileDwldCompare.npaid") + .noCache() + .contentType(WebClient.Request.ContentType.FORM) + .header("Accept", "application/json, text/javascript, */*; q=0.01") + .header("X-Requested-With", "XMLHttpRequest") + .header("AJAX", "true") + .header("X-CSRF-TOKEN", info.csrf) + + .data(info.asParams()) + .data("encryptValue", phoneNo) + ); + log().debug(hresp.body()); + } + + private FileInfo download(Info info) throws Exception { + HttpResponse hresp = hclient().post(req -> + req.uri(HOST + "/paid/syscmmn/fileDwld.npaid") + .noCache() + .contentType(WebClient.Request.ContentType.FORM) + .header("X-CSRF-TOKEN", info.csrf) + + .data(info.asParams()) + + .download(true) + ); + InputStream downloaded = hresp.body(); + if (WebClient.Request.SUCCESS != hresp.statusCode()) { + if (info.retry()) { + log().debug("Retrying to download the attachment"); + return download(info); + } + + log().debug(hclient().toString(downloaded).trim()); + return null; + } + + String filename = info.filename; + Optional header = hresp.headers().firstValue("content-length"); + long length = header.isPresent() ? Long.parseLong(header.get()) : 0; + + FileInfo fileInfo = new FileInfo(); + fileInfo.setName(filename); + fileInfo.setInputStream(downloaded); + + String mimeType = URLConnection.guessContentTypeFromName(filename); + if (isEmpty(mimeType)) + mimeType = URLConnection.guessContentTypeFromStream(downloaded); + fileInfo.setMimeType(mimeType); + + if (length > 0) + fileInfo.setSize(length); + + log().debug("{} downloaded", filename); + + return fileInfo; + } + + public static class Info { + private String + csrf, + atchFileGrpId, + atchFileId, + oldAtchFileId, + doc_id, + filename; + private int attempt = 1; + + public static Info parse(String str) { + Info info = new Info(); + + info.csrf = parseValue(str, "\"_csrf\" content=\"", "\"").trim(); + info.atchFileGrpId = parseValue(str, "atchFileGrpId\" value=\"", "\"").trim(); + info.atchFileId = parseValue(str, "atchFileId\" value=\"", "\"").trim(); + info.oldAtchFileId = parseValue(str, "oldAtchFileId\" value=\"", "\"").trim(); + info.doc_id = parseValue(str, "doc_id\" value=\"", "\"").trim(); + info.filename = parseValue(str, "filename\" value=\"", "\"").trim(); + + return info; + } + + public Map asParams() { + return Map.of( + "atchFileGrpId", atchFileGrpId, + "atchFileId", atchFileId, + "oldAtchFileId", "oldAtchFileId", + "doc_id", doc_id, + "filename", filename, + "_csrf", csrf + ); + } + + public boolean retry() { + ++attempt; + return attempt < 6; + } + + @Override + public String toString() { + return String.format( + "csrf: %s, atchFileGrpId: %s, atchFileId: %s, oldAtchFileId: %s, doc_id: %s, filename: %s", + csrf, atchFileGrpId, atchFileId, oldAtchFileId, doc_id, filename + ); + } + } +} \ No newline at end of file diff --git a/src/main/java/cokr/xit/interfaces/saeol/service/bean/MinwonBean.java b/src/main/java/cokr/xit/interfaces/saeol/service/bean/MinwonBean.java index 57ba3e0..5e3bd57 100644 --- a/src/main/java/cokr/xit/interfaces/saeol/service/bean/MinwonBean.java +++ b/src/main/java/cokr/xit/interfaces/saeol/service/bean/MinwonBean.java @@ -2,7 +2,6 @@ package cokr.xit.interfaces.saeol.service.bean; import java.io.File; import java.util.ArrayList; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -13,15 +12,17 @@ import org.springframework.stereotype.Component; import cokr.xit.base.file.FileInfo; import cokr.xit.base.file.service.bean.FileBean; +import cokr.xit.foundation.data.DataObject; import cokr.xit.interfaces.saeol.SOHNN00004; import cokr.xit.interfaces.saeol.SOHNN00011; @Component("minwonBean") @Scope("prototype") public class MinwonBean extends SaeolBean { - private EPeople epeople = new EPeople(); @Resource(name = "fileBean") private FileBean fileBean; + private EPeople epeople = new EPeople(); + private EPeople2 epeople2 = new EPeople2(); public MinwonBean() { log().debug("MinwonBean created"); @@ -37,9 +38,9 @@ public class MinwonBean extends SaeolBean { if (resp00004.error()) return resp00004.getFault().toMap(); - LinkedHashMap result = new LinkedHashMap<>(); - result.put("success", true); - result.put("minwonsReceived", resp00004.getResult().size()); + DataObject result = new DataObject() + .set("success", true) + .set("minwonsReceived", resp00004.getResult().size()); resp00004.getResult().stream() .map(item -> { @@ -57,23 +58,7 @@ public class MinwonBean extends SaeolBean { sohnn00011.getConverted().forEach(File::delete); }); -/* - .forEach(sohnn00011 -> { - List files = sohnn00011.getFileInfos(); - if (Configuration.logToDatabase()) - fileBean.create(files); - else - epeople.write(files); - sohnn00011.getConverted().forEach(File::delete); - }); - - for (SOHNN00004.Item item: resp00004.getResult()) { - String cnsl_qna_no = item.getCnsl_qna_no(); - SOHNN00011 sohnn00011 = getSOHNN00011(cnsl_qna_no, item.getDetail()); - result.put(cnsl_qna_no, !sohnn00011.getResponse().error() ? "success" : "fail"); - } -*/ return result; } @@ -123,79 +108,32 @@ public class MinwonBean extends SaeolBean { if (affected > 0) log(msg); - if (SOHNN00004.Item.GET.equals(detail)) { - String phoneNo = ifEmpty(result.getTelno_m(), result::getHpno_m); - FileInfo.Relation relation = new FileInfo.Relation() - .setInfoType(SOHNN00011.INF_TYPE) - .setInfoKey(result.infoKey()); - - create(msg, relation, phoneNo, resp.getFileinfo_m()); - create(msg, relation, phoneNo, resp.getFileinfo_p()); -// create(relation, phoneNo, resp.getFileinfo_m()); -// create(relation, phoneNo, resp.getFileinfo_p()); - } + if (SOHNN00004.Item.GET.equals(detail)) + downloadFiles(msg); return resp; } - private void create(SOHNN00011 msg, FileInfo.Relation relation, String phoneNo, List fileItems) { - ArrayList converted = new ArrayList<>(); - - List files = fileItems.stream() - .map(fileItem -> { - FileInfo fileInfo = epeople.download(fileItem.getFile_path(), phoneNo); - if (fileInfo == null) return null; - - relation.setInfo(fileInfo); - String file_type = fileItem.getFile_type(); - fileInfo.setSubType(file_type); - fileInfo.setSubCode("M".equals(file_type) ? fileItem.getFile_id_m() : fileItem.getFile_id_p()); - fileInfo.setSortOrder(fileItem.getFile_seq()); - - File jpg = epeople.pngToJpg(fileInfo); - if (jpg != null) - converted.add(jpg); + private void downloadFiles(SOHNN00011 msg) { + SOHNN00011.Resp00011 resp = msg.getResponse(); + SOHNN00011.Item result = resp.getResult(); + FileInfo.Relation relation = new FileInfo.Relation() + .setInfoType(SOHNN00011.INF_TYPE) + .setInfoKey(result.infoKey()); - return fileInfo; - }) - .filter(fileInfo -> fileInfo != null) - .toList(); + ArrayList converted = new ArrayList<>(); + List files = ifEmpty(epeople.download(resp), () -> epeople2.download(resp)); + files.forEach(fileInfo -> { + relation.setInfo(fileInfo); + File jpg = epeople.pngToJpg(fileInfo); + if (jpg != null) + converted.add(jpg); + }); msg.addFileInfos(files); msg.addConverted(converted); } - private void create(FileInfo.Relation relation, String phoneNo, List fileItems) { - ArrayList converted = new ArrayList<>(); - - List files = fileItems.stream() - .map(fileItem -> { - FileInfo fileInfo = epeople.download(fileItem.getFile_path(), phoneNo); - if (fileInfo == null) return null; - - relation.setInfo(fileInfo); - String file_type = fileItem.getFile_type(); - fileInfo.setSubType(file_type); - fileInfo.setSubCode("M".equals(file_type) ? fileItem.getFile_id_m() : fileItem.getFile_id_p()); - fileInfo.setSortOrder(fileItem.getFile_seq()); - - File jpg = epeople.pngToJpg(fileInfo); - if (jpg != null) - converted.add(jpg); - - return fileInfo; - }) - .filter(fileInfo -> fileInfo != null) - .toList(); - - if (Configuration.logToDatabase()) - fileBean.create(files); - else - epeople.write(files); - - converted.forEach(File::delete); - } - public int updateSOHNN00011(String[] cnsl_qna_nos, String[] msg_keys) { return saeolMapper.updateSOHNN00011(cnsl_qna_nos, msg_keys); } diff --git a/src/main/resources/intf-conf/xit-saeol.conf b/src/main/resources/intf-conf/xit-saeol.conf index d37d514..7078c53 100644 --- a/src/main/resources/intf-conf/xit-saeol.conf +++ b/src/main/resources/intf-conf/xit-saeol.conf @@ -5,6 +5,10 @@ "sigungu": "", /* 시군구 코드 */ "deptCodes": ["부서코드"], /* 부서코드 */ + "k_anc_code": "3150000", /* 기관코드 */ + "k_anc_id": "SU44526786720", /* 연계 ID */ + "k_anc_passwd": "ZUDDN1129404", /* 연계 비밀번호 */ + "logXml": "files/xml/{date}/{interfaceID}/{msgKey}.xml", /* xml 로그파일 이름 패턴, 로그파일을 남기지 않으려면 제거할 것 */ "logToDatabase": true, /* 전문 데이터베이스 사용 여부 */ "attachmentDir": "files/attachment/{date}", /* 첨부파일 디렉토리 경로 패턴, 전문 데이터베이스를 사용하지 않을 경우에만 유효 */ diff --git a/src/main/resources/xit-crypto.conf b/src/main/resources/xit-crypto.conf new file mode 100644 index 0000000..0158b7d --- /dev/null +++ b/src/main/resources/xit-crypto.conf @@ -0,0 +1,13 @@ +{ "enabled": true, + "cryptoDefs": [ + { "name": "xit-aria", + "class": "cokr.xit.base.crypto.bean.XitAria", + "settings": { + "version": 1, + "charset": "EUC-KR", + "key": "3AsrGqpYYnkHIu3D", + "keySize": 128 + } + } + ] +} \ No newline at end of file diff --git a/src/test/java/cokr/xit/interfaces/saeol/SaeolMessageTest.java b/src/test/java/cokr/xit/interfaces/saeol/SaeolMessageTest.java index 32b7aff..38e1af0 100644 --- a/src/test/java/cokr/xit/interfaces/saeol/SaeolMessageTest.java +++ b/src/test/java/cokr/xit/interfaces/saeol/SaeolMessageTest.java @@ -16,6 +16,7 @@ import cokr.xit.foundation.test.TestSupport; import cokr.xit.interfaces.saeol.dao.SaeolMapper; import cokr.xit.interfaces.saeol.service.bean.Configuration; import cokr.xit.interfaces.saeol.service.bean.EPeople; +import cokr.xit.interfaces.saeol.service.bean.EPeople2; import cokr.xit.interfaces.saeol.service.bean.SaeolMessenger; import cokr.xit.interfaces.saeol.service.bean.XmlSupport; @@ -149,6 +150,13 @@ public class SaeolMessageTest extends TestSupport { @Test void download() { EPeople epeople = new EPeople(); + List files = epeople.download("1741000", "SPP-2410-2802194 "); + epeople.write(files); + } + + @Test + void download2() { + EPeople2 epeople = new EPeople2(); String head = "http://www.epeople.go.kr/FileDownload.do?file=/attach19/nep/eai/"; List files = List.of( "2024/10/2/20241002121001397388301&filename=20241002_1_7e23810479054b1ea6ee25246908eb2c.jpg", @@ -157,17 +165,11 @@ public class SaeolMessageTest extends TestSupport { "2024/9/5/20240905020909019918103&filename=20240905_40cabda891fb4e2895c8964d000604b1_MAPIMG.png" ).stream() .map(str -> head + str) - .map(url -> epeople.download(url, null)) + .map(url -> epeople.downloadFrom(url, null)) .toList(); epeople.write(files); } - @Test - void download2() { -// EPeople2 epeople = new EPeople2(); -// epeople.download(null, null); - } - private void write(FileInfo fileInfo) { if (fileInfo == null) return;