在调用文档转换成 pdf功能时response返回403并且postman中提示
{
"successful": false,
"redirect": false
}
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
// 从 fileNameMap 中获取 fileid 对应的文档 URL
String fileUrl = fileNameMap.get(fileid);
// 提取文档 URL 中的文件名
String fileName = fileUrl.substring(fileUrl.lastIndexOf("/") + 1);
// 创建请求体 JSON
String jsonBody = "{\"url\":\"" + fileUrl + "\",\"filename\":\"" + fileName + "\"}";
RequestBody body = RequestBody.create(mediaType, jsonBody);
Map paramMap = new HashMap();
paramMap.put("_w_appid", ApplicationProperties.appid);
paramMap.put("_w_fileid", fileid);
// 获取当前时间
LocalDateTime now = LocalDateTime.now();
// 设置时间格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss z", Locale.ENGLISH);
// 将当前时间转换为指定时区的格式化字符串
String formattedTime = now.atZone(ZoneId.of("GMT")).format(formatter);
String contentMd5 = Objects.requireNonNull(Signature.calculateContentMd5(jsonBody)).toLowerCase();
// formattedTime = "Wed, 23 Jan 2013 06:43:08 GMT";
// 构建请求对象
Request request = new Request.Builder()
.url("https://solution.wps.cn/api/developer/v1/office/convert/to/pdf")
.post(body)
.addHeader("Date", formattedTime)
.addHeader("Content-Md5", contentMd5)
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "WPS-2:" + ApplicationProperties.appid + ":" + Signature.calculateSignature(ApplicationProperties.appSecret, contentMd5, "application/json", formattedTime));