农业银行信用卡电子账单读取

/**
 * Created by LYH on 2015/8/28.
 */
public class NongYeBankBill  {
    public static String temp_hello="尊敬的";
    public static String temp_nick="先生/女士:";
    // public static  List readBill(Document document) {
           public static List readBill(String mailContent) {
        List tempBillModalList = new ArrayList();
        TempBillModal billModal = new TempBillModal();
        Document document = Jsoup.parse(mailContent);
        tempBillModalList.add(billModal);
        //持卡人
        String cardUserStr = document.select("font:containsOwn(先生/女士)").text();
        cardUserStr = cardUserStr.substring(cardUserStr.indexOf(temp_hello)+temp_hello.length(),
                cardUserStr.indexOf(temp_nick));
        billModal.setCarduser(cardUserStr);
        System.out.println(cardUserStr);
        //账单日
        String billDateStr = document.select("font:containsOwn(账单日)").first().parent().parent().
                nextElementSibling()
                .text();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
        try {
            Date date = simpleDateFormat.parse(billDateStr);
            billDateStr = TimeUtils.getTime(date, TimeUtils.SIMPLE_DATE_FORMAT);
        } catch (ParseException e) {

        }
        billModal.setBilldate(billDateStr);
        System.out.println("账单日"+billDateStr);
        String year = billDateStr.substring(0, billDateStr.indexOf("-"));
        System.out.println("年份为:"+year);
        //信用额度
        String creditLimitStr = document.select("font:containsOwn(信用额度)").first().parent().parent().
                nextElementSibling()
                .text();
        creditLimitStr = creditLimitStr.substring(0,creditLimitStr.indexOf(" CNY"));
        billModal.setCreditlimit(new BigDecimal(creditLimitStr));
        System.out.println("信用额度:"+creditLimitStr);
        Elements cardinfoElement = document.select("table[style*=border-color:#489191]");
        Element cardElement = cardinfoElement.get(1);
        Element card = cardElement.child(0).children().select("table").get(0).child(0).child(0);
        String cardInfo = card.child(0).text();
        cardInfo = cardInfo.substring(cardInfo.length()-4,cardInfo.length());
        billModal.setCardlastnum(cardInfo);
        System.out.println("卡号信息:" + cardInfo);
        Elements cardElement2 = card.child(1).getElementsByTag("table").get(1).getElementsByTag("td");
        String needpayStr = cardElement2.get(2).text();
        billModal.setNeddrepay(new BigDecimal(needpayStr));
        System.out.println("本期应还:"+needpayStr);
        String lowpayStr = cardElement2.get(3).text();
        billModal.setLowrepay(new BigDecimal(lowpayStr));
        System.out.println("最低还款:" + lowpayStr);
        String payDateStr =card.child(2).text();
        try {
            Date date = simpleDateFormat.parse(payDateStr);
            payDateStr = TimeUtils.getTime(date, TimeUtils.SIMPLE_DATE_FORMAT);
        } catch (ParseException e) {

        }
        billModal.setRepaydate(payDateStr);
        billModal.setBankname("农业银行");
        System.out.println("本期还款日:"+payDateStr);
        //明细
        billModal.setBillDetailList(new ArrayList());
        Elements  element= document.select("div#loopband1").first().child(0).child(0).children();
        for(Element trade:element){
            BillDetail billDetail = new BillDetail();
            billModal.getBillDetailList().add(billDetail);
            Element dateEle = trade.select("table").get(2).child(0).child(0);
           // System.out.println(trade);
            String  tradeDateStgr = dateEle.child(1).text();
            tradeDateStgr = year+tradeDateStgr;
            try {
                Date date = simpleDateFormat.parse(tradeDateStgr);
                tradeDateStgr = TimeUtils.getTime(date, TimeUtils.SIMPLE_DATE_FORMAT);
            } catch (ParseException e) {}
            billDetail.setTradedate(tradeDateStgr);
            System.out.println("交易日:"+tradeDateStgr);
            String dateDetailStr = dateEle.child(4).text()+" "+dateEle.child(5).text();
            billDetail.setDetail(dateDetailStr);
            System.out.println("交易详情"+dateDetailStr);
            String cardNumStr = dateEle.child(3).text();
            System.out.println("卡号后四位"+cardNumStr);
            String tradeMoneyStr = dateEle.child(7).text().replaceAll("/CNY","");
            billDetail.setMoney(new BigDecimal(tradeMoneyStr));
            System.out.println("交易金额:"+tradeMoneyStr);

        }

        return tempBillModalList;
    }

    /*public static void main(String[] args) {
        try {
            Document document = Jsoup.connect("http://127.0.0.1/card/nongye.html").get();
            NongYeBankBill.readBill(document);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }*/
}

 

转载于:https://my.oschina.net/riaway/blog/687129

你可能感兴趣的:(农业银行信用卡电子账单读取)