京东到家.apk(点击下载) / RequestVerityProtocol.java


package com.jdjr.risk.identity.face.protocol;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import com.jdcn.biz.client.BankCardConstants;
import com.jdjr.risk.identity.face.TrackerConstantsImpl;
import com.jdjr.risk.identity.face.bean.IdentityResultIn;
import com.jdjr.risk.identity.face.bean.IdentityResultOut;
import com.jdjr.risk.identity.face.bean.IdentitySdkParams;
import com.jdjr.risk.identity.face.bean.IdentityVerifyReqParams;
import com.jdjr.risk.identity.face.bean.IntentMemoryData;
import com.jdjr.risk.identity.face.constants.VerifyFaceContants;
import com.jdjr.risk.identity.face.utils.BiometricTokenGetUtil;
import com.jdjr.risk.identity.face.utils.FsBase64;
import com.jdjr.risk.identity.face.utils.FsMD5Utils;
import com.jdjr.risk.jdcn.common.network.FsHttpManager;
import com.jdjr.risk.jdcn.common.utils.FsGsonUtil;
import com.jdjr.risk.jdcn.common.utils.JDCNLogUtils;
import com.jdjr.risk.jdcn.common.utils.PhoneInfoUtil;
import com.jdjr.risk.jdcn.security.FsSecurityChannelUtils;
import java.io.IOException;
import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONObject;

