签名和demo说明

data加密说明:使用AES-256-ECB进行加密,key由领新提供,加密字符串为(merchantid可不参与签名)json序列化字符串:

{"action":"enter","park_name":"xx停车场","park_number":"6F4AEC14D34E46C6A1EC2832CBF47BA0","gate_name":"22","gate_number":"gdfgdfgdf","status":"0","time":"2022-01-01 22:22:22","license_plate":"Z3333"}

php demo:
function sign($data,$key){
return bin2hex(openssl_encrypt(json_encode($data),'AES-256-ECB',$key,OPENSSL_RAW_DATA,''));
}

$post_data = array(
'action'=>'enter',
'park_name'=>'友联一村停车场',//停车场名称
'park_number'=>'xxx',//停车场编号
'gate_name'=>'22',//闸门名称
'gate_number'=>'gdfgdfgdf',//闸门编号
'status'=>'0',//0进 1出
'time'=>'2022-01-01 22:22:22',//时间
'license_plate'=>'Z3333',//车牌号
);
$key = 'xxx';
$post['data'] = sign($post_data,$key);
$post['merchantid'] = 'xxx';

$url = 'https://api.icar.leadnew.com.cn/index/index';

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);

$response = curl_exec($curl);
curl_close($curl);

print_r($response);



java demo

public static void main(String[] args) throws Exception {
System.out.println(encrypt("{\"action\":\"select\",\"park_number\":\"C3370E89B3\",\"license_plate\":\"苏E79749\"}","XXXX"));

                //post 2个参数merchantid和data(略) }


public static String encrypt(String str,String key) throws Exception {
byte[] SECRET_KEY = key.getBytes();
        SecretKeySpec secretKeySpec = new SecretKeySpec(SECRET_KEY, "AES");
         Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
        cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
        byte[] bytes = cipher.doFinal(str.getBytes("UTF-8"));
        return encodeHexString(bytes);
    }

public static String encodeHexString(byte[] data) {
char[] hexArray = "0123456789abcdef".toCharArray();
char[] out = new char[data.length * 2];
for (int i = 0; i < data.length; i++) {
int v = data[i] & 0xFF;
out[i * 2] = hexArray[v >>> 4];
out[i * 2 + 1] = hexArray[v & 0x0F];
}
return new String(out);
}