EKP接口调用,使用HTTP请求访问POST方法。

调用实例
/**
 * 获取第三方接口的token
 */
public static String getToken()
{
    String token = "";
    JSONObject object = new JSONObject();
    object.put("appid", "appid");
    object.put("secretkey", "secretkey");
    if(null == httpClient)
    {
        httpClient = HttpClientBuilder.create().build();
    }
    HttpPost httpPost = new HttpPost("http://localhost/login");
    httpPost.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36");
    try
    {
        StringEntity se = new StringEntity(object.toString());
        se.setContentEncoding("UTF-8");
        //发送json数据需要设置contentType
        se.setContentType("application/x-www-form-urlencoded");
        //设置请求参数
        httpPost.setEntity(se);
        HttpResponse response = httpClient.execute(httpPost);
        //这里可以把返回的结果按照自定义的返回数据结果,把string转换成自定义类
        //ResultTokenBO result = JSONObject.parseObject(response, ResultTokenBO.class);
        //把response转为jsonObject
        JSONObject result = (JSONObject) JSONObject.parseObject(String.valueOf(response));
        if(result.containsKey("token"))
        {
            token = result.getString("token");
        }
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
    return token;
}
调用接口公共类
package com.landray.kmss.third.cmbchina.httpservice;

import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

/**
 * @description: 使用http方式调用接口公共类
 * @date: 2023/10/24
 */
public class HttpPostUtil {

    private static HttpClient httpClient = HttpClients.createDefault();

    /**
     * @param url
     * @param jsonObject
     * @return com.alibaba.fastjson.JSONObject
     * @description: 请求接口方法调用接口返回数据
     * @date: 2023/10/24
     */
    public static JSONObject doPost(String url, JSONObject jsonObject) {
        //声明返回数据的JSON对象
        JSONObject returnGetDataJson = new JSONObject();
        HttpPost httpPost;
        //接受返回的Json
        String resultStr = "";
        if (null == httpClient) {
            httpClient = HttpClientBuilder.create().build();
        }
        //传入请求地址
        httpPost = new HttpPost(url);
        try {
            //设置请求参数
            StringEntity se = new StringEntity(jsonObject.toString());
            //设置编码
            se.setContentEncoding("GB18030");
            //发送json数据需要设置contentType
            se.setContentType("application/json");
            //设置请求参数
            httpPost.setEntity(se);
            HttpResponse response = httpClient.execute(httpPost);
            if (response != null) {
                HttpEntity resEntity = response.getEntity();
                if (resEntity != null) {
                    resultStr = EntityUtils.toString(resEntity);
                    //把response转为jsonObject
                    JSONObject resultJson = JSONObject.parseObject(resultStr);
                    //判断返回状态
                    if (resultJson != null && !resultJson.isEmpty()) {
                        if (resultJson.getBoolean("success")) {
                            //成功,返回整个JSONObject
                            return resultJson;
                        } else {
                            //错误,返回处理信息
                            returnGetDataJson.put("success", resultJson.getBoolean("success"));
                            returnGetDataJson.put("message", resultJson.get("message").toString());
                            returnGetDataJson.put("msgCode", resultJson.get("msgCode").toString());
                        }
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
            returnGetDataJson.put("success", false);
            returnGetDataJson.put("message", "请求接口异常");
            returnGetDataJson.put("msgCode", "请求接口异常");
        } catch (Exception e) {
            e.printStackTrace();
            returnGetDataJson.put("success", false);
            returnGetDataJson.put("message", "请求接口异常");
            returnGetDataJson.put("msgCode", "请求接口异常");
        }
        return returnGetDataJson;
    }
}

接口常量定义类
package com.landray.kmss.third.cmbchina.httpservice;

/**
 * @description: 接口常量定义类
 * @date: 2023/10/24
 */
public class HttpPostConstant {

    /*商务卡卡片信息查询接口调用地址*/
    public static final String GETCARDINFODATAURL = "";

    /*招商银行新商务卡交易数据查询接口调用地址*/
    public static final String GETTRANSDATAURL = "";

    /*接口请求参数:key值*/
    public static final String PARAMAP = "paraMap";
    /*接口请求参数:客户号*/
    public static final String CLIENTID = "clientId";
    /*接口请求参数:客户号*/
    public static final String CLIENTSECRET = "clientSecret";
    /*接口请求参数:成本中心号*/
    public static final String CORNUM = "corNum";
    /*接口请求参数:入账日期*/
    public static final String POSTDATE = "postDate";
}

接口请求参数配置信息
  • 接口请求参数 服务接口
package com.landray.kmss.third.cmbchina.service;

import com.landray.kmss.sys.metadata.interfaces.IExtendDataService;
import com.landray.kmss.third.cmbchina.model.ThirdCmbchinaParamap;

import java.util.List;

/**
 * 接口请求参数 服务接口
 */
public interface IThirdCmbchinaParamapService extends IExtendDataService {

    /*查询到配置的接口参数信息*/
    List<ThirdCmbchinaParamap> getParamapData() throws Exception;
}

  • 接口请求参数 服务实现
package com.landray.kmss.third.cmbchina.service.spring;

import com.landray.kmss.common.actions.RequestContext;
import com.landray.kmss.common.convertor.ConvertorContext;
import com.landray.kmss.common.dao.HQLInfo;
import com.landray.kmss.common.forms.IExtendForm;
import com.landray.kmss.common.model.IBaseModel;
import com.landray.kmss.sys.metadata.interfaces.ExtendDataServiceImp;
import com.landray.kmss.sys.notify.interfaces.ISysNotifyMainCoreService;
import com.landray.kmss.third.cmbchina.model.ThirdCmbchinaParamap;
import com.landray.kmss.third.cmbchina.service.IThirdCmbchinaParamapService;
import com.landray.kmss.third.cmbchina.util.ThirdCmbchinaUtil;
import com.landray.kmss.util.SpringBeanUtil;

import java.util.List;

/**
 * 接口请求参数 服务实现
 */
public class ThirdCmbchinaParamapServiceImp extends ExtendDataServiceImp implements IThirdCmbchinaParamapService {

    private ISysNotifyMainCoreService sysNotifyMainCoreService;

    public IBaseModel convertBizFormToModel(IExtendForm form, IBaseModel model, ConvertorContext context) throws Exception {
        model = super.convertBizFormToModel(form, model, context);
        if (model instanceof ThirdCmbchinaParamap) {
            ThirdCmbchinaParamap thirdCmbchinaParamap = (ThirdCmbchinaParamap) model;
        }
        return model;
    }

    public IBaseModel initBizModelSetting(RequestContext requestContext) throws Exception {
        ThirdCmbchinaParamap thirdCmbchinaParamap = new ThirdCmbchinaParamap();
        ThirdCmbchinaUtil.initModelFromRequest(thirdCmbchinaParamap, requestContext);
        return thirdCmbchinaParamap;
    }

    public void initCoreServiceFormSetting(IExtendForm form, IBaseModel model, RequestContext requestContext) throws Exception {
        ThirdCmbchinaParamap thirdCmbchinaParamap = (ThirdCmbchinaParamap) model;
    }

    public ISysNotifyMainCoreService getSysNotifyMainCoreService() {
        if (sysNotifyMainCoreService == null) {
            sysNotifyMainCoreService = (ISysNotifyMainCoreService) SpringBeanUtil.getBean("sysNotifyMainCoreService");
        }
        return sysNotifyMainCoreService;
    }

    /**
     * @param
     * @return java.util.List
     * @description: 查询到配置的接口参数信息
     * @date: 2023/10/19
     */
    @Override
    public List<ThirdCmbchinaParamap> getParamapData() throws Exception {
        HQLInfo hqlInfo = new HQLInfo();
        try {
            hqlInfo.setWhereBlock("thirdCmbchinaParamap.paraMapFd1 = :paraMapFd1");
            //设置数据是否有效标识(0-有效;1-无效)
            hqlInfo.setParameter("paraMapFd1", "0");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return this.findList(hqlInfo);
    }
}

商务卡卡片信息处理
  • 商务卡卡片信息 服务接口
package com.landray.kmss.third.cmbchina.service;

import com.landray.kmss.sys.metadata.interfaces.IExtendDataService;

/**
 * 商务卡卡片信息 服务接口
 */
public interface IThirdCmbchinaBusicardinfoService extends IExtendDataService {

    /*根据成本中心号,清空卡卡片信息*/
    void deleteCardInfoByCorNum(String corNum) throws Exception;
}

  • 商务卡卡片信息 服务实现
package com.landray.kmss.third.cmbchina.service.spring;

import com.landray.kmss.common.actions.RequestContext;
import com.landray.kmss.common.convertor.ConvertorContext;
import com.landray.kmss.common.forms.IExtendForm;
import com.landray.kmss.common.model.IBaseModel;
import com.landray.kmss.sys.metadata.interfaces.ExtendDataServiceImp;
import com.landray.kmss.sys.notify.interfaces.ISysNotifyMainCoreService;
import com.landray.kmss.third.cmbchina.model.ThirdCmbchinaBusicardinfo;
import com.landray.kmss.third.cmbchina.service.IThirdCmbchinaBusicardinfoService;
import com.landray.kmss.third.cmbchina.util.ThirdCmbchinaUtil;
import com.landray.kmss.util.SpringBeanUtil;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * 商务卡卡片信息 服务实现
 */
public class ThirdCmbchinaBusicardinfoServiceImp extends ExtendDataServiceImp implements IThirdCmbchinaBusicardinfoService {

    private ISysNotifyMainCoreService sysNotifyMainCoreService;

    public IBaseModel convertBizFormToModel(IExtendForm form, IBaseModel model, ConvertorContext context) throws Exception {
        model = super.convertBizFormToModel(form, model, context);
        if (model instanceof ThirdCmbchinaBusicardinfo) {
            ThirdCmbchinaBusicardinfo thirdCmbchinaBusicardinfo = (ThirdCmbchinaBusicardinfo) model;
        }
        return model;
    }

    public IBaseModel initBizModelSetting(RequestContext requestContext) throws Exception {
        ThirdCmbchinaBusicardinfo thirdCmbchinaBusicardinfo = new ThirdCmbchinaBusicardinfo();
        ThirdCmbchinaUtil.initModelFromRequest(thirdCmbchinaBusicardinfo, requestContext);
        return thirdCmbchinaBusicardinfo;
    }

    public void initCoreServiceFormSetting(IExtendForm form, IBaseModel model, RequestContext requestContext) throws Exception {
        ThirdCmbchinaBusicardinfo thirdCmbchinaBusicardinfo = (ThirdCmbchinaBusicardinfo) model;
    }

    public ISysNotifyMainCoreService getSysNotifyMainCoreService() {
        if (sysNotifyMainCoreService == null) {
            sysNotifyMainCoreService = (ISysNotifyMainCoreService) SpringBeanUtil.getBean("sysNotifyMainCoreService");
        }
        return sysNotifyMainCoreService;
    }

    /*注入卡片信息*/
    protected IThirdCmbchinaBusicardinfoService thirdCmbchinaBusicardinfoService;

    public IThirdCmbchinaBusicardinfoService getThirdCmbchinaBusicardinfoService() {
        if (thirdCmbchinaBusicardinfoService == null) {
            thirdCmbchinaBusicardinfoService = (IThirdCmbchinaBusicardinfoService) SpringBeanUtil
                    .getBean("thirdCmbchinaBusicardinfoService");
        }
        return thirdCmbchinaBusicardinfoService;
    }


    /**
     * @param corNum
     * @return void
     * @description: 根据成本中心号,清空卡卡片信息
     * @date: 2023/10/19
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void deleteCardInfoByCorNum(String corNum) throws Exception {
        try {
            StringBuilder sql = new StringBuilder();
            sql.append("delete from third_cmbchina_busicardinfo where cor_num = ?");
            getThirdCmbchinaBusicardinfoService().getBaseDao().getHibernateSession()
                    .createSQLQuery(sql.toString()).setString(0, corNum).executeUpdate();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

商务卡卡片信息查询接口
  • 接口定义
package com.landray.kmss.third.cmbchina.httpservice;

import com.alibaba.fastjson.JSONObject;
import com.landray.kmss.common.service.IBaseService;

public interface BusiCardInfoQuery extends IBaseService {

    /*商务卡卡片信息查询接口*/
    JSONObject getCardInfoData() throws Exception;
}

  • 接口实现
package com.landray.kmss.third.cmbchina.httpservice.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.landray.kmss.common.service.BaseServiceImp;
import com.landray.kmss.common.service.IBaseService;
import com.landray.kmss.third.cmbchina.httpservice.BusiCardInfoQuery;
import com.landray.kmss.third.cmbchina.httpservice.HttpPostUtil;
import com.landray.kmss.third.cmbchina.model.ThirdCmbchinaBusicardinfo;
import com.landray.kmss.third.cmbchina.model.ThirdCmbchinaParamap;
import com.landray.kmss.third.cmbchina.service.IThirdCmbchinaBusicardinfoService;
import com.landray.kmss.third.cmbchina.service.IThirdCmbchinaParamapService;
import com.landray.kmss.util.SpringBeanUtil;
import com.landray.kmss.web.annotation.RestApi;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

import static com.landray.kmss.third.cmbchina.httpservice.HttpPostConstant.*;
import static com.landray.kmss.util.SpringBeanUtil.getBean;

/*
 * @description: 商务卡卡片信息查询接口实现类
 * @date: 2023/10/24
 */
@Controller
@RequestMapping(value = "/api/third-cmbchina/busiCardInfoQuery", method = RequestMethod.POST)
@RestApi(docUrl = "", name = "busiCardInfoQueryServiceImp", resourceKey = "third-cmbchina:module.third.cmbchina")
public class BusiCardInfoQueryImpl extends BaseServiceImp implements BusiCardInfoQuery {

    private IThirdCmbchinaBusicardinfoService thirdCmbchinaBusicardinfoService;

    public IBaseService getServiceImp() {
        if (thirdCmbchinaBusicardinfoService == null) {
            thirdCmbchinaBusicardinfoService = (IThirdCmbchinaBusicardinfoService) getBean("thirdCmbchinaBusicardinfoService");
        }
        return thirdCmbchinaBusicardinfoService;
    }

    /*注入接口请求参数方法*/
    private IThirdCmbchinaParamapService thirdCmbchinaParamapService;

    private IThirdCmbchinaParamapService getThirdCmbchinaParamapService() {
        if (thirdCmbchinaParamapService == null) {
            thirdCmbchinaParamapService = (IThirdCmbchinaParamapService) getBean("thirdCmbchinaParamapService");
        }
        return thirdCmbchinaParamapService;
    }

    /*注入卡片信息*/
    public IThirdCmbchinaBusicardinfoService getThirdCmbchinaBusicardinfoService() {
        if (thirdCmbchinaBusicardinfoService == null) {
            thirdCmbchinaBusicardinfoService = (IThirdCmbchinaBusicardinfoService) SpringBeanUtil
                    .getBean("thirdCmbchinaBusicardinfoService");
        }
        return thirdCmbchinaBusicardinfoService;
    }


    /**
     * @param
     * @return com.alibaba.fastjson.JSONObject
     * @description: 商务卡卡片信息查询接口
     * @date: 2023/10/24
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    @ResponseBody
    @RequestMapping(value = "/getCardInfoData", method = RequestMethod.POST)
    public JSONObject getCardInfoData() throws Exception {
        //声明最终返回的变量
        JSONObject returnJsonObject = new JSONObject();
        JSONArray returnJsonArray = new JSONArray();
        boolean isSuccess = true;
        try {
            //调用设置的参数,进行循环读取操作
            List<ThirdCmbchinaParamap> parMapList = getThirdCmbchinaParamapService().getParamapData();
            //查询到所有有效的公司配置信息
            if (parMapList.size() > 0) {
                ThirdCmbchinaParamap thirdCmbchinaParamap;
                //客户号
                String clientId;
                //客户秘钥
                String clientSecret;
                //所属公司
                String companyName;
                //成本中心号
                String paramMapCorNum;
                for (int i = 0; i < parMapList.size(); i++) {
                    //每个公司返回的json对象信息
                    JSONObject companyJson = new JSONObject();
                    thirdCmbchinaParamap = parMapList.get(i);
                    if (thirdCmbchinaParamap != null) {
                        clientId = thirdCmbchinaParamap.getClientId();
                        clientSecret = thirdCmbchinaParamap.getClientSecret();
                        companyName = thirdCmbchinaParamap.getCompanyName();
                        paramMapCorNum = thirdCmbchinaParamap.getCorNum();
                        //必须保证请求参数中客户号与客户秘钥不为空
                        if ((!"".equals(clientId) && clientId != "") && (!"".equals(clientSecret) && clientSecret != "") && (!"".equals(paramMapCorNum) && paramMapCorNum != "")) {
                            //封装请求参数
                            //声明参数JSON变量
                            JSONObject paraMapJson = new JSONObject();
                            //声明参数JSONKEY的JSON变量
                            JSONObject paraMapKeyJson = new JSONObject();
                            //放入请求参数
                            paraMapKeyJson.put(CLIENTID, clientId);//客户号
                            paraMapKeyJson.put(CLIENTSECRET, clientSecret);//客户秘钥
                            paraMapJson.put(PARAMAP, paraMapKeyJson);
                            //调用请求方方法
                            JSONObject doPostJson = HttpPostUtil.doPost(GETCARDINFODATAURL, paraMapJson);
                            if (doPostJson != null && !doPostJson.isEmpty() && doPostJson.size() != 0) {
                                if (doPostJson.getBoolean("success")) {
                                    isSuccess = true;
                                    //获取规定的key值,得到JSON数组
                                    if (doPostJson.containsKey("object")) {
                                        JSONArray jsonArray = doPostJson.getJSONArray("object");
                                        if (jsonArray != null) {
                                            //循环保存数据
                                            JSONObject jsonItem;
                                            //在保存数据之前,先根据成本中心号删除掉这个公司的数据,再重新保存新的数据
                                            getThirdCmbchinaBusicardinfoService().deleteCardInfoByCorNum(paramMapCorNum);
                                            for (int z = 0; z < jsonArray.size(); z++) {
                                                jsonItem = jsonArray.getJSONObject(z);
                                                ThirdCmbchinaBusicardinfo cardInfo = new ThirdCmbchinaBusicardinfo();
                                                if (jsonItem != null && !jsonItem.isEmpty()) {
                                                    cardInfo.setCorNum(jsonItem.getString("corNum"));
                                                    cardInfo.setCorChiName(jsonItem.getString("corChiName"));
                                                    cardInfo.setActNum(jsonItem.getString("actNum"));
                                                    cardInfo.setAcctNbr(jsonItem.getString("acctNbr"));
                                                    cardInfo.setCardNumber(jsonItem.getString("cardNumber"));
                                                    cardInfo.setHolderChiName(jsonItem.getString("holderChiName"));
                                                    cardInfo.setHolderEngName(jsonItem.getString("holderEngName"));
                                                    cardInfo.setEmpNumber(jsonItem.getString("empNumber"));
                                                    cardInfo.setActivationCode(jsonItem.getString("activationCode"));
                                                    cardInfo.setActivationDate(jsonItem.getString("activationDate"));
                                                    cardInfo.setCirculationFlag(jsonItem.getString("circulationFlag"));
                                                    cardInfo.setCancelDate(jsonItem.getString("cancelDate"));
                                                    getServiceImp().add(cardInfo);
                                                }
                                            }
                                        }
                                    }
                                } else {
                                    isSuccess = false;
                                }
                                companyJson.put("success", doPostJson.getBoolean("success"));
                                companyJson.put("message", doPostJson.get("message").toString());
                                companyJson.put("msgCode", doPostJson.get("msgCode").toString());
                                companyJson.put("msgCompany", companyName);
                                returnJsonArray.add(companyJson);

                            }
                        }
                    }
                }
            } else {
                returnJsonObject.put("success", false);
                returnJsonObject.put("message", "没有查询到公司配置信息");
                return returnJsonObject;
            }
        } catch (Exception e) {
            e.printStackTrace();
            returnJsonObject.put("success", false);
            returnJsonObject.put("message", "抛出异常");
            return returnJsonObject;
        }
        if (isSuccess) {
            returnJsonObject.put("success", true);
        } else {
            returnJsonObject.put("success", false);
        }
        returnJsonObject.put("message", returnJsonArray);
        return returnJsonObject;
    }
}

招商银行新商务卡交易数据查询接口
  • 接口定义
package com.landray.kmss.third.cmbchina.httpservice;

import com.alibaba.fastjson.JSONObject;
import com.landray.kmss.common.service.IBaseService;

public interface BusiTranDataQuery extends IBaseService {

    /*招商银行新商务卡交易数据查询接口*/
    JSONObject getTranData() throws Exception;
}

  • 接口实现
package com.landray.kmss.third.cmbchina.httpservice.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.landray.kmss.common.service.BaseServiceImp;
import com.landray.kmss.common.service.IBaseService;
import com.landray.kmss.third.cmbchina.httpservice.BusiTranDataQuery;
import com.landray.kmss.third.cmbchina.httpservice.HttpPostUtil;
import com.landray.kmss.third.cmbchina.model.ThirdCmbchinaBusitrandata;
import com.landray.kmss.third.cmbchina.model.ThirdCmbchinaParamap;
import com.landray.kmss.third.cmbchina.service.IThirdCmbchinaBusitrandataService;
import com.landray.kmss.third.cmbchina.service.IThirdCmbchinaParamapService;
import com.landray.kmss.web.annotation.RestApi;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Calendar;
import java.util.List;

import static com.landray.kmss.third.cmbchina.httpservice.HttpPostConstant.*;
import static com.landray.kmss.util.SpringBeanUtil.getBean;

/*
 * @description: 招商银行新商务卡交易数据查询接口实现类
 * @date: 2023/10/24
 */
@Controller
@RequestMapping(value = "/api/third-cmbchina/busiTranDataQuery", method = RequestMethod.POST)
@RestApi(docUrl = "", name = "busiTranDataQueryServiceImp", resourceKey = "third-cmbchina:module.third.cmbchina")
public class BusiTranDataQueryImpl extends BaseServiceImp implements BusiTranDataQuery {

    private IThirdCmbchinaBusitrandataService thirdCmbchinaBusitrandataService;

    public IBaseService getServiceImp() {
        if (thirdCmbchinaBusitrandataService == null) {
            thirdCmbchinaBusitrandataService = (IThirdCmbchinaBusitrandataService) getBean("thirdCmbchinaBusitrandataService");
        }
        return thirdCmbchinaBusitrandataService;
    }

    /*注入接口请求参数方法*/
    private IThirdCmbchinaParamapService thirdCmbchinaParamapService;

    private IThirdCmbchinaParamapService getThirdCmbchinaParamapService() {
        if (thirdCmbchinaParamapService == null) {
            thirdCmbchinaParamapService = (IThirdCmbchinaParamapService) getBean("thirdCmbchinaParamapService");
        }
        return thirdCmbchinaParamapService;
    }

    /**
     * @param
     * @return com.alibaba.fastjson.JSONObject
     * @description: 招商银行新商务卡交易数据查询接口
     * @date: 2023/10/24
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    @ResponseBody
    @RequestMapping(value = "/getTranData", method = RequestMethod.POST)
    public JSONObject getTranData() throws Exception {
        //声明最终返回的变量
        JSONObject returnJsonObject = new JSONObject();
        JSONArray returnJsonArray = new JSONArray();
        boolean isSuccess = true;
        try {
            //调用设置的参数,进行循环读取操作
            List<ThirdCmbchinaParamap> parMapList = getThirdCmbchinaParamapService().getParamapData();
            //查询到所有有效的公司配置信息
            if (parMapList.size() > 0) {
                ThirdCmbchinaParamap thirdCmbchinaParamap;
                //客户号
                String clientId;
                //客户秘钥
                String clientSecret;
                //所属公司
                String companyName;
                //成本中心号
                String paramMapCorNum;
                //入账日期
                String postdate;
                for (int i = 0; i < parMapList.size(); i++) {
                    //每个公司返回的json对象信息
                    JSONObject companyJson = new JSONObject();
                    thirdCmbchinaParamap = parMapList.get(i);
                    if (thirdCmbchinaParamap != null) {
                        clientId = thirdCmbchinaParamap.getClientId();
                        clientSecret = thirdCmbchinaParamap.getClientSecret();
                        companyName = thirdCmbchinaParamap.getCompanyName();
                        paramMapCorNum = thirdCmbchinaParamap.getCorNum();
                        //必须保证请求参数中客户号、客户秘钥、成本中心不为空
                        if ((!"".equals(clientId) && clientId != "") && (!"".equals(clientSecret) && clientSecret != "") && (!"".equals(paramMapCorNum) && paramMapCorNum != "")) {
                            //设置时间,循环时间区间
                            //设置起始日期
                            Calendar startCalendar = Calendar.getInstance();
                            startCalendar.set(2023, Calendar.AUGUST, 1);
                            //设置结束日期
                            Calendar endCalendar = Calendar.getInstance();
                            endCalendar.set(2023, Calendar.AUGUST, 31);
                            //日期循环
                            String monStr;
                            String dayStr;
                            while (startCalendar.compareTo(endCalendar) <= 0) {
                                int year = startCalendar.get(Calendar.YEAR);
                                int month = startCalendar.get(Calendar.MONTH) + 1;
                                int day = startCalendar.get(Calendar.DAY_OF_MONTH);
                                //月份补全
                                if (month < 10) {
                                    monStr = "0" + month + "";
                                } else {
                                    monStr = month + "";
                                }
                                //天数补全
                                if (day < 10) {
                                    dayStr = "0" + day + "";
                                } else {
                                    dayStr = day + "";
                                }
                                postdate = year + "-" + monStr + "-" + dayStr;
                                //封装请求参数
                                //声明参数JSON变量
                                JSONObject paraMapJson = new JSONObject();
                                //声明参数JSONKEY的JSON变量
                                JSONObject paraMapKeyJson = new JSONObject();
                                //放入请求参数
                                paraMapKeyJson.put(CLIENTID, clientId);//客户号
                                paraMapKeyJson.put(CLIENTSECRET, clientSecret);//客户秘钥
                                paraMapKeyJson.put(CORNUM, paramMapCorNum);//成本中心号
                                paraMapKeyJson.put(POSTDATE, postdate);//入账日期
                                paraMapJson.put(PARAMAP, paraMapKeyJson);
                                //调用请求方方法
                                JSONObject doPostJson = HttpPostUtil.doPost(GETTRANSDATAURL, paraMapJson);
                                if (doPostJson != null && !doPostJson.isEmpty() && doPostJson.size() != 0) {
                                    if (doPostJson.getBoolean("success")) {
                                        isSuccess = true;
                                        //获取规定的key值,得到JSON数组
                                        if (doPostJson.containsKey("object")) {
                                            JSONArray jsonArray = doPostJson.getJSONArray("object");
                                            if (jsonArray != null) {
                                                //循环保存数据
                                                JSONObject jsonItem;
                                                for (int z = 0; z < jsonArray.size(); z++) {
                                                    jsonItem = jsonArray.getJSONObject(z);
                                                    ThirdCmbchinaBusitrandata trandata = new ThirdCmbchinaBusitrandata();
                                                    if (jsonItem != null && !jsonItem.isEmpty()) {
                                                        trandata.setCorNum(jsonItem.getString("corNum"));
                                                        trandata.setActNum(jsonItem.getString("actNum"));
                                                        trandata.setAcctNbr(jsonItem.getString("acctNbr"));
                                                        trandata.setBilMon(jsonItem.getString("bilMon"));
                                                        trandata.setBilDate(jsonItem.getString("bilDate"));
                                                        trandata.setCrdNum(jsonItem.getString("crdNum"));
                                                        trandata.setActChiNam(jsonItem.getString("actChiNam"));
                                                        trandata.setActEngNam(jsonItem.getString("actEngNam"));
                                                        trandata.setEmpNum(jsonItem.getString("empNum"));
                                                        trandata.setTrsDte(jsonItem.getString("trsDte"));
                                                        trandata.setTrxTim(jsonItem.getString("trxTim"));
                                                        trandata.setOriCurAmt(jsonItem.getString("oriCurAmt"));
                                                        trandata.setOriCurCod(jsonItem.getString("oriCurCod"));
                                                        trandata.setPosDate(jsonItem.getString("posDate"));
                                                        trandata.setPosCurAmt(jsonItem.getString("posCurAmt"));
                                                        trandata.setPosCurCod(jsonItem.getString("posCurCod"));
                                                        trandata.setAcpCtyCod(jsonItem.getString("acpCtyCod"));
                                                        trandata.setAcpType(jsonItem.getString("acpType"));
                                                        trandata.setAcpId(jsonItem.getString("acpId"));
                                                        trandata.setAcpName(jsonItem.getString("acpName"));
                                                        trandata.setAprCod(jsonItem.getString("aprCod"));
                                                        trandata.setTrxRef(jsonItem.getString("trxRef"));
                                                        trandata.setTrsCod(jsonItem.getString("trsCod"));
                                                        trandata.setTrsVchNbr(jsonItem.getString("trsVchNbr"));
                                                        trandata.setSeqNum(jsonItem.getString("seqNum"));
                                                        getServiceImp().add(trandata);
                                                    }
                                                }
                                            }
                                        }
                                    } else {
                                        isSuccess = false;
                                    }
                                    companyJson.put("success", doPostJson.getBoolean("success"));
                                    companyJson.put("message", doPostJson.get("message").toString());
                                    companyJson.put("msgCode", doPostJson.get("msgCode").toString());
                                    companyJson.put("msgCompany", companyName);
                                    companyJson.put("postdate", postdate);
                                    returnJsonArray.add(companyJson);

                                }
                                //将日期加1
                                startCalendar.add(Calendar.DAY_OF_MONTH, 1);
                            }
                        }
                    }
                }
            } else {
                returnJsonObject.put("success", false);
                returnJsonObject.put("message", "没有查询到公司配置信息");
                return returnJsonObject;
            }
        } catch (Exception e) {
            e.printStackTrace();
            returnJsonObject.put("success", false);
            returnJsonObject.put("message", "抛出异常");
            return returnJsonObject;
        }
        if (isSuccess) {
            returnJsonObject.put("success", true);
        } else {
            returnJsonObject.put("success", false);
        }
        returnJsonObject.put("message", returnJsonArray);
        return returnJsonObject;
    }
}
spring.xml配置bean
    <!--商务卡卡片信息查询接口-->
    <bean id="busiCardInfoQueryServiceImpl" class="com.landray.kmss.third.cmbchina.httpservice.impl.BusiCardInfoQueryImpl"/>

    <!--招商银行新商务卡交易数据查询接口-->
    <bean id="busiTranDataQuerServiceyImpl" class="com.landray.kmss.third.cmbchina.httpservice.impl.BusiTranDataQueryImpl"/>

你可能感兴趣的:(java,http)