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

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

parent aa93037f
......@@ -10,6 +10,7 @@ import com.pingan.openbank.api.sdk.common.http.HttpResult;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
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.ResponseBody;
......@@ -29,47 +30,14 @@ public class PingAnController extends BaseController {
@ApiModelProperty("子账户维护(BEDL_C002)")
@RequestMapping("/bedl/SubAcctMaintenance")
@ResponseBody
public ResponseData bindSubAccount(HttpServletRequest request){
// 模拟请求参数
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);
public JSONObject bindSubAccount(HttpServletRequest request,@RequestBody(required = true) JSONObject reqParams){
return pingAnService.invoke("bedl/SubAcctMaintenance",reqParams);
}
@ApiModelProperty("近期明细查询(BEDL_C00602)")
@RequestMapping("/bedl/InquiryIntoTheCurrentDetailsOfMainSubaccountAccountTwo")
@ResponseBody
public ResponseData recentDetailQuery(HttpServletRequest request){
// 模拟请求参数
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);
public JSONObject recentDetailQuery(HttpServletRequest request,@RequestBody(required = true) JSONObject reqParams){
return pingAnService.invoke("bedl/InquiryIntoTheCurrentDetailsOfMainSubaccountAccountTwo",reqParams);
}
......@@ -84,17 +52,9 @@ public class PingAnController extends BaseController {
@ApiModelProperty("清分台账明细下载(BEDL_F0P101)")
@RequestMapping("/bedl/DetailReportQueryNew")
@ResponseBody
public ResponseData downloadDetail(HttpServletRequest request){
public JSONObject downloadDetail(HttpServletRequest request,@RequestBody(required = true) JSONObject reqParams){
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("BsnCode","C006A");
// reqParams.put("BatchNo","");
return pingAnService.invoke("bedl/DetailReportQueryNew", reqParams);
}
}
......@@ -8,7 +8,7 @@ import java.util.HashMap;
public interface PingAnService {
ResponseData invoke(String interfaceName, JSONObject params);
JSONObject invoke(String interfaceName, JSONObject params);
ResponseData detailNotify(IRequest iRequest, JSONObject data);
}
......@@ -3,6 +3,7 @@ package com.hand.app.pingAn.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.chinapay.comm.Constants;
import com.chinapay.dto.HlsEbankCcbTransaction;
import com.chinapay.mapper.HlsEbankCcbTransactionMapper;
import com.chinapay.service.IHlsEbankCcbTransactionService;
......@@ -46,7 +47,6 @@ public class PingAnServiceImpl implements PingAnService {
private Logger logger = LoggerFactory.getLogger(getClass());
private static Properties pro = null;
static {
......@@ -62,8 +62,8 @@ public class PingAnServiceImpl implements PingAnService {
* @return
*/
@Override
public ResponseData invoke(String interfaceName, JSONObject params) {
ResponseData responseData = new ResponseData();
public JSONObject invoke(String interfaceName, JSONObject params) {
JSONObject responseData = new JSONObject();
JSONObject requestBody = ApiUtils.getBaseReqBody();
requestBody.putAll(params);
/*插入接口日志表*/
......@@ -71,43 +71,45 @@ public class PingAnServiceImpl implements PingAnService {
hlsWsRequests = createRequestLog(pro.getProperty("baseUrl")+"/V1.0/"+interfaceName, requestBody.toJSONString(), 1L);
HttpResult result = ApiUtils.invoke(interfaceName, requestBody);
if (Objects.nonNull(result)) {
JSONObject res;
// 通信成功
if ("200".equals(result.getCode() + "")) {
hlsWsRequests.setReturnStatus("s");
responseData.setSuccess(true);
JSONObject res = JSONObject.parseObject(result.getData());
// 具体业务是否请求成功判定,目前观察成功请求可能没有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 不同接口返回不同数据,需要确认返回结果的格式
switch (interfaceName) {
case "bedl/SubAcctMaintenance" :
hlsWsRequests.setFunctionName("pingAn_SubAcctMaintenance");
res = JSONObject.parseObject(result.getData());
// do something
ArrayList<String> strings = new ArrayList<>();
strings.add(res.getString("SubAccountNo"));
responseData.setRows(strings);
responseData.put("data",res);
break;
case "bedl/InquiryIntoTheCurrentDetailsOfMainSubaccountAccountTwo" :
hlsWsRequests.setFunctionName("pingAn_recentDetailQuery");
res = JSONObject.parseObject(result.getData());
//do something
ArrayList<JSONObject> jsonObjects = new ArrayList<>();
jsonObjects.add(res);
responseData.setRows(jsonObjects);
responseData.put("data",res);
break;
case "bedl/DetailReportQueryNew" :
hlsWsRequests.setFunctionName("pingAn_DetailReportQueryNew");
// 做文件下载
JSONObject arrRes = JSONArray.parseObject(result.getData());
ArrayList<JSONObject> fileInfo = new ArrayList<>();
fileInfo.add(arrRes);
responseData.setRows(fileInfo);
responseData.put("data",res);
break;
}
} else {
//请求失败
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.setResponsedDate(new Date());
......@@ -151,28 +153,22 @@ public class PingAnServiceImpl implements PingAnService {
private String postNotify(String params) {
String sysName = "HCL_UPLOAD_FILE";
// todo 待修改
String apiName = "writeOffLd037";
String apiName = "pingAnCallback";
try {
//初始化接口信息
HapInterfaceHeader headerAndLineDTO = headerService.getHeaderAndLine(sysName, apiName);
if (headerAndLineDTO == null) {
logger.info("headerAndLineDTO is null, apiName:{}, sysName:{}", apiName, sysName);
return "N";
}
String url = headerAndLineDTO.getDomainUrl() + headerAndLineDTO.getIftUrl();
Map<String, String> headInfo = new HashMap<String, String>();
headInfo.put("Content-Type", "application/x-www-form-urlencoded");
JSONObject requestData = new JSONObject();
requestData.put("requestData", params);
//发送http请求
SignHclcUtils signHclcUtils1 = new SignHclcUtils();
String stringResult = signHclcUtils1.postString(url, requestData, headInfo, SignHclcUtils.APPLICATION_FORM_URLENCODED);
//解析返回结果
JSONObject jsonResult = JSONObject.parseObject(stringResult);
if ("S".equalsIgnoreCase(jsonResult.getString("respCode"))) {
......
......@@ -6,11 +6,15 @@ import com.pingan.openbank.api.sdk.common.http.HttpResult;
import com.pingan.openbank.api.sdk.entity.*;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
public class ApiUtils {
private static ApiClient apiClient = ApiClient.getInstance("pingAn.properties");
private static JSONObject baseReqBody = new JSONObject();
private static Calendar cal = null;
private static SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmssSSS");
private static String MrchCode = "0090108040000KTAR000";
public static String AcctNo = "15000101414037";
static{
......@@ -27,7 +31,10 @@ public class ApiUtils {
}
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