From 049270ae151490ce45b2d9a695a88866fd1de966 Mon Sep 17 00:00:00 2001 From: lvleigang <957075182@qq.com> Date: Fri, 27 Jun 2025 17:08:48 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BA=E8=AF=BA=E5=8F=91=E7=A5=A8=E5=9B=9E?= =?UTF-8?q?=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../frame/seeyon/entity/CtpFileEntity.xml | 2 +- .../seeyon/entity/NuoNuoCallbackEntity.xml | 2 +- .../impl/NuoNuoCallbackServiceImpl.java | 102 +++++++++++++++++- 3 files changed, 99 insertions(+), 7 deletions(-) diff --git a/fw-oa/src/main/java/com/hzya/frame/seeyon/entity/CtpFileEntity.xml b/fw-oa/src/main/java/com/hzya/frame/seeyon/entity/CtpFileEntity.xml index c24e8a24..d3d5b840 100644 --- a/fw-oa/src/main/java/com/hzya/frame/seeyon/entity/CtpFileEntity.xml +++ b/fw-oa/src/main/java/com/hzya/frame/seeyon/entity/CtpFileEntity.xml @@ -1,6 +1,6 @@ - + diff --git a/fw-oa/src/main/java/com/hzya/frame/seeyon/entity/NuoNuoCallbackEntity.xml b/fw-oa/src/main/java/com/hzya/frame/seeyon/entity/NuoNuoCallbackEntity.xml index d64e7159..61c1daef 100644 --- a/fw-oa/src/main/java/com/hzya/frame/seeyon/entity/NuoNuoCallbackEntity.xml +++ b/fw-oa/src/main/java/com/hzya/frame/seeyon/entity/NuoNuoCallbackEntity.xml @@ -1,6 +1,6 @@ - + diff --git a/fw-oa/src/main/java/com/hzya/frame/seeyon/service/impl/NuoNuoCallbackServiceImpl.java b/fw-oa/src/main/java/com/hzya/frame/seeyon/service/impl/NuoNuoCallbackServiceImpl.java index c8200285..b7a10846 100644 --- a/fw-oa/src/main/java/com/hzya/frame/seeyon/service/impl/NuoNuoCallbackServiceImpl.java +++ b/fw-oa/src/main/java/com/hzya/frame/seeyon/service/impl/NuoNuoCallbackServiceImpl.java @@ -8,9 +8,18 @@ import com.hzya.frame.seeyon.dao.INuoNuoCallbackDao; import com.hzya.frame.seeyon.entity.NuoNuoCallbackEntity; import com.hzya.frame.seeyon.service.ICtpAttachmentService; import com.hzya.frame.seeyon.service.INuoNuoCallbackService; +import org.apache.http.HttpEntity; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.conn.ssl.TrustAllStrategy; +import org.apache.http.entity.ByteArrayEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.quartz.simpl.SystemPropertyInstanceIdGenerator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -22,6 +31,7 @@ import javax.net.ssl.X509TrustManager; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; +import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; @@ -29,11 +39,17 @@ import java.net.URL; import java.net.URLDecoder; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.UUID; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.http.ssl.SSLContextBuilder; + @Service(value = "nuoNuoCallbackService") @@ -63,7 +79,11 @@ public class NuoNuoCallbackServiceImpl implements INuoNuoCallbackService { String invoiceCode = jsonObject.getString("invoiceCode");//发票代码 String invoiceNumber = jsonObject.getString("invoiceNumber");//发票号码 String orderNo = jsonObject.getString("orderNo");//订单编号 - + if(invoiceTime != null && !"".equals(invoiceTime)){ + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date date = new Date(jsonObject.getLong("invoiceTime")); + invoiceTime = sdf.format(date); + } if(orderNo == null || "".equals(orderNo)){ JSONObject returnData = new JSONObject(); returnData.put("code","9999"); @@ -111,6 +131,7 @@ public class NuoNuoCallbackServiceImpl implements INuoNuoCallbackService { nuoNuoCallbackEntity.setField0188(invoiceCode);//发票代码 nuoNuoCallbackEntity.setField0152(errorMessage);//开票结果 String urluuid = String.valueOf(UUID.randomUUID().getLeastSignificantBits()); + if(pdfUrl != null){ String urlData = sendFileUpload(pdfUrl); if(urlData != null){ @@ -142,6 +163,7 @@ public class NuoNuoCallbackServiceImpl implements INuoNuoCallbackService { } } //修改单据信息 + nuoNuoCallbackEntity.setDataSourceCode("master"); nuoNuoCallbackDao.updateNuoNuo(nuoNuoCallbackEntity); JSONObject returnData = new JSONObject(); returnData.put("code","0000"); @@ -225,13 +247,14 @@ public class NuoNuoCallbackServiceImpl implements INuoNuoCallbackService { return null; } public JSONObject fileUpload(File file) { + if (null != file) { try { HashMap paramMap = new HashMap<>(); - String loginName = "hzya"; + String loginName = "fkmanager"; paramMap.put("file", file); String url = "/seeyon/rest/attachment?token=@token@";//如果后面加上applicationCategory=1&extensions=&firstSave=true,附件业务自动生成一条记录 - //url = url.replaceAll("@token@", getOAToken(loginName)); + url = url.replaceAll("@token@", getOAToken(loginName)); String result = HttpUtil.post("https://swoa.sunwave.com.cn:9999" + url, paramMap); if (StrUtil.isNotBlank(result)) { JSONObject jsonObject = JSONObject.parseObject(result); @@ -255,7 +278,7 @@ public class NuoNuoCallbackServiceImpl implements INuoNuoCallbackService { private String extractFileNameFromContentDisposition(String contentDisposition) { // 处理Content-Disposition头中的filename try { - Pattern pattern = Pattern.compile("fileName=\"?([^\"]+)\"?"); + Pattern pattern = Pattern.compile("filename=\"?([^\"]+)\"?"); Matcher matcher = pattern.matcher(contentDisposition); if (matcher.find()) { String filename = matcher.group(1); @@ -267,5 +290,74 @@ public class NuoNuoCallbackServiceImpl implements INuoNuoCallbackService { } return null; } + private String getOAToken(String name) { + String url = "https://swoa.sunwave.com.cn:9999/seeyon/rest/token"; + Map headers = null; + String bodys = "{\"password\":\"hzya1314\",\"userName\":\"hzyaRestUser\",\"loginName\":\""+name+"\"}"; + String tokenData = sendPost(url, headers, bodys); + String access_token = null; + if (tokenData != null && JSONObject.isValidObject(tokenData)) { + JSONObject tokendataJson = JSONObject.parseObject(tokenData); + if (tokendataJson != null && tokendataJson.getString("id") != null) { + access_token = tokendataJson.getString("id"); + } + } + return access_token; + } + private String sendPost(String url, Map headers, String bodys) { + logger.info("url:"+url+"。bodys:"+bodys); + SSLContext sslContext = null; + try { + sslContext = new SSLContextBuilder() + .loadTrustMaterial(null, TrustAllStrategy.INSTANCE) + .build(); + } catch (Exception e) { + + } + CloseableHttpClient closeableHttpClient = HttpClients.custom() + .setSSLContext(sslContext) + .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE) + .build(); + HttpPost post = new HttpPost(url); + CloseableHttpResponse response = null; + RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(60000).build(); + post.setConfig(requestConfig);//设置请求参数【超时时间】 + if (headers != null && headers.size() > 0) { + for (String key : headers.keySet()) { + post.setHeader(key, headers.get(key)); + } + } + StringBuilder body = new StringBuilder(); + try { + if (bodys != null && !"".equals(bodys)) { + ByteArrayEntity entity = new ByteArrayEntity(bodys.getBytes("UTF-8")); + entity.setContentType("application/json"); + post.setEntity(entity); + } + response = closeableHttpClient.execute(post); + HttpEntity entity = response.getEntity(); + body.append(EntityUtils.toString(entity, "UTF-8")); + logger.info("返回结果:" + body); + } catch (Exception e) { + logger.error("请求错误:" + e.getMessage()); + body = new StringBuilder(); + } finally { + try { + // 关闭响应对象 + if (response != null) { + response.close(); + } + // 关闭响应对象 + if (closeableHttpClient != null) { + closeableHttpClient.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + + } + logger.info("url:"+url+"。bodys:"+bodys+"。body"+body); + return body.toString(); + } }