民生银行信用卡电子账单读取

原创
2016/06/04 16:36
阅读数 735
/**
 * 民生银行账单解读
 * Created by LYH on 2015/8/28.
 */
public class MinShengBankBill {
    public static String temp_hello = "尊敬的";
    public static String temp_cardbill = "您好!感谢您使用本行信用卡,特别呈上您";
    public static List<TempBillModal> readBillModal(String mailContent){
        //public static TempBillModal readBill(Document document) {
        List<TempBillModal> tempBillModalList = new ArrayList<TempBillModal>();
        TempBillModal billModal = new TempBillModal();
        Document document = Jsoup.parse(mailContent);
        tempBillModalList.add(billModal);
        //持卡人
        String cardUserStr = document.select("font:containsOwn(尊敬的)").first().text();
        cardUserStr = cardUserStr.substring(cardUserStr.indexOf(temp_hello) +temp_hello.length(),cardUserStr.indexOf(":"));
        billModal.setCarduser(cardUserStr);
        System.out.println("持卡人:"+cardUserStr);
        //账单月份
        String billStr = document.select("font:containsOwn(您好!感谢您使用本行信用卡,特别呈上您)").first()
                .parent()
                .parent()
                .nextElementSibling()
                .text();
        String year= billStr.substring(0,billStr.indexOf("年"));
        billStr = billStr.substring(billStr.indexOf("年")+1,billStr.indexOf("月"));
        if(billStr.trim().indexOf("0")==0){
            billStr = billStr.substring(1,billStr.length());
        }
        int month = Integer.parseInt(billStr);
        billModal.setBillmonth(month);
        System.out.println("账单月份:"+billStr);
        //账单日
        Elements billDateElements = document.select("font:containsOwn(Statement Date)").first().parents();
        String billDateStr = billDateElements.get(10).nextElementSibling().text().replaceAll("/", "-");
        billModal.setBilldate(billDateStr);
        System.out.println("账单日:"+billDateStr);
        //还款日
        Elements repayElements = document.select("font:containsOwn(Payment Due Date)").first().parents();
        String repayDateStr = repayElements.get(10).nextElementSibling().text().replaceAll("/", "-");
        billModal.setRepaydate(repayDateStr);
        System.out.println("还款日:"+repayDateStr);

        Element repayElement = document.select("font:containsOwn(RMB/USD Account)").first().parents().get(10);
        //本期应还金额
        String needPayStr = repayElement.nextElementSibling().text().replace("RMB ", "").replaceAll(",", "").replaceAll("   ","");
        billModal.setNeddrepay(new BigDecimal(needPayStr));
        System.out.println("应还金额:"+needPayStr);
        //最低应还金额
        String lowPayStr = repayElement.nextElementSibling()
                .nextElementSibling().text().replace("RMB ", "").replaceAll(",", "").replaceAll("   ","");
        billModal.setLowrepay(new BigDecimal(lowPayStr));
        System.out.println("最低还款金额:" + lowPayStr);
        billModal.setBillDetailList(new ArrayList<BillDetail>());
        billModal.setBankname("民生银行");
        //交易明细
        Elements detailElements = document.select("span#loopband3").first()
                .child(0)
                .child(0)
                .children();
        for(Element detailElement:detailElements){
            BillDetail billDetail = new BillDetail();
            billModal.getBillDetailList().add(billDetail);
            Element detail = detailElement.child(0)
                    .child(0)
                    .child(0)
                    .child(0)
                    .child(1)
                    .child(0)
                    .child(0)
                    .child(0)
                    .child(0)
                    .child(0)
                    .child(0)
                    .child(0)
                    .child(0);
            String detailDateStr = detail.child(1).text();
            detailDateStr = year+"-"+detailDateStr.replaceAll("/","-");
            billDetail.setTradedate(detailDateStr);
            System.out.println("交易日:"+detailDateStr);
            String detailStr = detail.child(3).text();
            billDetail.setDetail(detailStr);
            System.out.println("交易摘要:"+detailStr);
            String detailMoneyStr = detail.child(4).text().replace(",","");
            billDetail.setMoney(new BigDecimal(detailMoneyStr));
            System.out.println("交易金额:"+detailMoneyStr);
            String cardLastNum = detail.child(5).text();
            System.out.println("卡号后四位:"+cardLastNum);
        }
        return tempBillModalList;
    }

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

 

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部