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) {
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;
public final static int AUTHTYPE_FACEID = 4;
public final static int WEARABLETYPE_BARCELET = 1;
public final static int WEARABLETYPE_WATCH = 2;
public final static int PROTOCOL_TYPE_NNL_FIDO = 1;
public final static int PROTOCOL_TYPE_ALIPAY = 2;
public final static int PROTOCOL_TYPE_FIDO_ALIPAY = 3;
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;
private int clientStatus;
private int authType;
private int wearableType;
private int protocalType;
private int protocalVersion;
private int vendor;
private int serviceVersion;
private String deviceId;
private String phoneModel;
private String cpModel;
private String authParameter;
private int sensorSupport;
private int bioInput;
private int accessPermission = 1;
private int hardwareInfo;
private int secDataVersion;
private int rootStatus;
private String appPackage;
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) {
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 {
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;
}
final String getAuthInfo() {
return clientStatus + "#" + authType + "#" + wearableType + "#" + protocalType + "#"
+ protocalVersion + "#" + vendor + "#" + serviceVersion;
}
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 + '\'' +
'}';
}
}