public class RequestVerityProtocol {
    public static Bundle requestIdentityVerity(Context context, IdentitySdkParams identitySdkParams) {
        IdentityResultOut identityResultOut;
        byte[] decodeDataFromServer;
        String postJsonString2;
        Bundle bundle = new Bundle();
        IdentityVerifyReqParams identityVerifyReqParams = new IdentityVerifyReqParams();
        identityVerifyReqParams.setAppName(identitySdkParams.getAppName());
        identityVerifyReqParams.setBusinessId(identitySdkParams.getBusinessId());
        identityVerifyReqParams.setAppAuthorityKey(identitySdkParams.getAppAuthorityKey());
        identityVerifyReqParams.setToken(identitySdkParams.getVerifyToken());
        identityVerifyReqParams.setSessionId(identitySdkParams.getSessionId());
        String buildBiometricToken = BiometricTokenGetUtil.buildBiometricToken(context, identitySdkParams.getBusinessId(), identitySdkParams.getUserId());
        if (TextUtils.isEmpty(buildBiometricToken)) {
            buildBiometricToken = "BiometricManagerError";
        }
        identityVerifyReqParams.setSdkToken(buildBiometricToken);
        identityVerifyReqParams.setFaceSDK("face_sdk");
        identityVerifyReqParams.setFaceSDKVersion("3.1.3");
        ArrayList arrayList = new ArrayList();
        if (IntentMemoryData.faceCheckListBytes == null && IntentMemoryData.faceCheckListBytes.size() == 0) {
            return bundle;
        }
        if (IntentMemoryData.faceCheckListBytes != null && IntentMemoryData.faceCheckListBytes.size() > 0) {
            arrayList.add("SFF#" + FsMD5Utils.md5_32bit(FsBase64.encodeBytes(IntentMemoryData.faceCheckListBytes.get(0))) + ":jdin:1.0:" + FsBase64.encodeBytes(IntentMemoryData.faceCheckListBytes.get(0)));
        }
        if (IntentMemoryData.faceCheckListBytes != null && IntentMemoryData.faceCheckListBytes.size() > 1) {
            arrayList.add("AP#" + FsMD5Utils.md5_32bit(FsBase64.encodeBytes(IntentMemoryData.faceCheckListBytes.get(IntentMemoryData.faceCheckListBytes.size() - 1))) + ":jdin:1.0:" + FsBase64.encodeBytes(IntentMemoryData.faceCheckListBytes.get(IntentMemoryData.faceCheckListBytes.size() - 1)));
        }
        if (IntentMemoryData.resizeImg != null) {
            arrayList.add("RES#" + FsMD5Utils.md5_32bit(FsBase64.encodeBytes(IntentMemoryData.resizeImg)) + ":jdin:1.0:" + FsBase64.encodeBytes(IntentMemoryData.resizeImg));
            IntentMemoryData.resizeImg = null;
        }
        identityVerifyReqParams.setFaceData(arrayList);
        if (IntentMemoryData.faceExposureImgBytes != null) {
            String encodeBytes = FsBase64.encodeBytes(IntentMemoryData.faceExposureImgBytes);
            identityVerifyReqParams.setExposureImage("EXP#" + FsMD5Utils.md5_32bit(encodeBytes) + ":jdin:1.0:" + encodeBytes);
            IntentMemoryData.faceExposureImgBytes = null;
        }
        identityVerifyReqParams.getExtra().faceDetectSdkDowngraded = IntentMemoryData.faceDetectSdkDowngraded;
        identityVerifyReqParams.getExtra().nolight = identitySdkParams.isNolight();
        try {
            JSONObject jSONObject = new JSONObject(FsGsonUtil.gsonString(identityVerifyReqParams));
            if (IntentMemoryData.colorfulBytes != null && !IntentMemoryData.colorfulBytes.isEmpty() && IntentMemoryData.colorfulStrList != null && !IntentMemoryData.colorfulStrList.isEmpty()) {
                JSONArray jSONArray = new JSONArray();
                JSONArray jSONArray2 = new JSONArray();
                int size = IntentMemoryData.colorfulBytes.size();
                if (size == IntentMemoryData.colorfulStrList.size()) {
                    for (int i = 0; i < size; i++) {
                        jSONArray.put("DAZZLE#" + FsMD5Utils.md5_32bit(FsBase64.encodeBytes(IntentMemoryData.colorfulBytes.get(i))) + ":jdin:1.0:" + FsBase64.encodeBytes(IntentMemoryData.colorfulBytes.get(i)));
                        jSONArray2.put(IntentMemoryData.colorfulStrList.get(i));
                    }
                    jSONObject.put("dazzleImages", jSONArray);
                    jSONObject.put("dazzleColors", jSONArray2);
                }
            }
            jSONObject.put("verifyBusinessType", "SIMPLE_VERIFY");
            jSONObject.put("antiAttackPolicy4Biz", "SFF");
            String idCardToken = identitySdkParams.getIdCardToken();
            if (!TextUtils.isEmpty(idCardToken)) {
                jSONObject.put("idCardToken", idCardToken);
                JSONObject jSONObject2 = new JSONObject();
                jSONObject2.put("IDP", "SFF");
                jSONObject.put("verifyStrategy", jSONObject2);
            } else if (TextUtils.isEmpty(idCardToken)) {
                JSONObject jSONObject3 = new JSONObject();
                jSONObject3.put("MP", "SFF");
                jSONObject.put("verifyStrategy", jSONObject3);
            }
            jSONObject.put("channelFlag", "101");
            JSONObject json = PhoneInfoUtil.getPhoneInfo(context).toJson();
            if (json != null) {
                json.put("sdkName", TrackerConstantsImpl.logId);
                json.put("sdkVersion", "1.6.00");
                jSONObject.put("shieldInfo", json);
            }
            if (IntentMemoryData.securityCode != null && IntentMemoryData.securityCode.length > 0) {
                jSONObject.put("imageCRC", FsBase64.encodeBytes(IntentMemoryData.securityCode));
            }
            if (IntentMemoryData.faceExposureSecurityCode != null && IntentMemoryData.faceExposureSecurityCode.length > 0) {
                jSONObject.put("exposureImageCRC", FsBase64.encodeBytes(IntentMemoryData.faceExposureSecurityCode));
                IntentMemoryData.faceExposureSecurityCode = null;
            }
            byte[] encodeDataToServer = FsSecurityChannelUtils.encodeDataToServer(context.getApplicationContext(), jSONObject.toString());
            if (encodeDataToServer != null) {
                String str = VerifyFaceContants.LOG_TAG;
                JDCNLogUtils.d(str, "dataByte.length = " + encodeDataToServer.length);
                String str2 = new String(encodeDataToServer);
                JSONObject jSONObject4 = new JSONObject();
                jSONObject4.put(BankCardConstants.KEY_APP_AUTHORITY_KEY, identitySdkParams.getAppAuthorityKey());
                jSONObject4.put("appName", identitySdkParams.getAppName());
                jSONObject4.put(BankCardConstants.KEY_BUSINESS_ID, identitySdkParams.getBusinessId());
                jSONObject4.put("data", str2);
                try {
                    System.currentTimeMillis();
                    postJsonString2 = FsHttpManager.postJsonString2("https://identify.jd.com/f/securityAutoIdauth", jSONObject4.toString(), false, 20, 20, 10);
                    String str3 = VerifyFaceContants.LOG_TAG;
                    JDCNLogUtils.d(str3, "核验返回:" + postJsonString2);
                } catch (IOException e) {
                    JDCNLogUtils.e(VerifyFaceContants.LOG_TAG, "requestIdentityVerity", e);
                    bundle.putInt("err_code", 10003);
                    bundle.putString("err_msg", e.getMessage());
                }
                if (!(TextUtils.isEmpty(postJsonString2) || (identityResultOut = (IdentityResultOut) FsGsonUtil.gsonToBean(postJsonString2, IdentityResultOut.class)) == null || (decodeDataFromServer = FsSecurityChannelUtils.decodeDataFromServer(context.getApplicationContext(), identityResultOut.getData())) == null)) {
                    bundle.putSerializable("resultDecrypt", (IdentityResultIn) FsGsonUtil.gsonToBean(new String(decodeDataFromServer), IdentityResultIn.class));
                }
            }
        } catch (Exception e2) {
            JDCNLogUtils.e(VerifyFaceContants.LOG_TAG, "requestIdentityVerity", e2);
            bundle.putInt("err_code", 10002);
            bundle.putString("err_msg", e2.getMessage());
        }
        String str4 = VerifyFaceContants.LOG_TAG;
        JDCNLogUtils.d(str4, "网络上传完成 : " + System.currentTimeMillis());
        return bundle;
    }
}