China Construction Bank payment interface, query the xml interface for settled orders by date (JAVA version)

Source: Internet
Author: User

The query interface of China Construction Bank is not as comprehensive as that of China Merchants Bank. China Construction Bank does not provide query by order number. If there is no successful order on the date you query, an html will be directly returned to tell you that there is no information, in addition, if you perform cross-day queries and there are many orders, he will return an html to tell you that there are too many orders and they cannot be displayed. So what Lu Ju chooses here is, each time you query data for only one day, if it is a time period, it is split into one day by a program. The following is the parsing core code that is selected to be queried in xml format. [Java] private List <OrderInfo> queryOrderInfoByCcb (String orderDate) {List <OrderInfo> list = new ArrayList <OrderInfo> (); String baseUrl = "https://ibsbjstar.ccb.com.cn/app/ccbMain? "; String MERCHANTID = this. getBankCono (); String BRANCHID = this. getBankBranchid (); String POSID = this. getBankPosId (); String ORDERDATE = orderDate; String BEGORDERTIME = "00:00:00"; String ENDORDERTIME = "23:59:59"; String BEGORDERID = this. getBankPwd (); String ENDORDERID = "9999999999"; String QUPWD = "******"; String TXCODE = "410405"; String SEL_TYPE = "3 "; string OPERATOR = "001"; String ban KURL = ""; String result = ""; string param = "MERCHANTID =" + MERCHANTID + "& BRANCHID =" + BRANCHID + "& POSID =" + POSID + "& ORDERDATE =" + ORDERDATE + "& BEGORDERTIME =" + BEGORDERTIME + "& ENDORDERTIME =" + ENDORDERTIME + "& BEGORDERID =" + BEGORDERID + "& ENDORDERID =" + ENDORDERID + "& QUPWD =" + QUPWD + "& TXCODE =" + TXCODE + "& SEL_TYPE =" + SEL_TYPE + "& OPERATOR =" + OPERATOR + "& bankURL =" + bankURL + "& res Ult = "+ result +" & MAC = "; string tmp = "MERCHANTID =" + MERCHANTID + "& BRANCHID =" + BRANCHID + "& POSID =" + POSID + "& ORDERDATE =" + ORDERDATE + "& BEGORDERTIME =" + BEGORDERTIME + "& ENDORDERTIME =" + ENDORDERTIME + "& BEGORDERID =" + BEGORDERID + "& ENDORDERID =" + ENDORDERID + "& QUPWD = & TXCODE =" + TXCODE + "& SEL_TYPE = "+ SEL_TYPE +" & OPERATOR = "+ OPERATOR; string strMD5 = ByteUtil. byteToChar (MD5Ccb. encode (Tmp. getBytes (); String xml = null; try {String url = baseUrl + param + strMD5; log. debug ("Send http request for CCB query:" + url); xml = HttpClientUtil. getHtml (url);} catch (IOException e) {String msg = "An error occurred while obtaining HTTP access to the CCB reconciliation file. Exception information:" + e. getMessage (); log. error (msg); throw new RuntimeException (msg);} if (xml. contains ("the IP address you are querying is incorrect") {String msg = "query Date:" + orderDate + "-information displayed on the CCB reconciliation system: the IP address you are querying is restricted access. Please contact China Construction Bank to add the server address to the access list before performing reconciliation. Operation. "; Log. error (msg); throw new RuntimeException (msg);} // no record is found based on the query conditions or too many records if (xml. contains ("no records or too many records are found based on query conditions") {String msg = "query Date:" + orderDate + "-prompt information of the CCB reconciliation system: no records are found based on the query conditions or there are too many records. Modify the query date. "; Log. error (msg); return list; // throw new RuntimeException (msg);} xml = xml. trim (); log. debug ("CCB reconciliation file HTTP retrieved successfully: xml length:" + xml. length (); StringReader stringReader = new StringReader (xml); Document doc = null; try {doc = new SAXReader (). read (stringReader);} catch (incluentexception e) {String msg = "XML parsing of the CCB reconciliation file failed, exception information:" + e. getMessage (); log. error (msg); log. error ("xml content:" + xml); throw new RuntimeE Xception (msg);} Element element = doc. getRootElement (); List <Element> orders = element. elements (); for (Element el: orders) {List <Element> orderContexts = el. elements (); double money = 0; // amount String orderNum = null; // order number String orderStatus = null; // order status for (Element orderEl: orderContexts) {// log. debug (orderEl. getName () + "-" + orderEl. getText (); if ("ORDERID ". equals (orderEl. getName () {ord ErNum = orderEl. getText ();} if ("AMOUNT ". equals (orderEl. getName () {money = Double. valueOf (orderEl. getText ();} if ("STATUS ". equals (orderEl. getName () & "success ". equals (orderEl. getText () {orderStatus = "0" ;}} if (money! = 0 &&! StringUtils. isBlank (orderNum )&&! StringUtils. isBlank (orderStatus) {OrderInfo orderInfo = new OrderInfo (); orderInfo. setTradeDate (orderDate); orderInfo. setDealDate (orderDate); orderInfo. setMoney (money); orderInfo. setOrderNum (orderNum); orderInfo. setOrderStatus (orderStatus); list. add (orderInfo);} www.2cto.com} log. debug ("successfully resolved the CCB reconciliation file: Order details:" + list. size ();/* for (OrderInfo orderInfo: list) {log. debug ("successfully resolved the CCB reconciliation file: Order details:" + orderI Nfo. toString ();} */log. debug ("XML parsing of the CCB reconciliation file is complete! "); Return list ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.