在调接口时,会将请求体进行加密,代码如下:

public class DataEncrypt2Test {
    public static void main(String[] args) throws Exception {
        String pubKey = "省略不写";// 生产批次
        StringBuilder sb = new StringBuilder();
        sb.append("很长字符串1,省略不写,下同");
        sb.append("很长字符穿2");
        sb.append("很长字符串3");
        sb.append("很长字符串4");
        sb.append("很长字符串5");
        sb.append("很长字符串6");
        sb.append("很长字符串7" );
        sb.append("很长字符串8");
        sb.append("很长字符串9");
        sb.append("很长字符串10");
        sb.append("很长字符串11");
        String str = sb.toString();
        
        JSONObject json = new JSONObject();
        json.put("ycocode","09876543211234567890");
        json.put("yconame","华润制药");
        json.put("medicode","B1243253");
        json.put("mediname","当归");
        json.put("allowname","张山");
        json.put("locality","深圳");
        json.put("batchno","B345353");
        json.put("batchciid","3452352");
        json.put("prodate","2021-10-10");
        json.put("checkdate","2021-11-11");
        json.put("packgg","10/箱");
        json.put("checkname","王五");
        json.put("norm","国标");
        json.put("arts","工艺01");
        json.put("yreport",str);
        json.put("creport",str);
        json.put("updatetime","2021-12-12");
        json.put("ybatchid","1232141");
        json.put("unit","kg");
        json.put("quantity","100");
        json.put("billtype","销售出库");
        
        String encrypt = RSAUtils.encryptByPublicKey(json.toString(), pubKey);
        System.out.println("requestData===> ");
        System.out.println(encrypt);
  }
}

通过postman发起请求,报错:unclosed string

原因分析:由于请求体中有两张图片,加密后字符串的长度为:1053356,由于idea控制台打印日志有限制,导致加密后在控制台打印出来的密文不完整,当去请求后台时,就会报错unclosed string.

修改如下:

 

posted on 2021-12-18 14:36  周文豪  阅读(6670)  评论(0编辑  收藏  举报