征信接口调用,解析(xml)

数据传输格式报文格式:xml
public CisReportRoot queryCisReport(PyQueryBean pyQueryBean) throws Exception {
CisReportRoot cisReportRoot = invokePy(pyQueryBean){
CisReportRoot cisReportRoot = queryCisReportFromPyServer(pyQueryBean);   } } 

pyQueryBean--CisReportRoot 
注意:接口数据传输通过xml,无论发送请求,还是获取响应都需要经过经过xml格式转化。 
1,CisReportRoot cisReportRoot = getCisReportRoot(doc); pyQueryBean--Map--doc--xmL
//实体转化为Map 2,Map<String, String> map = CommonUtils.beanToMap(pyQueryBean);
//Map转化为指定标签的xml字符串 Map-doc-xml 3,String queryInfo = XmlUtil.createQueryCondition(map);
//从鹏元获取Xml,转化为doc xml-doc- 4,Document doc = pyClient.connectToPyClient(queryInfo);
//解析doc中数据,赋值到实体
5,CisReportRoot cisReportRoot = getCisReportRoot(doc); 具体实现如下:
2, public static Map<String, String> beanToMap(Object obj) { if (obj == null) { return null; } Map<String, String> map = new HashMap<>(); try { BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass()); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); for (PropertyDescriptor property : propertyDescriptors) { String key = property.getName(); // 过滤class属性 if (!"class".equals(key)) { // 得到property对应的getter方法 Method getter = property.getReadMethod(); Object value = getter.invoke(obj); map.put(key, String.valueOf(value)); } } } catch (Exception e) { System.out.println("transBean2Map@CommonUtils_Exception" + e); } return map; } 3, 构建请求xml public static String createQueryCondition(Map<String, String> map) throws Exception { Document document = DocumentHelper.createDocument(); document.setXMLEncoding(ENCODING); Element root = document.addElement("conditions"); Element conditionElement = root.addElement("condition"); conditionElement.addAttribute("queryType", map.get("queryType")); Element itemName = conditionElement.addElement("item"); itemName.addElement("name").addText("name"); itemName.addElement("value").addText(map.get("name") == null ? "" : map.get("name")); Element itemDocumentNo = conditionElement.addElement("item"); itemDocumentNo.addElement("name").addText("documentNo"); itemDocumentNo.addElement("value").addText(map.get("documentNo") == null ? "" : map.get("documentNo")); Element itemPhone = conditionElement.addElement("item");
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值