java call payment platform API - generate XML parameters traverse Bean

2010-04-25  来源:本站原创  分类:Java  人气:205 

Have always wanted to record their own stuff done, however, has been busy, no time (in fact, their lazy, hehe), today finally decided to start operations, has recently become a e-commerce site on the ticket, come into contact with payment platform interactive things, in fact, theoretically speaking, this is SO EASY, is the call to support the platform API, and then, pass parameters, return results payment platform, and then pile in their own database Update. In fact, I wanted to talk about today, when the call payment platform API like how simple and convenient way to pass parameters
I contacted the payment platform, called API requires incoming XML format parameter, the returned data format is XML, the parameter format is as follows:
<? Xml version = "1.0" encoding = "UTF-8"?>
<MasMessage Xmlns="">
<version> 1.0 </ version>
<txnType> PUR </ txnType>
<interactiveStatus> TR1 </ interactiveStatus>
<cardNo> XXXXXXXXXXXXX </ cardNo>
<expiredDate> 0811 </ expiredDate>
<cvv2> 123 </ cvv2>
<amount> 100 </ amount>
<merchantId> XXXXXXXXXX </ merchantId>
<terminalId> XXXXX </ terminalId>
<cardHolderName> test </ cardHolderName>
<cardHolderId> 130928198310000004 </ cardHolderId>
<entryTime> 20090330153345 </ entryTime>
<externalRefNumber> PUR_NET985534 </ externalRefNumber>
<customerId />
</ TxnMsgContent>
</ MasMessage>
Not elaborate on the contents of the above, anyway, is a bunch of parameters, I do organizational parameters, first of all to make a Bean, Bean is the XML attribute name for each node, as follows:

