文件转换,提示签名问题。求助,wps-2的加密方式在哪里出现了错误

阅读次数 72

调用接口:https://solution.wps.cn/api/developer/v1/office/convert/to/png 接口调用后提示错误内容: {"code":30003,"message":"InvalidSignature","hint":"signature not match. expect: ba92703be9e26cc95a0da44068f43fdfe723a0b4, actual: 57848d780dbbba707fc1edaae18ae1c9130e9ecb","extra":""}

sh1加密前字段(已经脱敏):wpxxxxxxxxxxxxxxxx82d7154a0945bd9ee8755d668b57afc2application/jsonWed, 27 Sep 2023 08:03:41 GMT

md5数据的加密原始数据(已经脱敏):{"url":"http://xxxxx/file/admin/uploadDir/2023-09-26/xxxx.ppt","filename":"xxxx.ppt"}

Md5计算算法:

  public static String getMd5(String value) throws NoSuchAlgorithmException {

        System.out.println(value);
        MessageDigest md = MessageDigest.getInstance("MD5");

        // 计算消息的摘要
        byte[] digest = md.digest(value.getBytes());

        // 将摘要转换为十六进制字符串
        String hexString = bytesToHex(digest);

        System.out.println(hexString);

        return hexString;
    }

    public static String bytesToHex(byte[] bytes) {
        StringBuilder hexString = new StringBuilder();
        for (byte b : bytes) {
            String hex = Integer.toHexString(0xff & b);
            if (hex.length() == 1) {
                hexString.append('0');
            }
            hexString.append(hex);
        }
        return hexString.toString();
    }

求助,具体哪个步骤配置错误,才造成加密数据不一致?

1 Answers

问题解决了, 官方文档中文件转换的Header参数写的不对。

image.png

Content-Type的值 不是固定为:application/json 而是 application/json; charset=utf-8

官方文档中,服务端回调中写的才是更准确的:https://solution.wps.cn/docs/callback/summary.html#%E5%9B%9E%E8%B0%83%E8%AF%B7%E6%B1%82%E7%AD%BE%E5%90%8D image.png