12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package com.iamberry.rst.utils;
- import com.alibaba.dubbo.common.json.JSON;
- import com.auth0.jwt.internal.org.apache.commons.codec.binary.Base64;
- import com.auth0.jwt.internal.org.apache.commons.codec.binary.StringUtils;
- import net.sf.json.JSONArray;
- import net.sf.json.JSONObject;
- //import org.apache.kafka.clients.consumer.ConsumerRecord;
- import java.io.File;
- import java.io.FileInputStream;
- import java.security.Key;
- import java.util.Map;
- import javax.crypto.Cipher;
- import javax.crypto.spec.SecretKeySpec;
- import java.security.Key;
- public class test {
- private static final String AES = "AES";
- public static String decrypt(String encryptedData, String secretKey) throws Exception {
- Key key = new SecretKeySpec(secretKey.getBytes(), AES);
- Cipher c = Cipher.getInstance(AES);
- c.init(2, key);
- byte[] decodedValue = Base64.decodeBase64(encryptedData);
- byte[] decValue = c.doFinal(decodedValue);
- String decryptedValue = StringUtils.newStringUtf8(decValue);
- return decryptedValue;
- }
- /* public static void main(String[] args) throws Exception {
- ConsumerRecord<String, String> record = new ConsumerRecord<String, String>("4", 1, 1, "data", "{\"data\":\"7uiBfrOFcdy/EDWxcT6SlSH10bmyKW4BoILZ7f4LQygzN9scB2To4W3gRf0nzI+kHOKWzrv5DHEfJNt9/QrlfTk6VcHGwiPGycwiPvDkoTe4eJOW8Qqwm/1H4nNX+1Ed/CTueaJe3E/BNsFxe7rF+qYIHqZnL4b2n9Padc5ySenpG7G0a5xepWP0KZYDN4KeCTCNBf4XIxuHSB/BGVZpATEykU1vILnX89GzoJlV+10=\"}");
- String appKey = "5kkyurvvtt58bbuxueee";//填APP KEY
- String secretKey = "rhj6na6u3y6uhy6qrbb3944mg5uqqpbb";//APP SECRET
- String data = decrypt(JSONObject.fromObject(record.value()).getString("data"),
- secretKey.substring(8, 24));//解析后的真正数据
- JSONObject jasonObject = JSONObject.fromObject(data);
- System.out.println(jasonObject);
- if(jasonObject.has("dps")){
- JSONArray dps = jasonObject.getJSONArray("dps");
- boolean flog = false;
- for(int i = 0; i < dps.size(); i++){
- Map maps = (Map) JSON.parse(dps.getString(i));
- for (Object obj : maps.keySet()){
- if(obj.equals("DEVECE_CONTROL_MILK")){
- String milkPowder = maps.get(obj).toString();
- flog = true;//如果数据中包含当前字段,表示当前推送的数据为奶粉记录
- }
- if(obj.equals("t")){
- Long milkTime = (Long)maps.get((obj));
- }
- }
- }
- if(flog){
- // 根据机器ID 获取对应的用户id
- String devId = jasonObject.getString("devId");
- flog = false;
- }
- }
- }*/
- }
|