|
|
@@ -25,7 +25,7 @@ import java.util.Base64; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
@Service |
|
|
|
public class AnXinServiceImpl extends AbstractManager implements AnXinService{ |
|
|
|
public class AnXinServiceImpl extends AbstractManager implements AnXinService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public InterfaceResponse post(InterfaceRequest request) throws ServiceHandleException { |
|
|
@@ -42,12 +42,12 @@ public class AnXinServiceImpl extends AbstractManager implements AnXinService{ |
|
|
|
|
|
|
|
final String txCode = request.getMethod(); |
|
|
|
String res; |
|
|
|
Map<String, Object> jsonObject = JsonTools.json2Map(req,String.class, Object.class); |
|
|
|
Map<String, Object> jsonObject = JsonTools.json2Map(req, String.class, Object.class); |
|
|
|
|
|
|
|
// 判断是否有文件 走不同的请求 |
|
|
|
String path = (String) jsonObject.get("filePath"); |
|
|
|
if (hasText(path)) { |
|
|
|
File file = getByFilePath(jsonObject.get("filePath")+""); |
|
|
|
File file = getByFilePath(jsonObject.get("filePath") + ""); |
|
|
|
res = httpConnector.post("platId/" + Request.PLAT_ID + "/txCode/" + txCode + "/transaction", req, signature, file); |
|
|
|
} else { |
|
|
|
res = httpConnector.post("platId/" + Request.PLAT_ID + "/txCode/" + txCode + "/transaction", req, signature); |
|
|
@@ -71,20 +71,22 @@ public class AnXinServiceImpl extends AbstractManager implements AnXinService{ |
|
|
|
|
|
|
|
// 解析业务数据 |
|
|
|
if (resJson.containsKey("data")) { |
|
|
|
interfaceResponse.setBizContent(resJson.get("data")+""); |
|
|
|
interfaceResponse.setBizContent(resJson.get("data") + ""); |
|
|
|
} |
|
|
|
|
|
|
|
// 解析错误信息 |
|
|
|
if (resJson.containsKey("errorCode")) { |
|
|
|
interfaceResponse.setErrorCode(resJson.get("errorCode")+""); |
|
|
|
interfaceResponse.setErrorMessage(resJson.get("errorMessage")+""); |
|
|
|
interfaceResponse.setErrorCode(resJson.get("errorCode") + ""); |
|
|
|
} |
|
|
|
if(resJson.containsKey("errorMessage")) { |
|
|
|
interfaceResponse.setErrorMessage(resJson.get("errorMessage") + ""); |
|
|
|
} |
|
|
|
|
|
|
|
return interfaceResponse; |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("处理请求失败", e); |
|
|
|
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("处理请求失败"+ e); |
|
|
|
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("处理请求失败" + e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -96,16 +98,18 @@ public class AnXinServiceImpl extends AbstractManager implements AnXinService{ |
|
|
|
String uri = "platId/" + Request.PLAT_ID + "/contractNo/" + contractNo + "/downloading"; |
|
|
|
byte[] bytes = httpConnector.getFile(uri); |
|
|
|
|
|
|
|
// 合同不存在,抛出异常 |
|
|
|
if (CommonUtil.isEmpty(bytes)) { |
|
|
|
throw new RuntimeException("合同不存在,合同编号: " + contractNo); |
|
|
|
} |
|
|
|
// 包装响应参数 |
|
|
|
InterfaceResponse interfaceResponse = new InterfaceResponse(); |
|
|
|
// 合同不存在,抛出异常 |
|
|
|
if (CommonUtil.isEmpty(bytes)) { |
|
|
|
interfaceResponse.setErrorCode("0"); |
|
|
|
interfaceResponse.setErrorMessage("合同不存在,合同编号: " + contractNo); |
|
|
|
}else { |
|
|
|
// // 使用 Base64 编码二进制数据,以便在文本响应中安全传输 |
|
|
|
// String encodedBytes = Base64.getEncoder().encodeToString(bytes); |
|
|
|
// interfaceResponse.setBizContent(encodedBytes); |
|
|
|
interfaceResponse.setFileBytes(bytes); |
|
|
|
interfaceResponse.setFileBytes(bytes); |
|
|
|
} |
|
|
|
return interfaceResponse; |
|
|
|
} |
|
|
|
|
|
|
@@ -121,7 +125,7 @@ public class AnXinServiceImpl extends AbstractManager implements AnXinService{ |
|
|
|
outputStream.write(buffer, 0, bytesRead); |
|
|
|
} |
|
|
|
|
|
|
|
logger.info("文件已成功保存到本地: {}",localFilePath); |
|
|
|
logger.info("文件已成功保存到本地: {}", localFilePath); |
|
|
|
return new File(localFilePath); |
|
|
|
} catch (IOException e) { |
|
|
|
logger.error("文件加载失败", e); |
|
|
@@ -129,7 +133,9 @@ public class AnXinServiceImpl extends AbstractManager implements AnXinService{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** 包装请求参数*/ |
|
|
|
/** |
|
|
|
* 包装请求参数 |
|
|
|
*/ |
|
|
|
private static String packParam(String req) throws ServiceHandleException { |
|
|
|
Map<String, Object> jsonObject = null; |
|
|
|
String resStr = null; |
|
|
@@ -140,7 +146,7 @@ public class AnXinServiceImpl extends AbstractManager implements AnXinService{ |
|
|
|
jsonObject.put("head", head); |
|
|
|
resStr = JsonTools.toJsonStr(jsonObject); |
|
|
|
} catch (IOException e) { |
|
|
|
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("处理请求失败"+ e); |
|
|
|
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("处理请求失败" + e); |
|
|
|
} |
|
|
|
return resStr; |
|
|
|
} |
|
|
@@ -191,10 +197,10 @@ public class AnXinServiceImpl extends AbstractManager implements AnXinService{ |
|
|
|
|
|
|
|
// 解析错误信息 |
|
|
|
if (resJson.containsKey("errorCode")) { |
|
|
|
interfaceResponse.setErrorCode(resJson.get("errorCode")+""); |
|
|
|
interfaceResponse.setErrorMessage(resJson.get("errorMessage")+""); |
|
|
|
interfaceResponse.setErrorCode(resJson.get("errorCode") + ""); |
|
|
|
interfaceResponse.setErrorMessage(resJson.get("errorMessage") + ""); |
|
|
|
} |
|
|
|
|
|
|
|
System.out.println("==>"+interfaceResponse.toJson()); |
|
|
|
System.out.println("==>" + interfaceResponse.toJson()); |
|
|
|
} |
|
|
|
} |