嵌入式签名api docusign

时间:2013-07-10 12:58:13

标签: api java-ee docusignapi

我正在使用DocuSign为我的请求添加电子签名,一切运行良好。现在,我通过使用嵌入式方法发送签名请求,通过导航到URL立即启动我的工作流程。

登录后,执行下面的代码,我得到(嵌入式视图:https://demo.docusign.net/Member/StartInSession.aspx?StartConsole=1&t=32598057-5a59-4d0b-bad8-a8ff8f2407f6&DocuEnvelope=168bc155-e013-4ffd-abb4-7608b56647f8&send=1),但是我粘贴网址以尝试在导航中签名文档,但是会将我重定向到其他网址({ {3}}),

怎么能开始wotkflow进程来签署我的enveloppe?我无法看到我的封面签名。

//第2步 - 创建一个包含一个收件人,文档和标签的信封并发送         //

    String jsonBody = "{\"emailBlurb\":\"partail\"," + 
            "\"emailSubject\":\"API Call for adding signature request to document and sending\"," + 
            "\"documents\":[{" + 
            "\"documentId\":\"1\"," + 
            "\"name\":\"test.pdf\"}]," + 
            "\"recipients\":{" + 
            "\"signers\":[{" + 
            "\"email\":\"" + EmailRecipients + "\"," + 
            "\"name\":\"name\"," + 
            "\"recipientId\":\"1\"," +
            "\"routingOrder\":\"1\","+
            "\"clientUserId\":\"1000\","+              
            "\"tabs\":{" + 
            "\"signHereTabs\":[{" + 
            "\"xPosition\":\"300\"," + 
            "\"yPosition\":\"600\"," + 
            "\"documentId\":\"1\"," + 
            "\"pageNumber\":\"1\"" + "}]}}]}," + 
            "\"status\":\"sent\"}";
          //DemandeSign.getenvelope();


    File file = new File("D:/test.pdf");
    InputStream inputStream = new FileInputStream(file); 
    byte[] bytes = new byte[(int) file.length()];
    inputStream.read(bytes);
    inputStream.close();

    String requestBody = "\r\n\r\n--BOUNDARY\r\n" + 
            "Content-Type: application/json\r\n" + 
            "Content-Disposition: form-data\r\n" + 
            "\r\n" + 
            jsonBody + "\r\n\r\n--BOUNDARY\r\n" +   // our json formatted request body
            "Content-Type: application/pdf\r\n" + 
            "Content-Disposition: file; filename=\"test.pdf\"; documentId=1\r\n" + 
            "\r\n";
        // we break this up into two string since the PDF doc bytes go here and are not in string format.
        // see further below where we write to the outputstream...
    String reqBody2 = "\r\n" + "--BOUNDARY--\r\n\r\n";

    // append "/envelopes" to the baseUrl and use in the request
    conn = (HttpURLConnection)new URL(baseURL + "/envelopes").openConnection();
    conn.setRequestMethod("POST");
    conn.setDoOutput(true);
    conn.setRequestProperty("X-DocuSign-Authentication", authenticateStr);
    conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=BOUNDARY");
    conn.setRequestProperty("Content-Length", Integer.toString(requestBody.toString().length()));
    conn.setRequestProperty("Accept", "application/xml"); 

    // write the body of the request...
    DataOutputStream dos = new DataOutputStream( conn.getOutputStream() );
    dos.writeBytes(requestBody.toString()); 
    dos.write(bytes);
    dos.writeBytes(reqBody2.toString()); 
    dos.flush(); dos.close();
    status = conn.getResponseCode(); // triggers the request
    if( status != 201 ) // 201 = Created
    {
        System.out.println("Error calling webservice, status is: " + status);
        InputStreamReader isr = new InputStreamReader( conn.getErrorStream() );
        br = new BufferedReader(isr);
        StringBuilder error_response = new StringBuilder();
        while ( (line = br.readLine()) != null)
            error_response.append(line);
        System.out.println("Error response is " + error_response.toString() );
        System.exit(-1);
    }
    // Read the response
    InputStreamReader isr = new InputStreamReader( conn.getInputStream() );
    br = new BufferedReader(isr);
    StringBuilder response2 = new StringBuilder();
    while ( (line = br.readLine()) != null)
        response2.append(line);
    //token1 = "//*[1]/*[local-name()='envelopeId']";
    //String envelopeId = xPath.evaluate(token1, new InputSource(new StringReader(response2.toString())));

    //--- display results
    //System.out.println("Document sent!  envelopeId is " + envelopeId );//envelopeId is e4c0659a-9d01-4ac3-a45f-02a80fd6bd96 at 04/07/2013 17:24


    token1 = "//*[1]/*[local-name()='uri']";
    String uri = xPath.evaluate(token1, new InputSource(new StringReader(response2.toString())));
    //--- display results
    System.out.println("uri = " + uri );


/// Step3
// construct another outgoing XML request body
String reqBody = "<returnUrlRequest xmlns=\"http://www.docusign.com/restapi\">" +
"<authenticationMethod>email</authenticationMethod>" +
"<email>***test@gmail.com***</email>" +
"<returnUrl>http://www.docusign.com</returnUrl>" +
"<userName>name</userName>" +
"<clientUserId>1000</clientUserId>" +
"</returnUrlRequest>";

// append uri + "/views/sender" to the baseUrl and use in the request
conn = (HttpURLConnection)new URL(baseURL + uri + "/views/sender").openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setRequestProperty("X-DocuSign-Authentication", authenticateStr);
conn.setRequestProperty("Content-Type", "application/xml");
conn.setRequestProperty("Content-Length", Integer.toString(reqBody.length()));
conn.setRequestProperty("Accept", "application/xml");
// write the body of the request...
dos = new DataOutputStream( conn.getOutputStream() );
dos.writeBytes(reqBody); dos.flush(); dos.close();
status = conn.getResponseCode(); // triggers the request
if( status != 201 ) // 201 = Created
{
System.out.println("Error calling webservice, status is: " + status);
System.exit(-1);
}
// Read the response
isr = new InputStreamReader( conn.getInputStream() );
br = new BufferedReader(isr);
StringBuilder response3 = new StringBuilder();
while ( (line = br.readLine()) != null)
response3.append(line);
token1 = "//*[1]/*[local-name()='url']";
//--- display results
System.out.println("Embedded View: " + xPath.evaluate(token1, new InputSource(new StringReader(response3.toString()))));`

1 个答案:

答案 0 :(得分:0)

您是在尝试立即访问该网址还是在等待?生成URL令牌以访问给定的信封后,它的TTL(生命时间)为5分钟,这意味着它会在5分钟后过期,然后您需要生成一个新的。

如果不是这样,您的问题可能与识别收件人的方式有关。 DocuSign中的收件人通过其名称,电子邮件,recipientId的唯一组合以及嵌入的clientUserId进行标识。您似乎设置了所有这些,但无论您在第一次创建信封时的组合是什么,在请求嵌入式URL令牌时都需要引用相同的组合。

当您创建信封时,我看到您将名称字面设置为“名称”,并且您通过名为“EmailRecipients”的变量设置电子邮件。但是,当您请求URL令牌时,您使用的是电子邮件“test@gmail.com”,这可能会导致您的问题。