诺诺发票回调

This commit is contained in:
lvleigang 2025-06-27 17:08:48 +08:00
parent 26468c5a6e
commit 049270ae15
3 changed files with 99 additions and 7 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hzya.frame.seeyon.entity.CtpFileEntity"> <mapper namespace="com.hzya.frame.seeyon.dao.impl.CtpFileDaoImpl">
<resultMap id="get-CtpFileEntity-result" type="com.hzya.frame.seeyon.entity.CtpFileEntity"> <resultMap id="get-CtpFileEntity-result" type="com.hzya.frame.seeyon.entity.CtpFileEntity">
<!--主键 --> <!--主键 -->
<result property="id" column="id" /> <result property="id" column="id" />

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hzya.frame.seeyon.entity.NuoNuoCallbackEntity"> <mapper namespace="com.hzya.frame.seeyon.dao.impl.NuoNuoCallbackDaoImpl">

View File

@ -8,9 +8,18 @@ import com.hzya.frame.seeyon.dao.INuoNuoCallbackDao;
import com.hzya.frame.seeyon.entity.NuoNuoCallbackEntity; import com.hzya.frame.seeyon.entity.NuoNuoCallbackEntity;
import com.hzya.frame.seeyon.service.ICtpAttachmentService; import com.hzya.frame.seeyon.service.ICtpAttachmentService;
import com.hzya.frame.seeyon.service.INuoNuoCallbackService; 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.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.quartz.simpl.SystemPropertyInstanceIdGenerator;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -22,6 +31,7 @@ import javax.net.ssl.X509TrustManager;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
@ -29,11 +39,17 @@ import java.net.URL;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.apache.http.ssl.SSLContextBuilder;
@Service(value = "nuoNuoCallbackService") @Service(value = "nuoNuoCallbackService")
@ -63,7 +79,11 @@ public class NuoNuoCallbackServiceImpl implements INuoNuoCallbackService {
String invoiceCode = jsonObject.getString("invoiceCode");//发票代码 String invoiceCode = jsonObject.getString("invoiceCode");//发票代码
String invoiceNumber = jsonObject.getString("invoiceNumber");//发票号码 String invoiceNumber = jsonObject.getString("invoiceNumber");//发票号码
String orderNo = jsonObject.getString("orderNo");//订单编号 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)){ if(orderNo == null || "".equals(orderNo)){
JSONObject returnData = new JSONObject(); JSONObject returnData = new JSONObject();
returnData.put("code","9999"); returnData.put("code","9999");
@ -111,6 +131,7 @@ public class NuoNuoCallbackServiceImpl implements INuoNuoCallbackService {
nuoNuoCallbackEntity.setField0188(invoiceCode);//发票代码 nuoNuoCallbackEntity.setField0188(invoiceCode);//发票代码
nuoNuoCallbackEntity.setField0152(errorMessage);//开票结果 nuoNuoCallbackEntity.setField0152(errorMessage);//开票结果
String urluuid = String.valueOf(UUID.randomUUID().getLeastSignificantBits()); String urluuid = String.valueOf(UUID.randomUUID().getLeastSignificantBits());
if(pdfUrl != null){ if(pdfUrl != null){
String urlData = sendFileUpload(pdfUrl); String urlData = sendFileUpload(pdfUrl);
if(urlData != null){ if(urlData != null){
@ -142,6 +163,7 @@ public class NuoNuoCallbackServiceImpl implements INuoNuoCallbackService {
} }
} }
//修改单据信息 //修改单据信息
nuoNuoCallbackEntity.setDataSourceCode("master");
nuoNuoCallbackDao.updateNuoNuo(nuoNuoCallbackEntity); nuoNuoCallbackDao.updateNuoNuo(nuoNuoCallbackEntity);
JSONObject returnData = new JSONObject(); JSONObject returnData = new JSONObject();
returnData.put("code","0000"); returnData.put("code","0000");
@ -225,13 +247,14 @@ public class NuoNuoCallbackServiceImpl implements INuoNuoCallbackService {
return null; return null;
} }
public JSONObject fileUpload(File file) { public JSONObject fileUpload(File file) {
if (null != file) { if (null != file) {
try { try {
HashMap<String, Object> paramMap = new HashMap<>(); HashMap<String, Object> paramMap = new HashMap<>();
String loginName = "hzya"; String loginName = "fkmanager";
paramMap.put("file", file); paramMap.put("file", file);
String url = "/seeyon/rest/attachment?token=@token@";//如果后面加上applicationCategory=1&extensions=&firstSave=true附件业务自动生成一条记录 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); String result = HttpUtil.post("https://swoa.sunwave.com.cn:9999" + url, paramMap);
if (StrUtil.isNotBlank(result)) { if (StrUtil.isNotBlank(result)) {
JSONObject jsonObject = JSONObject.parseObject(result); JSONObject jsonObject = JSONObject.parseObject(result);
@ -255,7 +278,7 @@ public class NuoNuoCallbackServiceImpl implements INuoNuoCallbackService {
private String extractFileNameFromContentDisposition(String contentDisposition) { private String extractFileNameFromContentDisposition(String contentDisposition) {
// 处理Content-Disposition头中的filename // 处理Content-Disposition头中的filename
try { try {
Pattern pattern = Pattern.compile("fileName=\"?([^\"]+)\"?"); Pattern pattern = Pattern.compile("filename=\"?([^\"]+)\"?");
Matcher matcher = pattern.matcher(contentDisposition); Matcher matcher = pattern.matcher(contentDisposition);
if (matcher.find()) { if (matcher.find()) {
String filename = matcher.group(1); String filename = matcher.group(1);
@ -267,5 +290,74 @@ public class NuoNuoCallbackServiceImpl implements INuoNuoCallbackService {
} }
return null; return null;
} }
private String getOAToken(String name) {
String url = "https://swoa.sunwave.com.cn:9999/seeyon/rest/token";
Map<String, String> 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<String, String> 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();
}
}