[英]Signing on our website with Docusign FULL API with PHP Curl but need CURLOPT_POSTFIELDS and CURLOPT_URL
I would like our clients to clic an <input/>
button on our website and for it to sign the Docusign document, I have looked in the Docusign documentation but haven't found it.我希望我们的客户在我们的网站上单击<input/>
按钮并为其签署 Docusign 文档,我查看了 Docusign 文档但没有找到它。 Could someone explain to me how you'd do this or link me to somewhere.有人可以向我解释您将如何执行此操作或将我链接到某个地方。 The links I have found on Stackoverflow are all old and the urls
don't work anymore.我在 Stackoverflow 上找到的链接都是旧的,并且urls
不再有效。
I'd like to do this in php, like maybe curl requests, but I need the CURLOPT_POSTFIELDS
and the CURLOPT_URL
from Docusign to make those requests.我想在 php 中执行此操作,例如 curl 请求,但我需要来自 Docusign 的CURLOPT_POSTFIELDS
和CURLOPT_URL
来发出这些请求。
Like this像这样
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://docisign.com/v2.1/documents/{documentId}/users/{userId}/operations", //Just supposing
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, //Just supposing
CURLOPT_CUSTOMREQUEST => "POST", //Just supposing
CURLOPT_POSTFIELDS => "{
\"type\": \"accept\",
\"members\": [
\"/members/" . $idMember . "\" //Just supposing
],
}",
CURLOPT_HTTPHEADER => array(
"Authorization: API KEY ??", //Just supposing
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
Thank you to anyone who has more information on this topic.感谢任何对此主题有更多信息的人。
EDIT : I am using PHP 5.6编辑:我正在使用 PHP 5.6
Here is some PHP code, you can find the full example of this in here: https://github.com/docusign/eg-03-php-auth-code-grant (link to specific file - https://github.com/docusign/eg-03-php-auth-code-grant/blob/master/src/EG001EmbeddedSigning.php )这是一些 PHP 代码,您可以在此处找到完整的示例: https://github.com/docusign/eg-03-php-auth-code-grant (链接到特定文件 - Z5E056C500A1C4BADE5Z ://github.com/github.com/docusign/eg-03-php-auth-code-grant com/docusign/eg-03-php-auth-code-grant/blob/master/src/EG001EmbeddedSigning.php )
Code:代码:
/**
* Do the work of the example
* 1. Create the envelope request object
* 2. Send the envelope
* 3. Create the Recipient View request object
* 4. Obtain the recipient_view_url for the signing ceremony
* @param $args
* @return array ['redirect_url']
* @throws \DocuSign\eSign\ApiException for API problems and perhaps file access \Exception too.
*/
# ***DS.snippet.0.start
private function worker($args)
{
$envelope_args = $args["envelope_args"];
# 1. Create the envelope request object
$envelope_definition = $this->make_envelope($envelope_args);
# 2. call Envelopes::create API method
# Exceptions will be caught by the calling function
$config = new \DocuSign\eSign\Configuration();
$config->setHost($args['base_path']);
$config->addDefaultHeader('Authorization', 'Bearer ' . $args['ds_access_token']);
$api_client = new \DocuSign\eSign\Client\ApiClient($config);
$envelope_api = new \DocuSign\eSign\Api\EnvelopesApi($api_client);
$results = $envelope_api->createEnvelope($args['account_id'], $envelope_definition);
$envelope_id = $results->getEnvelopeId();
# 3. Create the Recipient View request object
$authentication_method = 'None'; # How is this application authenticating
# the signer? See the `authenticationMethod' definition
# https://developers.docusign.com/esign-rest-api/reference/Envelopes/EnvelopeViews/createRecipient
$recipient_view_request = new \DocuSign\eSign\Model\RecipientViewRequest([
'authentication_method' => $authentication_method,
'client_user_id' => $envelope_args['signer_client_id'],
'recipient_id' => '1',
'return_url' => $envelope_args['ds_return_url'],
'user_name' => $envelope_args['signer_name'], 'email' => $envelope_args['signer_email']
]);
# 4. Obtain the recipient_view_url for the signing ceremony
# Exceptions will be caught by the calling function
$results = $envelope_api->createRecipientView($args['account_id'], $envelope_id,
$recipient_view_request);
return ['envelope_id' => $envelope_id, 'redirect_url' => $results['url']];
}
/**
* Creates envelope definition
* @param $args parameters for the envelope:
* signer_email, signer_name, signer_client_id
* @return mixed -- returns an envelope definition
*/
private function make_envelope($args)
{
# document 1 (pdf) has tag /sn1/
#
# The envelope has one recipient.
# recipient 1 - signer
#
# Read the file
$demo_docs_path = __DIR__ . '/../public/demo_documents/';
$content_bytes = file_get_contents($demo_docs_path . $GLOBALS['DS_CONFIG']['doc_pdf']);
$base64_file_content = base64_encode($content_bytes);
# Create the document model
$document = new \DocuSign\eSign\Model\Document([ # create the DocuSign document object
'document_base64' => $base64_file_content,
'name' => 'Example document', # can be different from actual file name
'file_extension' => 'pdf', # many different document types are accepted
'document_id' => 1 # a label used to reference the doc
]);
# Create the signer recipient model
$signer = new \DocuSign\eSign\Model\Signer([ # The signer
'email' => $args['signer_email'], 'name' => $args['signer_name'],
'recipient_id' => "1", 'routing_order' => "1",
# Setting the client_user_id marks the signer as embedded
'client_user_id' => $args['signer_client_id']
]);
# Create a sign_here tab (field on the document)
$sign_here = new \DocuSign\eSign\Model\SignHere([ # DocuSign SignHere field/tab
'anchor_string' => '/sn1/', 'anchor_units' => 'pixels',
'anchor_y_offset' => '10', 'anchor_x_offset' => '20'
]);
# Add the tabs model (including the sign_here tab) to the signer
# The Tabs object wants arrays of the different field/tab types
$signer->settabs(new \DocuSign\eSign\Model\Tabs(['sign_here_tabs' => [$sign_here]]));
# Next, create the top level envelope definition and populate it.
$envelope_definition = new \DocuSign\eSign\Model\EnvelopeDefinition([
'email_subject' => "Please sign this document sent from the PHP SDK",
'documents' => [$document],
# The Recipients object wants arrays for each recipient type
'recipients' => new \DocuSign\eSign\Model\Recipients(['signers' => [$signer]]),
'status' => "sent" # requests that the envelope be created and sent.
]);
return $envelope_definition;
}
# ***DS.snippet.0.end
/**
* Show the example's form page
*/
private function getController()
{
if (ds_token_ok()) {
$basename = basename(__FILE__);
$GLOBALS['twig']->display('eg001_embedded_signing.html', [
'title' => "Embedded Signing Ceremony",
'source_file' => $basename,
'source_url' => $GLOBALS['DS_CONFIG']['github_example_url'] . $basename,
'documentation' => $GLOBALS['DS_CONFIG']['documentation'] . $this->eg,
'show_doc' => $GLOBALS['DS_CONFIG']['documentation'],
'signer_name' => $GLOBALS['DS_CONFIG']['signer_name'],
'signer_email' => $GLOBALS['DS_CONFIG']['signer_email']
]);
} else {
# Save the current operation so it will be resumed after authentication
$_SESSION['eg'] = $GLOBALS['app_url'] . 'index.php?page=' . $this->eg;
header('Location: ' . $GLOBALS['app_url'] . 'index.php?page=must_authenticate');
exit;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.