package com.mints.goodmoney.manager;


import android.content.Context;
import android.text.TextUtils;

import com.ishumei.smantifraud.SmAntiFraud;
import com.mints.goodmoney.MintsApplication;

/**
 * 描述：数美反欺诈
 * 作者：孟崔广
 * 时间：2020/10/10 10:44
 */
public class ShumeiManager {

    /**
     * 组织标识，邮件中organization项。
     */
    public static final String ORGANIZATION = "46Y91K7dU5utpc48P6JQ";
    /**
     * 应用标识，登录数美后台应用管理查看。
     */
    public static final String APP_ID = "mints_goodmoney";
    /**
     * 加密 KEY。
     */
    public static final String PUBLIC_KEY = "MIIDLzCCAhegAwIBAgIBMDANBgkqhkiG9w0BAQUFADAyMQswCQYDVQQGEwJDTjELMAkGA1UECwwCU00xFjAUBgNVBAMMDWUuaXNodW1laS5jb20wHhcNMjAwMTA2MDk1ODM4WhcNNDAwMTAxMDk1ODM5WjAyMQswCQYDVQQGEwJDTjELMAkGA1UECwwCU00xFjAUBgNVBAMMDWUuaXNodW1laS5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCAbaB3PszWA4FAqVfzZWsPchWK3rZPzb0XMb1O/7U5LkL25eY337rKY2UFz2NG2Lrimn3mnXZyFCFI3azSeR7Qh4IXJWlVMIQYQH49bKFPKMlJcdLB/J7xEDbvmAo3o7YEv4Z+VEplaH/QAtPjexLbfKP9VxLFtHDpqImxUprHat9OdmSzjaYZ7uB4aylGcBuDIRmqWri4t3r1li+EvHwx2OsyTXW12f9PwfuucWqTZ6ndxJ9xkUMKfFYmUhnuzudKzaly6C/14CZpc0GmS6QmXuy6uXxnjkmi1RUXX4q94BMfq/EyAp7OzEGh4D5kBljGYeadYoOKFSYkDvy/8qjbAgMBAAGjUDBOMB0GA1UdDgQWBBQEvkAQhyEi8TBS2TpBN0wbDTfVsTAfBgNVHSMEGDAWgBQEvkAQhyEi8TBS2TpBN0wbDTfVsTAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4IBAQBovJ9Eu3hpfBCkpuTsY8GZ5URKwbYTL8bRNa6SFDoRxsCr7f22YZxJ8/nRrRR+QT3dW7zmJyWyzjwlovRWrVPL/uNGdAx72X+0dE65n86CHdXxJgHlEyRej77p7xmTRsncxqUAnKi5w8O/jKJRhgMbHyo+xzA4OW0tk78sKxlEJut18BbCCmPxocQBSHlyeA8Yp+knakHWlbGp9MCuuj53djvi7Tb4b7brGGepJiJUxEbVNTJM4PSdJno9obXohOKEU3yCLTDebR1jWgp7VOTGl1bi4gyBBNGUCJ1H0xh8z2MMa+FqLqMB/wce+sRWiRYLRqw/VUI4q4JwuWrrWYdL";
    /**
     * 加密 KEY，邮件中 Android ainfo key 项。
     */
    public static final String AINFO_KEY = "tbAlHLEBfOeCTrYtRYwmtEDCFLskFXQoLZSfBSPXymdSldhFwASaQJRMNHuPnTVV";

    private static ShumeiManager _inst;
    private Context context;

    public static ShumeiManager getInstance() {
        if (_inst != null) {
            return _inst;
        } else {
            _inst = new ShumeiManager();
            return _inst;
        }
    }

    private ShumeiManager() {
        init();
    }

    private void init() {
        context = MintsApplication.getContext();
    }

    /**
     * 初始化数美SDK
     */
    public void initShumei() {
        try {
            //1.通用配置项
            SmAntiFraud.SmOption option = new SmAntiFraud.SmOption();
            option.setOrganization(ORGANIZATION); //必填，组织标识，邮件中organization项
            option.setAppId(APP_ID); //必填，应用标识，登录数美后台应用管理查看
            option.setPublicKey(PUBLIC_KEY); //必填，加密 KEY，邮件中 android_public_key 附件内容
            option.setAinfoKey(AINFO_KEY); //必填，加密 KEY，邮件中 Android ainfo key 项
            //2.连接海外机房特殊配置项，仅供设备数据上报海外机房客户使用
            // option.setArea(SmAntiFraud.AREA_XJP); //连接新加坡机房客户使用此选项
            // option.setArea(SmAntiFraud.AREA_FJNY); //连接美国机房客户使用此选项
            //3.SDK 初始化
            SmAntiFraud.create(context, option);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取数美id
     */
    public String getShumeiDeviceId() {
        String id = "";
        try {
            id = SmAntiFraud.getDeviceId();
        } catch (Exception e) {
            e.printStackTrace();
            id = "";
        }

        if (TextUtils.isEmpty(id)) {
            initShumei();
        }
        return id;
    }
}
