Подписываемся на нашем сайте с помощью Docusign FULL API с помощью PHP Curl, но нужно CURLOPT_POSTFIELDS и CURLOPT_URL - PullRequest
0 голосов
/ 10 октября 2019

Я бы хотел, чтобы наши клиенты нажимали кнопку <input/> на нашем веб-сайте и чтобы она подписывала документ Docusign, я просматривал документацию Docusign, но не нашел ее. Может ли кто-нибудь объяснить мне, как ты это сделаешь, или связать меня с кем-нибудь? Все ссылки, которые я нашел в Stackoverflow, старые и urls больше не работают.

Я хотел бы сделать это в php, как, например, запросы curl, но мне нужны CURLOPT_POSTFIELDS иCURLOPT_URL от Docusign, чтобы сделать эти запросы.

Как это

$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);

Спасибо всем, кто имеет больше информации по этой теме.

РЕДАКТИРОВАТЬ: я использую PHP 5.6

1 Ответ

0 голосов
/ 10 октября 2019

Вот некоторый код PHP, полный пример этого можно найти здесь: https://github.com/docusign/eg-03-php-auth-code-grant (ссылка на конкретный файл - https://github.com/docusign/eg-03-php-auth-code-grant/blob/master/src/EG001EmbeddedSigning.php)

Код:

 /**
 * 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;
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...