格式转换结果查询 报错 急急急

阅读次数 2

格式转换结果查询 报错 :{"code":30003,"message":"InvalidSignature","hint":"md5 not match. expect: 5f65bdb77f6391ffa4b148e0a0b5ae41, actual: dde16167261eba697baa4c1cd3d84c03","extra":""} ;

以下是实现的代码 :

	    SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
	    sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
	    String date = sdf.format(new Date());
	    System.out.println("date========" + date);
	    
	    JSONObject bodyJSONObeject = new JSONObject();
	    bodyJSONObeject.put("url", "http://221.11.46.122:18000/cgplat/2025/07/16/output_20250716153852A110.docx");
	    bodyJSONObeject.put("filename", "output_20250716153852A110.docx");
	    String bodyStr = JSONObject.toJSONString(bodyJSONObeject);
	    System.out.println("bodyStr:" + bodyStr);
	    
	    String contentMd5 = SecureUtil.md5(task_id);
	    System.out.println("contentMd5========" + contentMd5);
	    String mediaTypeStr = "application/json;charset=utf-8";
	    MediaType mediaType = MediaType.parse(mediaTypeStr);
	    System.out.println("mediaType" + JSONObject.toJSONString(mediaType));
	    
	    String shi1Str = appSecret + contentMd5 + mediaTypeStr + date;
	    System.out.println("shi1Str======" + shi1Str);
	    String sha1Str = SecureUtil.sha1(shi1Str);
	    System.out.println("sha1========" + sha1Str);
	    String authorization = "WPS-2:" + appID + ":" + sha1Str;
	    System.out.println("authorization========" + authorization);
	    Request request = new Request.Builder()			                      .url("https://solution.wps.cn/api/developer/v1/tasks/"+ URLEncoder.encode(task_id, StandardCharsets.UTF_8))
			                     
			                      .addHeader("Date", date)
			                      .addHeader("Content-Md5", contentMd5)
			                      .addHeader("Content-Type", mediaTypeStr)
			                      .addHeader("Authorization", authorization)
			                      .get()
			                      .build();
	    OkHttpClient client = new OkHttpClient();
	    Response response = null;
	    response = client.newCall(request).execute();
	    System.out.println(response.body().string());
	    System.out.println("返回数据:" + JSONObject.toJSONString(response));
0 Answers