public class PURTR1XMLMessage (

/ / Transaction type: PUR = real consumption, PRE = pre-authorization (three fixed-length alphabetic characters)
private String txnType;

/ / Message status: value TR1 (3 bit fixed length alphabetic characters)
private String interactiveStatus;

/ / Credit card numbers (up to 19 bytes (numeric character))
private String cardNo;

/ / Card is valid (four fixed-length numeric characters; format MMYY)
private String expiredDate;

/ / Card verification code (three fixed-length numeric characters)
private String cvv2;

/ / Transaction amount (up to 12-bit, 2 decimal point)
private String amount;

/ / Business number, this number test (client should be configured)
private String merchantId;

/ / Terminal number, this number test (client should be configured) (8-bit fixed length of letters and numeric characters)
private String terminalId;

/ / Cardholder name (up to 32 bytes (letters and numeric characters), for Chinese)
private String cardHolderName;

/ / Holder identification number (up to 32 bytes (letters and numeric characters))
private String cardHolderId;

/ / Client transaction time (the number of 14-bit fixed-length character format is yyyyMMddHHmmss)
private String entryTime;

/ / Application side order number (32 numbers and letters)

private String externalRefNumber;

/ / Customer number (empty)
private String customerId;

public PURTR1XMLMessage () (
public String getTxnType () (
return txnType;

public void setTxnType (String txnType) (
this.txnType = txnType;

public String getInteractiveStatus () (
return interactiveStatus;

public void setInteractiveStatus (String interactiveStatus) (
this.interactiveStatus = interactiveStatus;

public String getCardNo () (
return cardNo;

public void setCardNo (String cardNo) (
this.cardNo = cardNo;

public String getExpiredDate () (
return expiredDate;

public void setExpiredDate (String expiredDate) (
this.expiredDate = expiredDate;

public String getCvv2 () (
return cvv2;

public void setCvv2 (String cvv2) (
this.cvv2 = cvv2;

public String getAmount () (
return amount;

public void setAmount (String amount) (
this.amount = amount;

public String getMerchantId () (
return merchantId;

public void setMerchantId (String merchantId) (
this.merchantId = merchantId;

public String getTerminalId () (
return terminalId;

public void setTerminalId (String terminalId) (
this.terminalId = terminalId;

public String getCardHolderName () (
return cardHolderName;

public void setCardHolderName (String cardHolderName) (
this.cardHolderName = cardHolderName;

public String getCardHolderId () (
return cardHolderId;

public void setCardHolderId (String cardHolderId) (
this.cardHolderId = cardHolderId;

public String getEntryTime () (
return entryTime;

public void setEntryTime (String entryTime) (
this.entryTime = entryTime;

public String getExternalRefNumber () (
return externalRefNumber;

public void setExternalRefNumber (String externalRefNumber) (
this.externalRefNumber = externalRefNumber;

public String getCustomerId () (
return customerId;

public void setCustomerId (String customerId) (
this.customerId = customerId;

Then, I wrote a class to the bean into XML, the code is as follows:
public class PURModel (

public static String beanToXml (Object bean) throws IllegalArgumentException, SecurityException, IllegalAccessException, InvocationTargetException, NoSuchMethodException (
java.lang.reflect.Field [] flds = bean.getClass (). getDeclaredFields ();
String fieldXML = getClassFields (flds, bean);
StringBuffer queryXML = new StringBuffer ("<? Xml version = \" 1.0 \ "encoding = \" UTF-8 \ "?>"+
"<MasMessage Xmlns=\"\">" +
"<version> 1.0 </ version>");

if (bean instanceof PURTR1XMLMessage) (
queryXML.append ("<TxnMsgContent>");
queryXML.append (fieldXML);
queryXML.append ("</ TxnMsgContent> </ MasMessage>");
else if (bean instanceof PURTR3XMLMessage) (
queryXML.append ("<QryTxnMsgContent>");
queryXML.append (fieldXML);
queryXML.append ("</ QryTxnMsgContent> </ MasMessage>");
return queryXML.toString ();
private static String getClassFields (java.lang.reflect.Field [] flds, Object msg) throws IllegalArgumentException, SecurityException, IllegalAccessException, InvocationTargetException, NoSuchMethodException (
String xml = "";
if (flds! = null) (
for (int i = 0; i <flds.length; i + +) (
String getMethod = "get" + flds [i]. GetName (). Substring (0, 1). ToUpperCase () + flds [i]. GetName (). Substring (1);
Class [] methodParam = null;
Object [] params = ();
Object retValue = null;
/ / Here is the get method is called Bean, Henshuang Oh, in the base class for writing in! ! !
retValue = msg.getClass (). getMethod (getMethod, methodParam). invoke (msg, params);
if (retValue == null) (
xml = xml + "<" + flds [i]. getName ()+"/>";
else (
xml = xml + "<" + flds [i]. getName ()+">"+ retValue + "</"+ flds [i]. getName ()+">";
return xml;
This transfer came just need to Bean, Bean can automatically traverse the property, organized into XML, traverse the Bean property using a type of reflection,

getDeclaredFields (): returns an array of Field objects, these objects reflect the Class object that the class or interface declared in all the fields. Including public, protected, default (package) access and private fields, but does not include inherited fields. Return the array element does not sort, nor any particular order. If the class or interface does not declare any field, or this Class object represents a basic type, an array class or void, then this method returns an array of length 0

  • java call payment platform API - generate XML parameters traverse Bean 2010-04-25

    Have always wanted to record their own stuff done, however, has been busy, no time (in fact, their lazy, hehe), today finally decided to start operations, has recently become a e-commerce site on the ticket, come into contact with payment platform in

  • java call payment platform API - parsing XML bean to return 2010-04-25

    The one mentioned how to traverse the generated xml bean parameters, this one, talk about how to return the xml parsing payment platform to return to the form bean. Analytical articles on the xml that is considerably much more attractive, in order to

  • 使用java concurrent调用xmlp api生成pdf 2012-03-09

    目的:通过java concurrent调用XML Publisher API处理XML Data Definition和rtf 模板生成PDF报表. 环境:Oracle EBS R12.0.4 技术:Oracle, Java, XML Publisher 步骤: 1.创建XML数据定义文件(EmpDataTemplate.xml)并上传至服务器的/home/applprod/test4bip/目录: <?xml version="1.0" encoding="UTF-

  • Production reports using Fusion Charts (dom4j generate XML) 2011-10-01

    For the first time that Fusion Charts is Bug Free, there is a statistical function, see the data report, implementation of Flash, and Open Flash Chart is similar, but different data formats. OFC using JSON data, and Fusion Chart to use XML data, OFC

  • Java EE 6 Platform草案包含了Web Profile 2012-03-09

    作者 Dionysios G. Synodinos译者 宋玮 发布于 2009年2月3日 下午10时55分 社区 Java 主题 Enterprise Application Blocks 标签 Java EE Java EE 6 Platform规范的公共草案已经发布了,其将对公众评估和反馈保持开放,直到2009年2月23日为止. 或许这一 迟到的草案最引人注目的地方就是Web Profile,这是Java EE平台历史上第一个profile. 规范的领导者Roberto Chinnici对这

  • Mainstream business processes About Payment Platform 2010-05-04

    Reproduced the self-site blog: Click It Mainstream business processes About Payment Platform simpleCoder (*** Intern) Abstract: Entering the new century, with the computer Wangluo, communication technology, rapid development, particularly Internet ap

  • java使用xpath和dom4j解析xml 2014-05-26

    XPath是一门在XML文档中查找信息的语言,下面介绍一下java使用xpath和dom4j解析xml的示例,大家参考使用吧 1 XML文件解析的4种方法 通常解析XML文件有四种经典的方法.基本的解析方式有两种,一种叫SAX,另一种叫DOM.SAX是基于事件流的解析,DOM是基于XML文档树结构的解析.在此基础上,为了减少DOM.SAX的编码量,出现了JDOM,其优点是,20-80原则(帕累托法则),极大减少了代码量.通常情况下JDOM使用时满足要实现的功能简单,如解析.创建等要求.但在底层,

  • JAVA 中的四种解析XML方式 2013-08-24

    解析XML XML现在已经成为一种通用的数据交换格式,平台的无关性使得很多场合都需要用到XML.本文将详细介绍用Java解析 XML的四种方法. XML现在已经成为一种通用的数据交换格式,它的平台无关性,语言无关性,系统无关性,给数据集成与交互带来了极大的 方便.对于XML本身的语法知识与技术细节,需要阅读相关的技术文献,这里面包括的内容有DOM(Document Object Model),DTD(Document Type Definition),SAX(Simple API for XML

  • Java程序员的10道XML面试题 2014-04-18

    包括 web开发人员的Java面试 在内的各种面试中,XML面试题在各种编程工作的面试中很常见.XML是一种成熟的技术,经常作为从一个平台到其他平台传输数据的标准.XML面试问题包括用于转换XML文件的XSLT技术, XPATH ,XQuery等各种XML技术和XML基础知识,比如DTD或者Schema. 本文将看到10道常见的XML面试问答题.这些问题大部分在Java面试中会问到,同时在C,C++,Scala或其他语言的编程面试中同样很有用处.XML并不依赖于其他编程语言,同SQL一样是编程人

  • how to generate XML using PHP 2010-07-15

    PHP generated XML file with the common methods are as follows: [Content] XML file <? Xml version = "1.0" encoding = "utf-8"?> <article> <item> <title size="1"> title1 </ title> <content> co

  • Java Cryptography Extension: Unsupported keysize or algorithm parameters 2010-08-17

    A recent return to pay to get results, but to pay the resulting url is too long to get results. String ItemUrl = "https://XXXXXXXXXXXXXXXXXXXXXXXXXXXX";// Longer url BufferedReader bufferedreader = null; StringBuffer stringbuffer = new StringBuf

  • java调用百度定位api服务获取地理位置示例 2013-10-01

    java调用百度定位api服务获取地理位置示例,大家参考使用吧 package test; import; import; import; import; import; import; import java.nio.charset.Charset; import

  • JAVA Map架构和API介绍 2014-04-18

    JAVA Map架构和API介绍:Map.Map.Entry.AbstractMap.SortedMap. NavigableMap.Dictionary. 首先,我们看看Map架构. 如上图: Map 是映射接口,Map中存储的内容是键值对(key-value). AbstractMap 是继承于Map的抽象类,它实现了Map中的大部分API.其它Map的实现类可以通过继承AbstractMap来减少重复编码. SortedMap 是继承于Map的接口.SortedMap中的内容是排序的键值对

  • java使用淘宝API读写json实现手机归属地查询功能代码 2014-06-02

    本文介绍java使用淘宝API读写json实现手机归属地查询功能,代码简单,大家可以参考使用 一般查询手机归属地内容应该很好用json格式保存,在网上找到了淘宝的归属地API,并下了处理json相关的jar包,做了这个手机归属地查询功能 package; import; import; import; import

  • [Python]XML文件解析之SAX(Simple API for XML) 2012-05-25

    常见的XML编程接口有DOM和SAX,这两种接口处理XML文件的方式不同,当然使用场合也不同. DOM和SAX的区别 DOM(Document Object Model):将XML数据在内存中解析成一个树,通过对树的操作来操作XML. SAX(Simple API for XML):采用事件驱动模型,通过在解析XML的过程中触发一个个的事件并调用用户定义的回调函数来处理XML文件. 因DOM需要将XML数据映射到内存中的树,一是比较慢,二是比较耗内存,而SAX流式读取XML文件,比较快,占用内存

  • About Sina open microblogging platform API and Java client Tucao 2011-07-31

    The next weekend with an open platform microblogging Sina official release of the API and the Java client, you can use two words to describe feelings: pit father! First talk about the encounter of several extremely mentally retarded bug it: 1) Page I

  • Memcached Study Notes - Part IV: Memcached Java client-gwhalin (5) - Main API to parse 2011-07-10

    Looking for a long time can not find the official APIdoc, trees have a way, only to see the source code for finishing one. SocketIOPool Mainly responsible for the client connection pool, communications and positioning. After version 2.6.0 is implemen

  • HIbernate in line with Java custom relational database persistence of XML configuration 2010-03-29

    Hibernate-mapping <hibernate-mapping schema = "schemaName" (1) catalog = "catalogName" (2) default-cascade = "cascade_style" (3) default-access = "field | property | ClassName" (4) default-lazy = "true | fal

  • Read the information from excel and generate XML document structure 2010-10-11

    There is such a demand, a excel file, which describes the structure of a xml document. We need to do a tool, read the excel content and generates the structure of the document. Save the form in which information is the key to this article. For exampl

  • Jdom generate XML data, XML and access methods 2011-04-29

    Use this project to XML, which generates two XML files to write to, and can read the XML content. With Jdom (Jdom is Java language to read, write, operation of the new XML API functions. Jdom tree operation is based on pure Java API, is a set of pars