兴业银行电子账单读取

/**
 * 兴业银行
 * Created by LYH on 2015/8/27.
 */
public class XingYeBankBill {
    public static String temp_credit_en="Credit Limit(RMB)";
    public static String temp_crash = "预借现金额度(人民币)";
    public static String temp_crash_en = "Cash Advance Limit(RMB)";
    public static String temp_payment_date = "Payment Due Date ";
    public static String temp_newbalance = "本期应还款总额";
    public static String temp_newbalance_en = "New Balance RMB ";
    public static String temp_mini_paymen ="本期最低还款额";
    public static String temp_mini_pay_en = "Minimum Payment RMB ";
    public static List<TempBillModal> readBill(String mailContent){
        //public static List<TempBillModal> readBill(Document document){
        List<TempBillModal> tempBillModalList = new ArrayList<TempBillModal>();
        TempBillModal billModal = new TempBillModal();
        tempBillModalList.add(billModal);
        Document document = Jsoup.parse(mailContent);
        //设置银行名称
        billModal.setBankname("兴业银行");
        //持卡人
        String cardUserStr = document.select("td:containsOwn(尊敬的 )").first().text();
        cardUserStr = cardUserStr.replace("尊敬的 ","").replace(" 您好!","");
        billModal.setCarduser(cardUserStr);
        System.out.println("持卡人:"+cardUserStr);
        //账单月份
        Element billMonthElement = document.select("td:containsOwn(感谢您选择兴业银行)").first();
        String billMonthDateStr = billMonthElement.select("b:containsOwn(年)").first().text();
        //每月的7号为账单日
        String billDateStr = billMonthDateStr.replaceAll("年","-").replaceAll("月","-")+"07";
        billMonthDateStr = billMonthDateStr.substring(billMonthDateStr.indexOf("年")+1,billMonthDateStr.indexOf("月"));
        if(billMonthDateStr.trim().indexOf("0")==0){
            billMonthDateStr = billMonthDateStr.substring(1,billMonthDateStr.length());
        }
        billModal.setBillmonth(Integer.parseInt(billMonthDateStr));
        System.out.println("账单月份:"+billMonthDateStr);
        //卡号后四位
        String cardLastNumStr = billMonthElement.select("b:containsOwn(卡号末四位)").text();
        cardLastNumStr = cardLastNumStr.substring(cardLastNumStr.indexOf("卡号末四位")+6,cardLastNumStr.indexOf(")"));
        billModal.setCardlastnum(cardLastNumStr);
        System.out.println("卡号后四位:"+cardLastNumStr);
        //账单日<td width="42%"> 账单周期 <font face="times new roman">Statement Cycle</font> <span style="border-bottom:1px dashed #ccc;" t="5" times="">2015/07/06</span>-<span style="border-bottom-width: 1px; border-bottom-style: dashed; border-bottom-color: rgb(204, 204, 204);" t="5" times="">2015/08/05</span> <br> 信用额度(人民币) <font face="times new roman">Credit Limit(RMB)</font> 32,000 <br> 预借现金额度(人民币) <font face="times new roman">Cash Advance Limit(RMB)</font> 16,000 </td>
        Element billElement = document.select("td:containsOwn(账单周期)")
                .first();

       /* String billDateStr = billElement//td
                .child(2)//td span
                .text();
       // billDateStr = billElement.select("font:containsOwn");
        billDateStr = billDateStr.replaceAll("/","-");*/
        billModal.setBilldate(billDateStr);
        System.out.println("账单日期:"+billDateStr);
        String billStr = billElement.text();
        //信用额度
        String creditLimitStr = billStr.substring(billStr.indexOf(temp_credit_en)+temp_credit_en.length(),
                billStr.indexOf(temp_crash)).trim();
        creditLimitStr = creditLimitStr.replaceAll(",","");
        billModal.setCreditlimit(new BigDecimal(creditLimitStr));
        System.out.println("信用额度:"+creditLimitStr.trim());
        //取现额度
        String crashLimitStr = billStr.substring(billStr.indexOf(temp_crash_en)+temp_crash_en.length()).trim();
        crashLimitStr = crashLimitStr.replaceAll(",","");
        billModal.setCrashlimit(new BigDecimal(creditLimitStr));
        System.out.println("取现额度:"+ crashLimitStr);
        //还款日
        Element payElement = document.select("font:containsOwn(到期还款日)").first().parent();
        String payStr = payElement.text();
        String dayPayStr = payStr.substring(payStr.indexOf(temp_payment_date)+temp_payment_date.length(),
                payStr.indexOf(temp_newbalance));
        dayPayStr = dayPayStr.replace("年","-").replace("月", "-").replace("日","").trim();
        billModal.setRepaydate(dayPayStr);
        System.out.println("还款日:"+dayPayStr);
        //需要还款
        String needPayStr = payStr.substring(payStr.indexOf(temp_newbalance_en)+temp_newbalance_en.length(),
                payStr.indexOf(temp_mini_paymen)).trim();
        needPayStr = needPayStr.replaceAll(",","");
        billModal.setNeddrepay(new BigDecimal(needPayStr));
        System.out.println("需要还款:"+needPayStr);
        //最低还款
        String lowPayStr = payStr.substring(payStr.indexOf(temp_mini_pay_en)+temp_mini_pay_en.length());
        lowPayStr = lowPayStr.replaceAll(",","");
        billModal.setLowrepay(new BigDecimal(lowPayStr));
        System.out.println("最低还款:" + lowPayStr);
        billModal.setBillDetailList(new ArrayList<BillDetail>());
        //交易明细
        System.out.println("-----------------下面是交易明细------------------");
        Element tradeElement = document.select("td:containsOwn(交易摘要)").first()
                .parent()//tr
                .parent();//tobdy
        Elements  tradeChilds = tradeElement.children();
        for(int i=1;i<tradeChilds.size();i++){

            Element  trade= tradeChilds.get(i);
            if(trade.children().size()>2){//默认一行的提示直接跳过
                BillDetail billDetail = new BillDetail();
                billModal.getBillDetailList().add(billDetail);
                String tradDateStr = trade.child(0).text();
                String tradeDetail = trade.child(2).text();
                String tradeMoney = trade.child(4).text().replaceAll(",","");
                billDetail.setMoney(new BigDecimal(tradeMoney));
                billDetail.setTradedate(tradDateStr);
                billDetail.setDetail(tradeDetail);
                System.out.println("交易日期:" + tradDateStr);
                System.out.println("交易类型:"  +tradeDetail);
                System.out.println("交易金额:"+tradeMoney);
            }else{
                continue;
            }
        }
        return tempBillModalList;
    }

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

 

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值