package com.iformall.utils.car;

import com.alibaba.fastjson.JSONObject;
import com.iformall.utils.AesUtils;
import com.iformall.utils.HttpUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * 大华 停车管理
 */
public class DaHuaUtil {

    public static final String KEY = "8G5M4Ff9hel6fUA7";

    public static final String IV = "g8v90drvOmIx1PuR";

    public static final String URL = "http://47.106.104.196:8025/external/common";

    public static final String SUCCESS_CODE = "0000";

    public static String parkInfo(String appId) {
        Map<String, Object> requestParams = new HashMap<>();
        requestParams.put("method", "parkInfo");
        return request(requestParams, appId);
    }

    public static String plateCharge(String carNum, String appId) {
        Map<String, Object> requestParams = new HashMap<>();
        Map<String, Object> data = new HashMap<>();
        data.put("carNum", carNum);
        requestParams.put("data", data);
        requestParams.put("method", "plateCharge");
        return request(requestParams, appId);
    }

    public static String request(Map<String, Object> requestParams, String appId) {
        String cipher = AesUtils.encryptCtrMode(JSONObject.toJSONString(requestParams), KEY, IV);
        Map<String, Object> params = new HashMap<>();
        params.put("appId", appId);
        params.put("cipher", cipher);
        params.put("timestamp", System.currentTimeMillis());
        try {
            return HttpUtil.doPost(URL, JSONObject.toJSONString(params));
        } catch (Exception e) {
            return null;
        }
    }


}

