java-银行卡基本信息查询

							            <link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/ck_htmledit_views-d7e2a68c7c.css">
					<div class="htmledit_views" id="content_views">

用于验证的请求接口:

https://ccdcapi.alipay.com/validateAndCacheCardInfo.json?_input_charset=utf-8&cardNo=6217002430035835629&cardBinCheck=true

返回:

{"bank":"CCB","validated":true,"cardType":"DC","key":"6217002430035835629","messages":[],"stat":"ok"}
bank 银行的 英文简称

validated 是否通过验证

下面贴个工具类:    使用此工具类可实现链式调用       不要忘记先调用getInstance方法

/**
 * @Author Xi
 * Created by zz.wbkj.xi on 2016/11/2.
 */

public class CardUtils {
<span style="color:#000080;"><strong>public static </strong></span>Map&lt;String,String&gt; <span style="color:#660e7a;"><em>bankName </em></span>= <span style="color:#000080;"><strong>new </strong></span>HashMap&lt;&gt;();

<span style="color:#000080;"><strong>private </strong></span>CardUtils(){
    <span style="color:#660e7a;"><em>bankName</em></span>.put(<span style="color:#008000;"><strong>"ICBC"</strong></span>,<span style="color:#008000;"><strong>"中国工商银行"</strong></span>);
    <span style="color:#660e7a;"><em>bankName</em></span>.put(<span style="color:#008000;"><strong>"BOC"</strong></span>,<span style="color:#008000;"><strong>"中国银行"</strong></span>);
    <span style="color:#660e7a;"><em>bankName</em></span>.put(<span style="color:#008000;"><strong>"CCB"</strong></span>,<span style="color:#008000;"><strong>"中国建设银行"</strong></span>);
    <span style="color:#660e7a;"><em>bankName</em></span>.put(<span style="color:#008000;"><strong>"ABC"</strong></span>,<span style="color:#008000;"><strong>"中国农业银行"</strong></span>);
    <span style="color:#660e7a;"><em>bankName</em></span>.put(<span style="color:#008000;"><strong>"HNRCU"</strong></span>,<span style="color:#008000;"><strong>"河南省农村信用社"</strong></span>);
    <span style="color:#660e7a;"><em>bankName</em></span>.put(<span style="color:#008000;"><strong>"PSBC"</strong></span>,<span style="color:#008000;"><strong>"中国邮政储蓄银行"</strong></span>);
    <span style="color:#660e7a;"><em>bankName</em></span>.put(<span style="color:#008000;"><strong>"CEB"</strong></span>,<span style="color:#008000;"><strong>"中国光大银行"</strong></span>);
    <span style="color:#660e7a;"><em>bankName</em></span>.put(<span style="color:#008000;"><strong>"BCM"</strong></span>,<span style="color:#008000;"><strong>"交通银行"</strong></span>);
    <span style="color:#660e7a;"><em>bankName</em></span>.put(<span style="color:#008000;"><strong>"CMB"</strong></span>,<span style="color:#008000;"><strong>"招商银行"</strong></span>);
    <span style="color:#660e7a;"><em>bankName</em></span>.put(<span style="color:#008000;"><strong>"CMBC"</strong></span>,<span style="color:#008000;"><strong>"民生银行"</strong></span>);
    <span style="color:#660e7a;"><em>bankName</em></span>.put(<span style="color:#008000;"><strong>"CDB"</strong></span>,<span style="color:#008000;"><strong>"国家开发银行"</strong></span>);
    <span style="color:#660e7a;"><em>bankName</em></span>.put(<span style="color:#008000;"><strong>"CIB"</strong></span>,<span style="color:#008000;"><strong>"兴业银行"</strong></span>);
    <span style="color:#660e7a;"><em>bankName</em></span>.put(<span style="color:#008000;"><strong>"BCCB"</strong></span>,<span style="color:#008000;"><strong>"北京市商业银行"</strong></span>);
    <span style="color:#660e7a;"><em>bankName</em></span>.put(<span style="color:#008000;"><strong>"HSBC"</strong></span>,<span style="color:#008000;"><strong>"汇丰银行"</strong></span>);
}

<span style="color:#000080;"><strong>private static class </strong></span>CardUtilsHolder{
    <span style="color:#000080;"><strong>private static </strong></span>CardUtils <span style="color:#660e7a;"><em>holder </em></span>= <span style="color:#000080;"><strong>new </strong></span>CardUtils() ;
}

<span style="color:#000080;"><strong>public static </strong></span>CardUtils getInstance(){
    <span style="color:#000080;"><strong>return </strong></span>CardUtilsHolder.<span style="color:#660e7a;"><em>holder</em></span>;
}

<span style="color:#000080;"><strong>public static </strong></span>String isBank(String bankStr){
    <span style="color:#000080;"><strong>if </strong></span>(<span style="color:#660e7a;"><em>bankName</em></span>.containsKey(bankStr)){
        Log.<span style="font-style:italic;">e</span>(<span style="color:#008000;"><strong>"包含"</strong></span>,bankStr);
        <span style="color:#000080;"><strong>return </strong></span><span style="color:#660e7a;"><em>bankName</em></span>.get(bankStr);
    }
    Log.<span style="font-style:italic;">e</span>(<span style="color:#008000;"><strong>"不包含"</strong></span>,bankStr);
    <span style="color:#000080;"><strong>return </strong></span><span style="color:#008000;"><strong>""</strong></span>;
}

}


使用方法:

String bankName = CardUtils.getInstance().isBank(bankResultBean.getBank());
 可对bankName进行  TextUtils.isEmpty()方法进行判空


posted @ 2018-12-09 18:16  学不死的程序员  阅读(2670)  评论(0编辑  收藏  举报