我在postman中测试可以通过 但是代码中就报错 {"code":30003,"message":"InvalidSignature","hint":"signature not match. expect: 75b134a375868398335721531fd2f8a3afc8acaf, actual: d39317d513fc31a273220c3fdf51f864931436fe","extra":""}
,看了下postman中的body参数md5加密后与后台加密后数据不一样,请问怎么回事
Map param = new LinkedHashMap<>();
param.put("url", "http://www.xxxxx.com/userfiles/xxxxx/test11.docx");
param.put("filename", "test11.docx");
String content = JSON.toJSONString(param);
String contentMd5 = Common.getMd52(content);
okhttp3.MediaType mediaType=okhttp3.MediaType.parse(mediaTypeStr);
RequestBody body = RequestBody.create(mediaType,content);
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("https://solution.wps.cn/api/developer/v1/office/save/as/docx")
.post(body)
.addHeader("Date", headerDate)
.addHeader("Content-Md5", contentMd5)
.addHeader("Content-Type", mediaTypeStr)
.addHeader("Authorization", "WPS-2:"+convertAppid+":"+seed) //
.build();
public static String getMd52(String value) {
String hexString ="";
System.out.println(value);
MessageDigest md;
try {
md = MessageDigest.getInstance("MD5");
// 计算消息的摘要
byte[] digest = md.digest(value.getBytes());
// 将摘要转换为十六进制字符串
hexString = bytesToHex(digest);
System.out.println(hexString);
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
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();
}