繁体   English   中英

用于签名的嵌入式文档-Docu Sign REST API

[英]Embedded document for Signing -Docu sign REST API

我正在使用REST api来嵌入签名。我想为每个登录我的网站的用户嵌入一个文档,用于在网站中签名。 为此,我创建了一个模板并添加一些标签并根据需要设置它们。 在“收件人和路由”部分中创建模板时,我仅提供了一个签名者电子邮件和姓名。 为了生成用于嵌入式签名的URL,我使用了以下代码

<?php

// Input your info:
$email = "***";         // your account email
$password = "***";      // your account password
$integratorKey = "***";     // your account integrator key, found on (Preferences -> API page)
$recipientName = "***";     // provide a recipient (signer) name
$templateId = "***";        // provide a valid templateId of a template in your account
$templateRoleName = "***";  // use same role name that exists on the template in the console
$clientUserId = "***";      // to add an embedded recipient you must set their clientUserId property in addition to
                // the recipient name and email.  Whatever you set the clientUserId to you must use the same
                // value when requesting the signing URL

// construct the authentication header:
$header = "<DocuSignCredentials><Username>" . $email . "</Username><Password>" . $password . "</Password><IntegratorKey>" . $integratorKey . "</IntegratorKey></DocuSignCredentials>";

/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 1 - Login (retrieves baseUrl and accountId)
/////////////////////////////////////////////////////////////////////////////////////////////////
$url = "https://demo.docusign.net/restapi/v2/login_information";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-DocuSign-Authentication: $header"));

$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

if ( $status != 200 ) {
    echo "error calling webservice, status is:" . $status;
    exit(-1);
}

$response = json_decode($json_response, true);
$accountId = $response["loginAccounts"][0]["accountId"];
$baseUrl = $response["loginAccounts"][0]["baseUrl"];
curl_close($curl);

//--- display results
echo "accountId = " . $accountId . "\nbaseUrl = " . $baseUrl . "\n";

/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 2 - Create an envelope with an Embedded recipient (uses the clientUserId property)
/////////////////////////////////////////////////////////////////////////////////////////////////
$data = array("accountId" => $accountId, 
    "emailSubject" => "DocuSign API - Embedded Signing Example",
    "templateId" => $templateId, 
    "templateRoles" => array(
        array( "roleName" => $templateRoleName, "email" => $email, "name" => $recipientName, "clientUserId" => $clientUserId )),
    "status" => "sent");                                                                    

$data_string = json_encode($data);  
$curl = curl_init($baseUrl . "/envelopes" );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);                                                                  
curl_setopt($curl, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: application/json',                                                                                
    'Content-Length: ' . strlen($data_string),
    "X-DocuSign-Authentication: $header" )                                                                       
);

$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 201 ) {
    echo "error calling webservice, status is:" . $status . "\nerror text is --> ";
    print_r($json_response); echo "\n";
    exit(-1);
}

$response = json_decode($json_response, true);
$envelopeId = $response["envelopeId"];
curl_close($curl);

//--- display results   
echo "Envelope created! Envelope ID: " . $envelopeId . "\n"; 

/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 3 - Get the Embedded Singing View 
/////////////////////////////////////////////////////////////////////////////////////////////////
$data = array("returnUrl" => "http://www.docusign.com/devcenter",
    "authenticationMethod" => "None", "email" => $email, 
    "userName" => $recipientName, "clientUserId" => $clientUserId
);                                                                    

$data_string = json_encode($data);    
$curl = curl_init($baseUrl . "/envelopes/$envelopeId/views/recipient" );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);                                                                  
curl_setopt($curl, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: application/json',                                                                                
    'Content-Length: ' . strlen($data_string),
    "X-DocuSign-Authentication: $header" )                                                                       
);

$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 201 ) {
    echo "error calling webservice, status is:" . $status . "\nerror text is --> ";
    print_r($json_response); echo "\n";
    exit(-1);
}

$response = json_decode($json_response, true);
$url = $response["url"];

//--- display results
echo "Embedded URL is: \n\n" . $url . "\n\nNavigate to this URL to start the embedded signing view of the envelope\n"; 

?>

并成功生成链接。 但是问题是我看不到模板中设置的标签,左侧有一个字段列表,是否还有其他设置可以为所有登录用户显示标签?访问文档进行签名。

作为此处的后续步骤,问题似乎出在您的收件人与模板上的roleName不匹配。 为了社区的利益,每当您创建信封/从模板请求签名时,都需要确保在API请求中指定与在DocuSign控制台中指定模板角色相同的完全相同的roleName

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM