println("Hello JSRUN!   \n\n         - from Groovy .")

println 1..6
println 1..<6
println 'a'..'h'
println 'a'..<'h'

def range = 1..5
println range[2]
println range.get(2)
println range.getFrom()
println range.getTo()
println range.contains(4)
println range.subList(1, 3)
println range.size()
range = 5..1
println range.isReverse()

range.each {
    print "${it} "
}
println()
for (i in range) {
    print "${i} "
}
println()

def num = 15
switch (num) {
    case 1..<10:
        println "1 ~ 10"
        break
    case 10..<20:
        println "10 ~ 20"
        break
    default:
        println "> 20"
}
shadaileng(Shadaileng非飞) - 2019-07-09 0 人
range
println("Hello JSRUN!   \n\n         - from Groovy .")

println 1..6
println 1..<6
println 'a'..'h'
println 'a'..<'h'

def range = 1..5
println range[2]
println range.get(2)
println range.getFrom()
println range.getTo()
println range.contains(4)
println range.subList(1, 3)
println range.size()
range = 5..1
println range.isReverse()

range.each {
    print "${it} "
}
println()
for (i in range) {
    print "${i} "
}
println()

def num = 15
switch (num) {
    case 1..<10:
        println "1 ~ 10"
        break
    case 10..<20:
        println "10 ~ 20"
        break
    default:
        println "> 20"
}
shadaileng(Shadaileng非飞) - 2019-07-09 0 人
range
println("Hello JSRUN!   \n\n         - from Groovy .")
kevinwu(null) - 2019-04-05 0 人
这是我的一个测试代码
import com.alibaba.common.lang.StringUtil
import groovy.json.JsonSlurper

import java.util.regex.Pattern

class Groovy1 {

    def split(String line) {
        try {
            if (!line.contains("query bio status list from mic request :")) {
                return null;
            }
            line.find("[\\w+]")
            Pattern.compile(/aaa/)

            List<String[]> result = new ArrayList<String[]>();
            result.add(fields);
            return result;

        } catch (Exception e) {
            return null;
        }
    }


