ariesy 跟影像和SAP系统对接的接口加上鉴权

release
yefei 2 years ago
parent a6709a7fcf
commit a8473e6596
  1. 8
      dxhy-erp/src/main/java/com/dxhy/erp/controller/InterfaceController.java
  2. 35
      dxhy-erp/src/main/java/com/dxhy/erp/controller/SDNYMainProcessController.java
  3. 14
      dxhy-erp/src/main/java/com/dxhy/erp/entity/CheckReInfo.java
  4. 28
      dxhy-erp/src/main/java/com/dxhy/erp/service/GatherService.java
  5. 134
      dxhy-erp/src/main/java/com/dxhy/erp/service/impl/GatherServiceImpl.java
  6. 11
      dxhy-sign/src/main/java/com/dxhy/sign/util/HmacSHA1Util.java

@ -710,6 +710,14 @@ public class InterfaceController extends AbstractController {
case "INVOICE.SALSESPUSH": case "INVOICE.SALSESPUSH":
returnResult = invoicePoolService.salsePush(globalInfo, requestParam, request, response, authorize); returnResult = invoicePoolService.salsePush(globalInfo, requestParam, request, response, authorize);
break; break;
// 获取单张发票
case "INVOICE.SINGLEINVOICECHECK":
returnResult = gatherService.singleInvoiceChenck(globalInfo, requestParam, request, response, authorize);
break;
// 获取单张发票
case "INVOICE.SYNCINVOICEINFO":
returnResult = gatherService.syncInvoiceInfo(globalInfo, requestParam, request, response, authorize);
break;
// 接口编码不存在 // 接口编码不存在
default: default:
returnResult = authStatusService.getInterfaceCodeError(globalInfo); returnResult = authStatusService.getInterfaceCodeError(globalInfo);

@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dxhy.common.aspect.SysLog; import com.dxhy.common.aspect.SysLog;
import com.dxhy.common.constant.CommonConstants; import com.dxhy.common.constant.CommonConstants;
import com.dxhy.common.constant.ConfigurerInfo;
import com.dxhy.common.constant.DbConstant; import com.dxhy.common.constant.DbConstant;
import com.dxhy.common.controller.AbstractController; import com.dxhy.common.controller.AbstractController;
import com.dxhy.common.datasource.config.DynamicContextHolder; import com.dxhy.common.datasource.config.DynamicContextHolder;
@ -22,6 +23,7 @@ import com.dxhy.erp.service.InvoiceQueryService;
import com.dxhy.erp.service.SNPushCheckRecordService; import com.dxhy.erp.service.SNPushCheckRecordService;
import com.dxhy.erp.service.SignCheckRecordService; import com.dxhy.erp.service.SignCheckRecordService;
import com.dxhy.erp.service.SignSaveInvoiceInfoService; import com.dxhy.erp.service.SignSaveInvoiceInfoService;
import com.dxhy.erp.utils.HmacSHA1Util;
import com.dxhy.erp.utils.ServiceResult; import com.dxhy.erp.utils.ServiceResult;
import io.swagger.models.auth.In; import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -73,7 +75,7 @@ public class SDNYMainProcessController extends AbstractController {
@PostMapping("/sn/singleInvoiceCheck") @PostMapping("/sn/singleInvoiceCheck")
@ResponseBody @ResponseBody
@SysLog("发票查验") @SysLog("发票查验")
public ResponseEntity<?> singleInvoiceCheck(@RequestBody Map<String, String> pramsMap) { public ResponseEntity<Map<String,Object>> singleInvoiceCheck(@RequestBody Map<String, String> pramsMap) {
log.info("传入的参数为:{}",pramsMap); log.info("传入的参数为:{}",pramsMap);
String userid = "101833"; String userid = "101833";
String dbName = "business"; String dbName = "business";
@ -179,7 +181,7 @@ public class SDNYMainProcessController extends AbstractController {
@PostMapping("/sn/syncInvoiceInfo") @PostMapping("/sn/syncInvoiceInfo")
@ResponseBody @ResponseBody
@SysLog("同步发票信息") @SysLog("同步发票信息")
public ResponseEntity<?> syncInvoiceInfo(@RequestBody SNRequestObject snRequestObject) { public ResponseEntity<Map<String,Object>> syncInvoiceInfo(@RequestBody SNRequestObject snRequestObject) {
log.info("影像系统同步数据:{}",JSONObject.toJSONString(snRequestObject)); log.info("影像系统同步数据:{}",JSONObject.toJSONString(snRequestObject));
@ -274,6 +276,35 @@ public class SDNYMainProcessController extends AbstractController {
return ResponseEntity.ok(R.error(CommonConstants.MSG_ERR_DEFAULT)); return ResponseEntity.ok(R.error(CommonConstants.MSG_ERR_DEFAULT));
} }
/**
* 查验发票
*/
@PostMapping("/sn/signature")
@ResponseBody
@SysLog("获取接口签名值")
public String signature(@RequestBody Map<String,String> paramMap) {
String ip = paramMap.get("ip");
String apiCode = paramMap.get("apiCode");
String secretId = paramMap.get("secretId");
String secretKey = paramMap.get("secretKey");
String content = paramMap.get("content");
String dataExchangeId = paramMap.get("dataExchangeId");
TreeMap<String, String> sortMap = new TreeMap<>();
sortMap.put(ConfigurerInfo.SECRETID, secretId);
sortMap.put(ConfigurerInfo.DATA_EXCHANGE_ID, dataExchangeId);
sortMap.put(ConfigurerInfo.ENCRYPTCODE, "0");
sortMap.put(ConfigurerInfo.ZIPCODE, "0");
sortMap.put(ConfigurerInfo.CONTENT, content);
String url = "POST"+ ip +"/invoice/jxpt/api/v5/"+ apiCode +"?";
String data = "POST"+ ip +"/invoice/jxpt/api/v5/"+ apiCode +"?SecretId="+ secretId + "&content="+ content +"&dataExchangeId="+ dataExchangeId +"&encryptCode=0&zipCode=0";
String signature = HmacSHA1Util.genSign(url, sortMap,secretKey);
return signature;
}
private InvoiceInfo convertToInvoiceInfo(SNInvoice snInvoice) { private InvoiceInfo convertToInvoiceInfo(SNInvoice snInvoice) {
InvoiceInfo invoice = new InvoiceInfo(); InvoiceInfo invoice = new InvoiceInfo();
invoice.setInvoiceTypeCode(snInvoice.getInvoiceType()); invoice.setInvoiceTypeCode(snInvoice.getInvoiceType());

@ -0,0 +1,14 @@
package com.dxhy.erp.entity;
import lombok.Data;
import java.util.Map;
@Data
public class CheckReInfo {
private String message;
private String code;
private Map<String,String> data;
}

@ -66,4 +66,32 @@ public interface GatherService extends MpBaseService<TdxRecordInvoice> {
*/ */
String getAuthResult(GlobalInfo globalInfo, Map<String, String> map, HttpServletRequest request, String getAuthResult(GlobalInfo globalInfo, Map<String, String> map, HttpServletRequest request,
HttpServletResponse response, Authorize authorize); HttpServletResponse response, Authorize authorize);
/**
* 待填
*
* @param globalInfo
* @param map
* @param request
* @param response
* @param authorize
* @return
*/
String singleInvoiceChenck(GlobalInfo globalInfo, Map<String, String> map, HttpServletRequest request,
HttpServletResponse response, Authorize authorize);
/**
* 待填
*
* @param globalInfo
* @param map
* @param request
* @param response
* @param authorize
* @return
*/
String syncInvoiceInfo(GlobalInfo globalInfo, Map<String, String> map, HttpServletRequest request,
HttpServletResponse response, Authorize authorize);
} }

@ -3,17 +3,20 @@ package com.dxhy.erp.service.impl;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap; import java.util.stream.Collectors;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.dxhy.erp.controller.SDNYMainProcessController;
import com.dxhy.erp.entity.CheckReInfo;
import com.dxhy.erp.entity.sdny.SNRequestObject;
import com.dxhy.erp.entity.sdny.SNSAPObject;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
@ -57,6 +60,9 @@ public class GatherServiceImpl extends MpBaseServiceImpl<TdxRecordInvoiceDao, Td
@Resource @Resource
private SysDeptDao sysDeptDao; private SysDeptDao sysDeptDao;
@Resource
private SDNYMainProcessController mainService;
@Override @Override
public String get(GlobalInfo globalInfo, Map<String, String> map, HttpServletRequest request, public String get(GlobalInfo globalInfo, Map<String, String> map, HttpServletRequest request,
HttpServletResponse response, Authorize authorize) { HttpServletResponse response, Authorize authorize) {
@ -729,6 +735,126 @@ public class GatherServiceImpl extends MpBaseServiceImpl<TdxRecordInvoiceDao, Td
return info; return info;
} }
@Override
public String singleInvoiceChenck(GlobalInfo globalInfo, Map<String, String> map, HttpServletRequest request,
HttpServletResponse response, Authorize authorize) {
ReturnStateInfo run = new ReturnStateInfo();
try {
if (run.getReturnCode() != null || run.getReturnMessage() != null) {
InterfaceCode interfaceCode = new InterfaceCode();
interfaceCode.setGlobalInfo(globalInfo);
interfaceCode.setReturnStateInfo(run);
return JSON.toJSONString(interfaceCode);
}
String dbName = "business";
DynamicContextHolder.push(dbName + DbConstant.BUSINESS_READ);
Map<String, String> param = JSONObject.parseObject(map.get("data").getBytes(),Map.class);
ResponseEntity<?> responseEntity = mainService.singleInvoiceCheck(param);
String body = responseEntity.getBody().toString();
body = body.replaceAll("=",":");
// Map<String, String> resultMap = Arrays.asList(body.split("=")).stream()
// .map(elem -> elem.split(":"))
// .collect(Collectors.toMap(e -> e[0], e -> e[1]));
String result = "";
if (body != null) {
result = body;
} else {
ReturnStateInfo runInfo = new ReturnStateInfo();
runInfo.setReturnCode(ReturnCodeEnum.FPBCZ.getFhzDm());
runInfo.setReturnMessage(ReturnCodeEnum.FPBCZ.getFhzMc(ReturnCodeEnum.FPBCZ.getIndex()));
InterfaceCode interfaceCode = new InterfaceCode();
interfaceCode.setGlobalInfo(globalInfo);
interfaceCode.setReturnStateInfo(runInfo);
return JSON.toJSONString(interfaceCode);
}
log.info("===========发票实体转换完成============" + globalInfo.getDataExchangeId());
run.setReturnCode(ReturnCodeEnum.CLCG.getFhzDm());
run.setReturnMessage(ReturnCodeEnum.CLCG.getFhzMc(ReturnCodeEnum.CLCG.getIndex()));
InterfaceCode interfaceCode = new InterfaceCode();
interfaceCode.setGlobalInfo(globalInfo);
interfaceCode.setReturnStateInfo(run);
interfaceCode.setData(Base64.encode(result));
return JSON.toJSONString(interfaceCode);
} catch (Exception e) {
e.printStackTrace();
run.setReturnCode("2011");
run.setReturnMessage("其他异常");
String globalJson = null;
String runJson = null;
try {
runJson = JSON.toJSONString(run);
globalJson = JSON.toJSONString(globalInfo);
} catch (Exception ignored) {
}
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
return "{\"globalInfo\":" + globalJson + ",\"returnStateInfo\":" + runJson + "}";
}
}
@Override
public String syncInvoiceInfo(GlobalInfo globalInfo, Map<String, String> map, HttpServletRequest request,
HttpServletResponse response, Authorize authorize) {
ReturnStateInfo run = new ReturnStateInfo();
try {
if (run.getReturnCode() != null || run.getReturnMessage() != null) {
InterfaceCode interfaceCode = new InterfaceCode();
interfaceCode.setGlobalInfo(globalInfo);
interfaceCode.setReturnStateInfo(run);
return JSON.toJSONString(interfaceCode);
}
String dbName = "business";
DynamicContextHolder.push(dbName + DbConstant.BUSINESS_READ);
String data = map.get("data");
SNRequestObject snRequestObject = JSONObject.parseObject(data.getBytes(), SNRequestObject.class);
ResponseEntity<?> responseEntity = mainService.syncInvoiceInfo(snRequestObject);
String body = responseEntity.getBody().toString();
body = body.replaceAll("=",":");
String result = "";
if (body != null) {
result = body;
} else {
ReturnStateInfo runInfo = new ReturnStateInfo();
runInfo.setReturnCode(ReturnCodeEnum.FPBCZ.getFhzDm());
runInfo.setReturnMessage(ReturnCodeEnum.FPBCZ.getFhzMc(ReturnCodeEnum.FPBCZ.getIndex()));
InterfaceCode interfaceCode = new InterfaceCode();
interfaceCode.setGlobalInfo(globalInfo);
interfaceCode.setReturnStateInfo(runInfo);
return JSON.toJSONString(interfaceCode);
}
log.info("===========发票实体转换完成============" + globalInfo.getDataExchangeId());
run.setReturnCode(ReturnCodeEnum.CLCG.getFhzDm());
run.setReturnMessage(ReturnCodeEnum.CLCG.getFhzMc(ReturnCodeEnum.CLCG.getIndex()));
InterfaceCode interfaceCode = new InterfaceCode();
interfaceCode.setGlobalInfo(globalInfo);
interfaceCode.setReturnStateInfo(run);
interfaceCode.setData(Base64.encode(result));
return JSON.toJSONString(interfaceCode);
} catch (Exception e) {
e.printStackTrace();
run.setReturnCode("2011");
run.setReturnMessage("其他异常");
String globalJson = null;
String runJson = null;
try {
runJson = JSON.toJSONString(run);
globalJson = JSON.toJSONString(globalInfo);
} catch (Exception ignored) {
}
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
return "{\"globalInfo\":" + globalJson + ",\"returnStateInfo\":" + runJson + "}";
}
}
public InvoiceDetailInfo getInvoiceDetailInfo(InvoiceDetailInfo detail) { public InvoiceDetailInfo getInvoiceDetailInfo(InvoiceDetailInfo detail) {
InvoiceDetailInfo detailInfo = new InvoiceDetailInfo(); InvoiceDetailInfo detailInfo = new InvoiceDetailInfo();
detailInfo.setDetailNo(detail.getDetailNo() + ""); detailInfo.setDetailNo(detail.getDetailNo() + "");

@ -66,4 +66,15 @@ public class HmacSHA1Util {
return buffer.toString(); return buffer.toString();
} }
public static void main(String[] args) {
String data = "POST10.51.112.141:18096/invoice/jxpt/api/v5/INVOICE.SINGLEINVOICECHECK?SecretId=c2FucWljZXNoaUFwcFNlY2lkUHJv&content=ewoJInB1cmNoYXNlclRheE5vIjoiIiwKCSJpbnZvaWNlQ29kZSI6IjAzNjAwMTkwMDEwNyIsCgkiaW52b2ljZU51bWJlciI6IjA4NTg1OTc4IiwKCSJiaWxsaW5nRGF0ZSI6IjIwMjAwOTI0IiwKCSJjaGVja0NvZGUiOiI4OTk0NDUiLAoJInRvdGFsQW1vdW50IjoiIiwKCSJpbnZvaWNlVHlwZSI6IjEwMTAzIgp9&dataExchangeId=1234567812345678123456781234567812300001&encryptCode=0&zipCode=0";
String key = "c2FucWljZXNoaUFwcHNlY0tleVBybw";
String signature = HmacSHA1Util.hmacsha1(data, key);
System.out.println("signature=" + signature);
}
} }

Loading…
Cancel
Save