本文介绍了Java和Docusign集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在docusign沙箱中创建了集成密钥和私钥/公钥。

I have created integrator key and private/public key in docusign sandbox.

当我尝试调用api时,这给了我错误。

When I am trying to call api,it is giving me error.

我的代码是这样的:

public class DocuSignExample1 {

    private static final String IntegratorKey = "10048d4c-0549-434e-b224-4805b36b69e1";
    private static final String UserId = "ef27e777-c6fc-4385-91ce-63dafab5385b";
    private static final String privateKeyFullPath = System.getProperty("user.dir") + "/src/test/keys/docusign_private_key2.txt";


    private static final String Recipient = "[email protected]";
    private static final String SignTest1File = "/src/test/docs/SignTest1.pdf";
    private static final String BaseUrl = "https://demo.docusign.net/restapi";
    public static void main(String[] args) {

        byte[] fileBytes = null;
        try {
            String currentDir = System.getProperty("user.dir");

            Path path = Paths.get(currentDir + SignTest1File);
            fileBytes = Files.readAllBytes(path);
        } catch (IOException ioExcp) {
            ioExcp.printStackTrace();
        }

        EnvelopeDefinition envDef = new EnvelopeDefinition();
        envDef.setEmailSubject("Please Sign My Sample Document");
        envDef.setEmailBlurb("Hello, Please Sign My Sample Document.");

        Document doc = new Document();
        String base64Doc = Base64.encodeToString(fileBytes, false);
        doc.setDocumentBase64(base64Doc);
        doc.setName("TestFile.pdf");
        doc.setDocumentId("1");

        List<Document> docs = new ArrayList<Document>();
        docs.add(doc);
        envDef.setDocuments(docs);

        Signer signer = new Signer();
        signer.setEmail(Recipient);
        signer.setName("Sanjay");
        signer.setRecipientId("1");
        envDef.setRecipients(new Recipients());
        envDef.getRecipients().setSigners(new ArrayList<Signer>());
        envDef.getRecipients().getSigners().add(signer);
        envDef.setStatus("sent");

        ApiClient apiClient = new ApiClient(BaseUrl);
        try {
            byte[] privateKeyBytes = null;
            try {
                privateKeyBytes = Files.readAllBytes(Paths.get(privateKeyFullPath));
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (privateKeyBytes == null)
                return;
            java.util.List<String> scopes = new ArrayList<String>();
            scopes.add(OAuth.Scope_SIGNATURE);
            OAuth.OAuthToken oAuthToken = apiClient.requestJWTUserToken(IntegratorKey, UserId, scopes, privateKeyBytes,
                    3600);
            apiClient.setAccessToken(oAuthToken.getAccessToken(), oAuthToken.getExpiresIn());
            UserInfo userInfo = apiClient.getUserInfo(oAuthToken.getAccessToken());
            apiClient.setBasePath(userInfo.getAccounts().get(0).getBaseUri() + "/restapi");
            Configuration.setDefaultApiClient(apiClient);
            String accountId = userInfo.getAccounts().get(0).getAccountId();
            EnvelopesApi envelopesApi = new EnvelopesApi();
            EnvelopeSummary envelopeSummary = envelopesApi.createEnvelope(accountId, envDef);
            System.out.println("EnvelopeSummary: " + envelopeSummary);
        } catch (ApiException ex) {
            ex.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

在上面的代码中,我只是

In above code I am just changing my account key,but not working.

我已经创建了带有示例的项目。
DocusignExample.java在这里工作,但DocusignExample1.java
在工作。

I have created project with example.Here DocusignExample.java is working but DocusignExample1.javais not working.

对于DocusignExample,我已参考(密钥)从docusign java sdk()
通过该引用,我创建了我的代码,只是更改了集成密钥, api用户名和私钥。

For DocusignExample,I have taken reference(key) from docusign java sdk(https://github.com/docusign/docusign-java-client/blob/master/src/test/java/SdkUnitTests.java)With that reference i have created my code and just change integratory key,api username and private key.

它给了我类似 com.docusign.esign.client.ApiException的错误:请求访问令牌时出错:POST 返回的响应状态为400错误请求

It's giving me error like "com.docusign.esign.client.ApiException: Error while requesting an access token: POST https://account-d.docusign.com/oauth/token returned a response status of 400 Bad Request"

推荐答案

所以您有一个有效的示例,但是当您更改集成密钥时,该示例停止了工作吗?

So you have a working example but then when you change the integration key the example stops working?

听起来您的设置有问题:请检查您使用的是正确的RSA

Sounds like a problem with your settings: check that you're using the right RSA Private key with the right Integration Key (IK).

还请检查IK是否未选中移动应用。

Also check that the IK does NOT have "Mobile app" checked.

这篇关于Java和Docusign集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 08:17