package com.zzwtec.wechat.util;

import com.zzwtec.third.utils.StringUtil;

/**
 * ${DESCRIPTION}
 *
 * @author dengliaoyan
 * @create 2018/2/24
 */
public class StringSecurityUtil {
    /**
     * 身份证隐藏 将身份证中间的都隐藏，用于表单中的显示
     * @param idNum
     * @return
     */
    public static String getIdSecurity(String idNum){
        if(StringUtil.isEmpty(idNum))return null;
        int longNum = idNum.length();
        StringBuffer security = new StringBuffer();
        for (int i = 0; i < longNum - 2; i ++) {
            security.append("*");
        }
        String newIdNum = new StringBuffer(idNum).replace(1, idNum.length() - 1, security.toString()).toString();
        return newIdNum;
    }
    /**
     * 手机号码隐藏 将手机号码中间4位隐藏，用于表单中的显示
     * @param phone
     * @return
     */
    public static String getPhoneSeccurity(String phone){
        if(StringUtil.isEmpty(phone))return "";
        String result=phone;
        if(StringUtil.notEmpty(phone)&& phone.length()>=11){
            result = phone.substring(0,phone.length()-(phone.substring(3)).length())+"****"+phone.substring(7);
        }
        return result;
    }
}
