调用报错{"code":10003,"message":"PermissionDenied","hint":"invalid Authorization","extra":""}

阅读次数 78

OkHttpClient client = new OkHttpClient(); String mediaTypeStr ="application/json" ;

    SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
    sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
    String currentDare = sdf.format(new Date());
    String content ="{\"url\":\"\",\"filename\":\"\"}";

    MediaType mediaType = MediaType.parse(mediaTypeStr);
    RequestBody body = RequestBody.create(mediaType, content);
    String contentMd5Str = SecureUtil.md5(content);
    String seed = accessKey+contentMd5Str+mediaType.toString()+currentDare;
    String sha1Str = SecureUtil.sha1(seed);

    System.out.println("Date:"+currentDare);
    System.out.println("Content-Md5:"+contentMd5Str);
    System.out.println("seed:"+seed);
    System.out.println("sha1Str:"+sha1Str);

    Request request = new Request.Builder()
            .url("https://solution.wps.cn/api/developer/v1/office/convert/to/pdf")
            .post(body)
            .addHeader("Date", currentDare)
            .addHeader("Content-Md5", contentMd5Str)
            .addHeader("Content-Type", mediaTypeStr)
            .addHeader("Authorization", "WPS-2"+appid+":"+sha1Str)
            .build();
    System.out.println("Authorization:"+"WPS_2"+appid+":"+sha1Str);
    Response response = client.newCall(request).execute();
    System.out.println(response.body().string());
1 Answers