Commit d7617a23 authored by 胡建龙's avatar 胡建龙

[fix]接口修改为接收外部传入参数

parent aa93037f
...@@ -10,6 +10,7 @@ import com.pingan.openbank.api.sdk.common.http.HttpResult; ...@@ -10,6 +10,7 @@ import com.pingan.openbank.api.sdk.common.http.HttpResult;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
...@@ -29,47 +30,14 @@ public class PingAnController extends BaseController { ...@@ -29,47 +30,14 @@ public class PingAnController extends BaseController {
@ApiModelProperty("子账户维护(BEDL_C002)") @ApiModelProperty("子账户维护(BEDL_C002)")
@RequestMapping("/bedl/SubAcctMaintenance") @RequestMapping("/bedl/SubAcctMaintenance")
@ResponseBody @ResponseBody
public ResponseData bindSubAccount(HttpServletRequest request){ public JSONObject bindSubAccount(HttpServletRequest request,@RequestBody(required = true) JSONObject reqParams){
// 模拟请求参数
JSONObject reqParams = new JSONObject();
reqParams.put("OpFlag","A");
reqParams.put("SubAccountSeq","123456");
reqParams.put("SubAccountName","测试别名");
String seqNoTime = new SimpleDateFormat("yyMMdd").format(Calendar.getInstance().getTime());
Random random = new Random();
String randomNo = "";
for (byte i = 0; i < 8; i++) {
int randomNumber = random.nextInt(10);
randomNo += randomNumber;
}
//系统流水号,规范:用户短号(6位)+日期(6位)+随机编号(10位)
reqParams.put("CnsmrSeqNo", "C25634" + seqNoTime + randomNo);
return pingAnService.invoke("bedl/SubAcctMaintenance",reqParams); return pingAnService.invoke("bedl/SubAcctMaintenance",reqParams);
} }
@ApiModelProperty("近期明细查询(BEDL_C00602)") @ApiModelProperty("近期明细查询(BEDL_C00602)")
@RequestMapping("/bedl/InquiryIntoTheCurrentDetailsOfMainSubaccountAccountTwo") @RequestMapping("/bedl/InquiryIntoTheCurrentDetailsOfMainSubaccountAccountTwo")
@ResponseBody @ResponseBody
public ResponseData recentDetailQuery(HttpServletRequest request){ public JSONObject recentDetailQuery(HttpServletRequest request,@RequestBody(required = true) JSONObject reqParams){
// 模拟请求参数
JSONObject reqParams = new JSONObject();
reqParams.put("OpFlag","1");
reqParams.put("StartTime","20221201000000");
reqParams.put("EndTime","20221202000000");
reqParams.put("PageNo","1");
reqParams.put("PageSize","200");
String seqNoTime = new SimpleDateFormat("yyMMdd").format(Calendar.getInstance().getTime());
Random random = new Random();
String randomNo = "";
for (byte i = 0; i < 8; i++) {
int randomNumber = random.nextInt(10);
randomNo += randomNumber;
}
//系统流水号,规范:用户短号(6位)+日期(6位)+随机编号(10位)
reqParams.put("CnsmrSeqNo", "C25634" + seqNoTime + randomNo);
return pingAnService.invoke("bedl/InquiryIntoTheCurrentDetailsOfMainSubaccountAccountTwo",reqParams); return pingAnService.invoke("bedl/InquiryIntoTheCurrentDetailsOfMainSubaccountAccountTwo",reqParams);
} }
...@@ -84,17 +52,9 @@ public class PingAnController extends BaseController { ...@@ -84,17 +52,9 @@ public class PingAnController extends BaseController {
@ApiModelProperty("清分台账明细下载(BEDL_F0P101)") @ApiModelProperty("清分台账明细下载(BEDL_F0P101)")
@RequestMapping("/bedl/DetailReportQueryNew") @RequestMapping("/bedl/DetailReportQueryNew")
@ResponseBody @ResponseBody
public ResponseData downloadDetail(HttpServletRequest request){ public JSONObject downloadDetail(HttpServletRequest request,@RequestBody(required = true) JSONObject reqParams){
IRequest iRequest = createRequestContext(request); IRequest iRequest = createRequestContext(request);
JSONObject reqParams = new JSONObject();
Calendar cal = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmssSSS");
String today = df.format(cal.getTime());
reqParams.put("CnsmrSeqNo", today+"000");
reqParams.put("QueryDate", "20221213");
reqParams.put("Account",ApiUtils.AcctNo); reqParams.put("Account",ApiUtils.AcctNo);
reqParams.put("BsnCode","C006A");
// reqParams.put("BatchNo","");
return pingAnService.invoke("bedl/DetailReportQueryNew", reqParams); return pingAnService.invoke("bedl/DetailReportQueryNew", reqParams);
} }
} }
...@@ -8,7 +8,7 @@ import java.util.HashMap; ...@@ -8,7 +8,7 @@ import java.util.HashMap;
public interface PingAnService { public interface PingAnService {
ResponseData invoke(String interfaceName, JSONObject params); JSONObject invoke(String interfaceName, JSONObject params);
ResponseData detailNotify(IRequest iRequest, JSONObject data); ResponseData detailNotify(IRequest iRequest, JSONObject data);
} }
...@@ -3,6 +3,7 @@ package com.hand.app.pingAn.service.impl; ...@@ -3,6 +3,7 @@ package com.hand.app.pingAn.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.chinapay.comm.Constants;
import com.chinapay.dto.HlsEbankCcbTransaction; import com.chinapay.dto.HlsEbankCcbTransaction;
import com.chinapay.mapper.HlsEbankCcbTransactionMapper; import com.chinapay.mapper.HlsEbankCcbTransactionMapper;
import com.chinapay.service.IHlsEbankCcbTransactionService; import com.chinapay.service.IHlsEbankCcbTransactionService;
...@@ -46,7 +47,6 @@ public class PingAnServiceImpl implements PingAnService { ...@@ -46,7 +47,6 @@ public class PingAnServiceImpl implements PingAnService {
private Logger logger = LoggerFactory.getLogger(getClass()); private Logger logger = LoggerFactory.getLogger(getClass());
private static Properties pro = null; private static Properties pro = null;
static { static {
...@@ -62,8 +62,8 @@ public class PingAnServiceImpl implements PingAnService { ...@@ -62,8 +62,8 @@ public class PingAnServiceImpl implements PingAnService {
* @return * @return
*/ */
@Override @Override
public ResponseData invoke(String interfaceName, JSONObject params) { public JSONObject invoke(String interfaceName, JSONObject params) {
ResponseData responseData = new ResponseData(); JSONObject responseData = new JSONObject();
JSONObject requestBody = ApiUtils.getBaseReqBody(); JSONObject requestBody = ApiUtils.getBaseReqBody();
requestBody.putAll(params); requestBody.putAll(params);
/*插入接口日志表*/ /*插入接口日志表*/
...@@ -71,43 +71,45 @@ public class PingAnServiceImpl implements PingAnService { ...@@ -71,43 +71,45 @@ public class PingAnServiceImpl implements PingAnService {
hlsWsRequests = createRequestLog(pro.getProperty("baseUrl")+"/V1.0/"+interfaceName, requestBody.toJSONString(), 1L); hlsWsRequests = createRequestLog(pro.getProperty("baseUrl")+"/V1.0/"+interfaceName, requestBody.toJSONString(), 1L);
HttpResult result = ApiUtils.invoke(interfaceName, requestBody); HttpResult result = ApiUtils.invoke(interfaceName, requestBody);
if (Objects.nonNull(result)) { if (Objects.nonNull(result)) {
JSONObject res; // 通信成功
if ("200".equals(result.getCode() + "")) { if ("200".equals(result.getCode() + "")) {
hlsWsRequests.setReturnStatus("s"); JSONObject res = JSONObject.parseObject(result.getData());
responseData.setSuccess(true); // 具体业务是否请求成功判定,目前观察成功请求可能没有Code值
if ("000000".equals(res.getString("Code")) || Objects.isNull(res.getString("Code"))){
hlsWsRequests.setReturnStatus("s");
responseData.put(Constants.RESP_CODE, "0000");
responseData.put("respMsg", "请求成功");
}else{
//粗略的报错 如:"Message":"业务处理失败(通讯成功)","Code":"E50000"
responseData.put(Constants.RESP_CODE ,res.getString("Code"));
responseData.put(Constants.RESP_MSG ,res.getString("Message"));
if (Objects.nonNull(res.getJSONArray("Errors"))){
//详情报错 如:"ErrorCode":"CE3887","ErrorMessage":":[CE3887]清分台账编码[30206688123456]记录已存在
responseData.put(Constants.RESP_CODE ,res.getJSONArray("Errors").getJSONObject(0).getString("ErrorCode"));
responseData.put(Constants.RESP_MSG ,res.getJSONArray("Errors").getJSONObject(0).getString("ErrorMessage"));
}
}
// todo 不同接口返回不同数据,需要确认返回结果的格式 // todo 不同接口返回不同数据,需要确认返回结果的格式
switch (interfaceName) { switch (interfaceName) {
case "bedl/SubAcctMaintenance" : case "bedl/SubAcctMaintenance" :
hlsWsRequests.setFunctionName("pingAn_SubAcctMaintenance"); hlsWsRequests.setFunctionName("pingAn_SubAcctMaintenance");
res = JSONObject.parseObject(result.getData()); responseData.put("data",res);
// do something
ArrayList<String> strings = new ArrayList<>();
strings.add(res.getString("SubAccountNo"));
responseData.setRows(strings);
break; break;
case "bedl/InquiryIntoTheCurrentDetailsOfMainSubaccountAccountTwo" : case "bedl/InquiryIntoTheCurrentDetailsOfMainSubaccountAccountTwo" :
hlsWsRequests.setFunctionName("pingAn_recentDetailQuery"); hlsWsRequests.setFunctionName("pingAn_recentDetailQuery");
res = JSONObject.parseObject(result.getData()); responseData.put("data",res);
//do something
ArrayList<JSONObject> jsonObjects = new ArrayList<>();
jsonObjects.add(res);
responseData.setRows(jsonObjects);
break; break;
case "bedl/DetailReportQueryNew" : case "bedl/DetailReportQueryNew" :
hlsWsRequests.setFunctionName("pingAn_DetailReportQueryNew"); hlsWsRequests.setFunctionName("pingAn_DetailReportQueryNew");
// 做文件下载 responseData.put("data",res);
JSONObject arrRes = JSONArray.parseObject(result.getData());
ArrayList<JSONObject> fileInfo = new ArrayList<>();
fileInfo.add(arrRes);
responseData.setRows(fileInfo);
break; break;
} }
} else { } else {
//请求失败 //请求失败
hlsWsRequests.setReturnStatus("f"); hlsWsRequests.setReturnStatus("f");
responseData.setSuccess(false); JSONObject errRes = JSONObject.parseObject(result.getData());
responseData.put(Constants.RESP_CODE,result.getCode());
responseData.put(Constants.RESP_MSG,"请求失败");
} }
hlsWsRequests.setResponseJson(result.getData()); hlsWsRequests.setResponseJson(result.getData());
hlsWsRequests.setResponsedDate(new Date()); hlsWsRequests.setResponsedDate(new Date());
...@@ -151,28 +153,22 @@ public class PingAnServiceImpl implements PingAnService { ...@@ -151,28 +153,22 @@ public class PingAnServiceImpl implements PingAnService {
private String postNotify(String params) { private String postNotify(String params) {
String sysName = "HCL_UPLOAD_FILE"; String sysName = "HCL_UPLOAD_FILE";
// todo 待修改 // todo 待修改
String apiName = "writeOffLd037"; String apiName = "pingAnCallback";
try { try {
//初始化接口信息 //初始化接口信息
HapInterfaceHeader headerAndLineDTO = headerService.getHeaderAndLine(sysName, apiName); HapInterfaceHeader headerAndLineDTO = headerService.getHeaderAndLine(sysName, apiName);
if (headerAndLineDTO == null) { if (headerAndLineDTO == null) {
logger.info("headerAndLineDTO is null, apiName:{}, sysName:{}", apiName, sysName); logger.info("headerAndLineDTO is null, apiName:{}, sysName:{}", apiName, sysName);
return "N"; return "N";
} }
String url = headerAndLineDTO.getDomainUrl() + headerAndLineDTO.getIftUrl(); String url = headerAndLineDTO.getDomainUrl() + headerAndLineDTO.getIftUrl();
Map<String, String> headInfo = new HashMap<String, String>(); Map<String, String> headInfo = new HashMap<String, String>();
headInfo.put("Content-Type", "application/x-www-form-urlencoded"); headInfo.put("Content-Type", "application/x-www-form-urlencoded");
JSONObject requestData = new JSONObject(); JSONObject requestData = new JSONObject();
requestData.put("requestData", params); requestData.put("requestData", params);
//发送http请求 //发送http请求
SignHclcUtils signHclcUtils1 = new SignHclcUtils(); SignHclcUtils signHclcUtils1 = new SignHclcUtils();
String stringResult = signHclcUtils1.postString(url, requestData, headInfo, SignHclcUtils.APPLICATION_FORM_URLENCODED); String stringResult = signHclcUtils1.postString(url, requestData, headInfo, SignHclcUtils.APPLICATION_FORM_URLENCODED);
//解析返回结果 //解析返回结果
JSONObject jsonResult = JSONObject.parseObject(stringResult); JSONObject jsonResult = JSONObject.parseObject(stringResult);
if ("S".equalsIgnoreCase(jsonResult.getString("respCode"))) { if ("S".equalsIgnoreCase(jsonResult.getString("respCode"))) {
......
...@@ -6,11 +6,15 @@ import com.pingan.openbank.api.sdk.common.http.HttpResult; ...@@ -6,11 +6,15 @@ import com.pingan.openbank.api.sdk.common.http.HttpResult;
import com.pingan.openbank.api.sdk.entity.*; import com.pingan.openbank.api.sdk.entity.*;
import java.io.File; import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List; import java.util.List;
public class ApiUtils { public class ApiUtils {
private static ApiClient apiClient = ApiClient.getInstance("pingAn.properties"); private static ApiClient apiClient = ApiClient.getInstance("pingAn.properties");
private static JSONObject baseReqBody = new JSONObject(); private static JSONObject baseReqBody = new JSONObject();
private static Calendar cal = null;
private static SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmssSSS");
private static String MrchCode = "0090108040000KTAR000"; private static String MrchCode = "0090108040000KTAR000";
public static String AcctNo = "15000101414037"; public static String AcctNo = "15000101414037";
static{ static{
...@@ -27,7 +31,10 @@ public class ApiUtils { ...@@ -27,7 +31,10 @@ public class ApiUtils {
} }
public static JSONObject getBaseReqBody(){ public static JSONObject getBaseReqBody(){
return baseReqBody.clone(); JSONObject clone = baseReqBody.clone();
cal = Calendar.getInstance();
String today = df.format(cal.getTime());
clone.put("CnsmrSeqNo",today+"000");
return clone;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment