import java.util.Base64; import javax.crypto.Cipher; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.DESKeySpec; import javax.crypto.spec.IvParameterSpec; import sun.misc.BASE64Decoder; String key ="你自己的desKEY";//引用key String body=prev.getResponseDataAsString(); import org.json.JSONObject; //导入 import org.json.*; prev.setDataEncoding("utf-8"); // 加密方法 public String DecryptAsDoNet(String message) { try { byte[] encrypted1 = new BASE64Decoder().decodeBuffer(message); Base64.Encoder encoder = Base64.getEncoder(); Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding"); DESKeySpec desKeySpec = new DESKeySpec(key.getBytes("UTF-8")); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); SecretKey secretKey = keyFactory.generateSecret(desKeySpec); IvParameterSpec iv = new IvParameterSpec(key.getBytes("UTF-8")); cipher.init(Cipher.DECRYPT_MODE, secretKey, iv); byte[] encryptbyte = cipher.doFinal(encrypted1); String str =new String(encryptbyte,"utf-8"); return str; } catch (Throwable e) { e.printStackTrace(); return ""; } } // 解密 String decrypt = DecryptAsDoNet(body); vars.put("DESSign",decrypt); JSONObject resbonseJson = new JSONObject(decrypt); //解析json String code = resbonseJson.get("code").toString(); String Token = resbonseJson.get("data").get("accessToken").toString(); log.info("请求登录返回报文"+decrypt); vars.put("DESSign",decrypt); vars.put("rescode",code); log.info("登录接口响应code"+code); vars.put("Token",Token); log.info("登录token:" + Token)