我想从docusign下载签名的文档。为此我创建了一个新的信封ID。这是下载文档的正确方法吗?我还尝试了用于文档签名的现有信封ID。信封ID,表示收到身份验证异常。
*JSONObject json=null;
String accessToken = null;
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
List<NameValuePair> form = new ArrayList<>();
form.add(new BasicNameValuePair("scope", "api"));
form.add(new BasicNameValuePair("username", docUsername));
form.add(new BasicNameValuePair("password", docPassword));
form.add(new BasicNameValuePair("grant_type", docGranttype));
form.add(new BasicNameValuePair("client_id", docClientId));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(form, Consts.UTF_8);
HttpPost httpPost = new HttpPost(docTokenurl);
httpPost.setEntity(entity);
System.out.println("Executing request " + httpPost.getRequestLine());
// Create a custom response handler
ResponseHandler<String> responseHandler = response -> {
int status = response.getStatusLine().getStatusCode();
if (status >= 200 && status < 300) {
HttpEntity responseEntity = response.getEntity();
return responseEntity != null ? EntityUtils.toString(responseEntity) : null;
} else {
throw new ClientProtocolException("Unexpected response status: " + status);
}
};
String responseBody = httpclient.execute(httpPost, responseHandler);
System.out.println("----------------------------------------");
System.out.println(responseBody);
json = new JSONObject(responseBody);
accessToken = json.getString("access_token");
String accountId = docAccountId;
EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition();
ApiClient apiClient = new ApiClient(docBasePath);
apiClient.addDefaultHeader("Authorization", "Bearer " + accessToken);
EnvelopesApi envelopesApi = new EnvelopesApi(apiClient);
EnvelopeSummary results = envelopesApi.createEnvelope(accountId, envelopeDefinition);
String envelopeId = results.getEnvelopeId();
EnvelopeDocumentsResult docsList = envelopesApi.listDocuments(docAccountId, envelopeId);
for( EnvelopeDocument doc: docsList.getEnvelopeDocuments() ) {
Files.write(
new File(doc.getName()).toPath(),envelopesApi.getDocument(docAccountId, envelopeId, doc.getDocumentId())
);
}*
答案 0 :(得分:0)
如果要从现有信封下载签名的文档,请使用现有信封的ID。请参阅EnvelopeDocuments::get
的文档请参阅github.com/docusign
中以eg-03开头的代码示例。请参见工作流程示例6和7。