    static void main(def args) {
//        Groovy1 groovy = new Groovy1()
        def jsonSlurper = new JsonSlurper()
        def string = """2019-01-10 19:00:29,787 INFO impl.VerifyProductManagerFacadeImpl - [0ba634751547118029510307154685],query bio status list from mic request : {"envData":{"deviceType":"android","appVersion":"10.1.55.5481","osVersion":"9","appName":"com.eg.android.AlipayGphone","bioMetaInfo":"3.28.0:4307394624,6","apdidToken":"XDW3kbV5Pj8qX7OKGqBipjgbe01uggWVy9sKPZL0TFEc4Cc3aAEAAA==","deviceModel":"MI 8","sdkVersion":"3.1.55.100","apdid":"eYOIkhsTIM50mYSj5YvNPfz0Nhb8UVVy1ETEZlFFRjWDQlnuEkVBdABp","deviceName":"Xiaomi","mcSdkVersion":"10.8.23"},"menuRequest":{"secData":"{"dv":"17","rt":"0","sv":"","di":"NDgwZWEwZDKX1df_iTblNVuieH1t8XJEa0f5Zud5BPIXzZ5zBbjNEzRaQVsu2Xtp;NFpDR0twM0dZMnk0Nmk5eS94OU1ZN041S090ckRBVjh2eEN6enYxMw==","bi":"1#1#2#0#2#20#100#11#2#1#1;2#0#2#0#2#1#10#11#0#0#0","ai":"2#1#0#2#20#100#11;2#2#0#2#1#10#11","cm":"Xiaomi#ursa","pm":"MI 8","pn":"com.eg.android.AlipayGphone","ap":""}","sceneId":"mobileic_biopay_biopay_setup_alipay_mobileClient","language":"zh-Hans"},"sceneId":"mobileic_biopay_biopay_setup_alipay_mobileClient","userId":"2088302479504424"}"""
        println(string.find(~/\[(\w+)\]/) { match, traceId -> return traceId })
        def request = jsonSlurper.parseText(string.find(~/\"envData\"\:(\{.*?\})/) { match, request -> return request })
        def secData = jsonSlurper.parseText(string.find(~/\"secData\"\:\"(\{.*?\})/) { match, secData -> return secData })
        def dateTime = string.find(~/\d{4}\-\d{2}\-\d{2}\s.+?\s/)
        println(secDataFromJson(secData))
    }

    static List<BICDataModel> secDataFromJson(Object data) {
        if (data == null) {
            return null;
        }

        List<BICDataModel> models = new ArrayList<BICDataModel>();

        String authInfo = data.ai;
        String deviceId = data.di;
        String authParameter = data.ap;
        String serviceVersion = data.sv;
        String phoneModel = data.pm;
        String cpModel = data.cm;
        String secDataVersion = data.dv;
        String root = data.rt;
        String bioInfo = data.bi;
        String appPackage = data.pn;

        boolean isAiFound = !(authInfo == null || authInfo.trim().equals(""));
        boolean isBiFound = !(bioInfo == null || bioInfo.trim().equals(""));

        if ((isAiFound == false) && (isBiFound == false)) {
            return null;
        }

        String[] deviceIdList = { "" };
        String[] authParameterList = { "" };
        String[] phoneModelList = { "" };

        if (deviceId != null) {
            deviceIdList = deviceId.split(";");
            for (int i = 0; i < deviceIdList.length; i++) {
                if (StringUtil.equals(deviceIdList[i],"#")) {
                    deviceIdList[i] = deviceIdList[i - 1];
                }
            }
        }
        if (authParameter != null) {
            authParameterList = authParameter.split(";");
        }
        if (phoneModel != null) {
            phoneModelList = phoneModel.split(";");
        }
        if (isAiFound && !isBiFound) {
            String[] authInfoList = authInfo.split(";");
            for (int i = 0; i < authInfoList.length; i++) {
                BICDataModel model = new BICDataModel(authInfoList[i],
                        deviceIdList[i > deviceIdList.length - 1 ? 0 : i],
                        authParameterList[i > authParameterList.length - 1 ? 0 : i],
                        phoneModelList[i > phoneModelList.length - 1 ? 0 : i]);
                model.setCpModel(cpModel);
                model.setRootStatus(0);
                model.setAccessPermission(1);
                model.setAppPackage(appPackage);
                model.setBioInput(1);
                models.add(model);
            }
        } else {
            String[] bioInfoList = bioInfo.split(";");
            for (int i = 0; i < bioInfoList.length; i++) {
                BICDataModel model = new BICDataModel(bioInfoList[i],
                        deviceIdList[i > deviceIdList.length - 1 ? 0 : i],
                        authParameterList[i > authParameterList.length - 1 ? 0 : i],
                        phoneModelList[i > phoneModelList.length - 1 ? 0 : i]);
                model.setCpModel(cpModel);
                model.setAppPackage(appPackage);
                model.setServiceVersion(StringUtil.isBlank(serviceVersion) ? 15 : Integer.parseInt(serviceVersion));
                model.setSecDataVersion(StringUtil.isBlank(secDataVersion) ? 15 : Integer.parseInt(secDataVersion));
                model.setRootStatus(StringUtil.isBlank(root) ? 0 : Integer.parseInt(root));
                models.add(model);
            }
        }

        return models;
    }
}

class BICDataModel {

    /**
     * 业务类型:指纹支付
     */
    public final static int AUTHTYPE_FINGERPRINT      = 1;
    /**
     * 业务类型:可穿戴设备免密支付
     */
    public final static int AUTHTYPE_PASSWORDLESS     = 2;
    /**
     * 业务类型:付款码支付
     */
    public final static int AUTHTYPE_BARCODE          = 3;

    /**
     * 业务类型:3d人脸支付
     */
    public final static int AUTHTYPE_FACEID          = 4;

    /**
     * 可穿戴设备类型:手环
     */
    public final static int WEARABLETYPE_BARCELET     = 1;
    /**
     * 可穿戴设备类型:手表
     */
    public final static int WEARABLETYPE_WATCH        = 2;

    /**
     * 协议类型:指纹三星NNL方案
     */
    public final static int PROTOCOL_TYPE_NNL_FIDO    = 1;
    /**
     * 协议类型:Alipay通用方案
     */
    public final static int PROTOCOL_TYPE_ALIPAY      = 2;
    /**
     * 协议类型:FIDO指纹Alipay方案
     */
    public final static int PROTOCOL_TYPE_FIDO_ALIPAY = 3;
    /**
     * 协议类型:FIDO标准方案
     */
    public final static int PROTOCOL_TYPE_FIDO        = 4;

    /**
     * 客户端开通状态, 未知
     */
    public final static int CLIENT_STATUS_UNKNOWN     = 3;
    /**
     * 客户端开通状态, 开通
     */
    public final static int CLIENT_STATUS_OPEN        = 2;
    /**
     * 客户端开通状态, 删除
     */
    public final static int CLIENT_STATUS_DELETED     = 1;
    /**
     * 客户端开通状态, 关闭
     */
    public final static int CLIENT_STATUS_CLOSED      = 0;

    /**
     * 客户端的开通状态, 0为未开通, 2为开通, 1为异常
     */
    private int             clientStatus;

    /**
     * 业务类型:<br>1、指纹支付<br>2、可穿戴设备免密支付<br>3、付款码支付
     */
    private int             authType;

    /**
     * 可穿戴设备类型:<br>1、手环<br>2、手表
     */
    private int             wearableType;

    /**
     * 协议类型:<br>1、指纹三星NNL方案<br>2、Alipay通用方案<br>3、FIDO指纹Alipay方案<br>4、FIDO标准方案
     */
    private int             protocalType;

    /**
     * 协议的版本,目前为1
     */
    private int             protocalVersion;

    /**
     * 设备的制造商类型
     */
    private int             vendor;

    /**
     * 客户端Service版本,替换为移动收银台版本
     */
    private int             serviceVersion;

    /**
     * 设备ID
     */
    private String          deviceId;

    /**
     * 用户手机的型号
     */
    private String          phoneModel;

    /**
     * aaid
     */
    private String          cpModel;

    /**
     * 认证参数
     */
    private String          authParameter;

    /**
     * 是否支持sensor
     * 1-支持,0-不支持
     */
    private int          sensorSupport;

    /**
     * 是否录入
     * 1-设备已经录入,0-设备没有录入
     */

    private int         bioInput;

    /**
     * 是否有访问权限
     * 1-有访问权限,0-无访问权限
     */
    private int         accessPermission = 1;

    /**
     * 设备信息
     */
    private int        hardwareInfo;

    /**
     *secdata version
     */
    private int        secDataVersion;

    /**
     *Root状态
     *1-设备已Root, 0-非Root
     */
    private int        rootStatus;

    /***
     * 包名
     */
    private String     appPackage;

    /**
     * 格式定义<pre>
     *      ai:clientStatus#authType#wearableType#protocalType#protocalVersion#vender#serviceVersion</pre>
     *     bi:authType#sensorSupport#clientStatus#wearableType#protocalType#protocalVersion#vendor#serviceVersion#bioInput#accessPermission#hardwareInfo
     */
    public BICDataModel(String dataInfo, String deviceId, String authParameter, String phoneModel) {
        String[] dataInfoList = dataInfo.split("#");
        int dataLen = dataInfoList.length;
        if (dataLen < 6){ return;}
        if (dataLen >= 11) {//bi
            this.authType = Integer.parseInt(dataInfoList[0]);
            this.sensorSupport = Integer.parseInt(dataInfoList[1]);
            this.clientStatus = Integer.parseInt(dataInfoList[2]);
            this.wearableType = Integer.parseInt(dataInfoList[3]);
            this.protocalType = Integer.parseInt(dataInfoList[4]);
            this.protocalVersion = Integer.parseInt(dataInfoList[5]);
            this.vendor = Integer.parseInt(dataInfoList[6]);
            this.serviceVersion = Integer.parseInt(dataInfoList[7]);
            this.bioInput = Integer.parseInt(dataInfoList[8]);
            this.accessPermission = Integer.parseInt(dataInfoList[9]);
            this.hardwareInfo = Integer.parseInt(dataInfoList[10]);
        } else {//ai
            this.clientStatus = Integer.parseInt(dataInfoList[0]);
            this.authType = Integer.parseInt(dataInfoList[1]);
            this.wearableType = Integer.parseInt(dataInfoList[2]);
            this.protocalType = Integer.parseInt(dataInfoList[3]);
            this.protocalVersion = Integer.parseInt(dataInfoList[4]);
            this.vendor = Integer.parseInt(dataInfoList[5]);

            if (dataLen >= 7) {
                this.serviceVersion = Integer.parseInt(dataInfoList[6]);
            } else {
                this.serviceVersion = 100;
            }
        }


        this.deviceId = deviceId;
        this.phoneModel = phoneModel;
        this.authParameter = authParameter;
    }


    public int getClientStatus() {
        return clientStatus;
    }

    public int getAuthType() {
        return authType;
    }

    public int getWearableType() {
        return wearableType;
    }

    public int getProtocalType() {
        return protocalType;
    }

    public int getProtocalVersion() {
        return protocalVersion;
    }

    public int getVendor() {
        return vendor;
    }

    public int getServiceVersion() {
        return serviceVersion;
    }

    public int setServiceVersion(int serviceVersion) {
        return this.serviceVersion = serviceVersion;
    }

    public String getDeviceId() {
        return deviceId;
    }

    public String getPhoneModel() {
        return phoneModel;
    }

    public String getCpModel() {
        return cpModel;
    }

    public String setCpModel(String cpModel) {
        return this.cpModel = cpModel;
    }

    public String getAuthParameter() {
        return authParameter;
    }

    public int getSensorSupport() {
        return sensorSupport;
    }

    public int getBioInput() {
        return bioInput;
    }

    public int getAccessPermission() {
        return accessPermission;
    }

    public int getHardwareInfo() {
        return hardwareInfo;
    }

    public int getSecDataVersion() {
        return secDataVersion;
    }

    public int getRootStatus() {
        return rootStatus;
    }

    public int setSecDataVersion(int version) {
        return this.secDataVersion = version;
    }

    public int setRootStatus(int rootStatus) {
        return this.rootStatus = rootStatus;
    }

    public int setSensorSupport(int sensorSupport) {
        return this.sensorSupport = sensorSupport;
    }

    public int setBioInput(int bioInput) {
        return this.bioInput = bioInput;
    }

    public int setAccessPermission(int accessPermission) {
        return this.accessPermission = accessPermission;
    }

    public String getAppPackage() {
        return appPackage;
    }

    public void setAppPackage(String appPackage) {
        this.appPackage = appPackage;
    }

    public String getFpServiceVersion() {
        return String.valueOf(serviceVersion);
    }

    public int setHardwareInfo(int hardwareInfo) {
        return this.hardwareInfo = hardwareInfo;
    }

    /**
     * 获取封装的AuthInfo
     * clientStatus#authType#wearableType#protocalType#protocalVersion#vender#serviceVersion
     */
    final String getAuthInfo() {
        return clientStatus + "#" + authType + "#" + wearableType + "#" + protocalType + "#"
        + protocalVersion + "#" + vendor + "#" + serviceVersion;
    }

    /**
     * 获取封装的BioInfo
     * authType#sensorSupport#clientStatus#wearableType#protocalType#protocalVersion#vendor#serviceVersion#bioInput#accessPermission#hardwareInfo
     */
    final String getBioInfo() {
        return authType + "#" + sensorSupport + "#" + clientStatus + "#" + wearableType + "#" + protocalType + "#"
        + protocalVersion + "#" + vendor + "#" + serviceVersion + "#" +  bioInput + "#" + accessPermission + "#" + hardwareInfo;
    }


    @Override
    public String toString() {
        return "BICDataModel{" +
                "clientStatus=" + clientStatus +
                ", authType=" + authType +
                ", wearableType=" + wearableType +
                ", protocalType=" + protocalType +
                ", protocalVersion=" + protocalVersion +
                ", vendor=" + vendor +
                ", serviceVersion=" + serviceVersion +
                ", deviceId='" + deviceId + '\'' +
                ", phoneModel='" + phoneModel + '\'' +
                ", cpModel='" + cpModel + '\'' +
                ", authParameter='" + authParameter + '\'' +
                ", sensorSupport=" + sensorSupport +
                ", bioInput=" + bioInput +
                ", accessPermission=" + accessPermission +
                ", hardwareInfo=" + hardwareInfo +
                ", secDataVersion=" + secDataVersion +
                ", rootStatus=" + rootStatus +
                ", appPackage='" + appPackage + '\'' +
                '}';
    }
}
thedream(前端大神) - 2019-01-20 0 人
测试代码保存
没有了
1/3 下一页