Docusignapi DocuSign-如何通过API控制发送通知

Docusignapi DocuSign-如何通过API控制发送通知,docusignapi,Docusignapi,我正在使用RESTAPI创建一个将由多个组织使用的解决方案 API中是否有方法控制发送方接收通知的人?默认情况下,所有通知电子邮件都会发送到我创建API帐户时设置的电子邮件。但我确实需要能够将这些通知发送给实际发送文档的人 以下是我正在使用的代码: public static function sendForSignature($filename, //The name of the file that will show up in the email

我正在使用RESTAPI创建一个将由多个组织使用的解决方案

API中是否有方法控制发送方接收通知的人?默认情况下,所有通知电子邮件都会发送到我创建API帐户时设置的电子邮件。但我确实需要能够将这些通知发送给实际发送文档的人

以下是我正在使用的代码:

public static function sendForSignature($filename,  //The name of the file that will show up in the email
                                        $document_path, //The path to the file on the server
                                        $template, //The json template file for this document                                           
                                        $opportunity=null, //The opportunity if applicable
                                        $company_id=-1, //The company id if applicable
                                        $contact_id=-1) //The contact if applicable
{       
    $envelop_summary = null;
    $company = null;
    $contact = null;

    $sign_here_tabs=[];
    $full_name_tabs=[];
    $date_tabs=[];
    $text_tabs=[];
    $all_documents=[];

    $basePath = Yii::getAlias('@frontend').'/doclib';
    $mappingPath = $basePath.'/mapping';

    $config = new \DocuSign\eSign\Configuration();
    $config->setHost(\Yii::$app->params['docusign_host']);
    $config->addDefaultHeader("X-DocuSign-Authentication", 
        "{\"Username\":\"" . \Yii::$app->params['docusign_username'] . 
        "\",\"Password\":\"" . \Yii::$app->params['docusign_password'] . 
        "\",\"IntegratorKey\":\"" . \Yii::$app->params['docusign_integrator_key'] . "\"}");

    $apiClient = new \DocuSign\eSign\ApiClient($config);
    $accountId = null;

    $organization = Organization::findOne(['id' => Yii::$app->user->getIdentity()->org_id]);
    $user = User::findOne(['id' => Yii::$app->user->getIdentity()->id]);

    if($opportunity !== null){
        $company = $opportunity->company;
        $contact = $opportunity->contact;
    }else{
        $company = Company::findOne(['company_id' => $company_id]);
        $contact = Contact::findOne(['contact_id' => $contact_id]);
    }

    try 
    {
        //*** STEP 1 - Login API
        $authenticationApi = new \DocuSign\eSign\Api\AuthenticationApi($apiClient);
        $options = new \DocuSign\eSign\Api\AuthenticationApi\LoginOptions();
        $loginInformation = $authenticationApi->login($options);

        if(isset($loginInformation) && count($loginInformation) > 0)
        {
            $loginAccount = $loginInformation->getLoginAccounts()[0];
            if(isset($loginInformation))
            {
                $accountId = $loginAccount->getAccountId();

                $envelopeApi = new \DocuSign\eSign\Api\EnvelopesApi($apiClient);

                $index = 0;

                if(is_array($document_path)){

                    foreach($document_path as $d){

                        $pdf = new FPDI();
                        $page_count = $pdf->setSourceFile($d);

                        $document = new \DocuSign\eSign\Model\Document();
                        $document->setDocumentBase64(base64_encode(file_get_contents($d)));
                        $document->setName($filename[$index]);
                        $document->setDocumentId($index+1);
                        $all_documents[]=$document;

                        $template_file = json_decode(file_get_contents($mappingPath .'/'. $template[$index]));

                        foreach($template_file as $t){
                            if($t->type == 'signHereTab'){
                                $signHere = new \DocuSign\eSign\Model\SignHere();

                                if(isset($t->anchorString)){
                                    $signHere->setAnchorString($t->anchorString);
                                    $signHere->setAnchorXOffset($t->anchorXOffset);
                                    $signHere->setAnchorYOffset($t->anchorYOffset);
                                    $signHere->setAnchorUnits($t->anchorUnits);
                                }else if(isset($t->xPosition)){
                                    $signHere->setXPosition($t->xPosition);
                                    $signHere->setYPosition($t->yPosition);
                                }

                                // $signHere->setAnchorIgnoreIfNotPresent($t->anchorIgnoreIfNotPresent);
                                $signHere->setDocumentId($index+1);
                                if($t->page == -1){
                                    $signHere->setPageNumber($page_count);
                                }else{
                                    $signHere->setPageNumber($t->page);
                                }
                                $signHere->setRecipientId("1");

                                $sign_here_tabs[]=$signHere;
                            }else if($t->type == 'fullNameTab'){
                                $fullName = new \DocuSign\eSign\Model\FullName;
                                if(isset($t->anchorString)){
                                    $fullName->setAnchorString($t->anchorString);
                                    $fullName->setAnchorXOffset($t->anchorXOffset);
                                    $fullName->setAnchorYOffset($t->anchorYOffset);
                                    $fullName->setAnchorUnits($t->anchorUnits);
                                }else if(isset($t->xPosition)){
                                    $fullName->setXPosition($t->xPosition);
                                    $fullName->setYPosition($t->yPosition);
                                }

                                // $fullName->setAnchorIgnoreIfNotPresent($t->anchorIgnoreIfNotPresent);
                                $fullName->setDocumentId($index+1);
                                if($t->page == -1){
                                    $fullName->setPageNumber($page_count);
                                }else{
                                    $fullName->setPageNumber($t->page);
                                }
                                $fullName->setRecipientId(1);

                                $full_name_tabs[]=$fullName;
                            }else if($t->type == 'textTab'){
                                $text = new \DocuSign\eSign\Model\Text;
                                if(isset($t->anchorString)){
                                    $text->setAnchorString($t->anchorString);
                                    $text->setAnchorXOffset($t->anchorXOffset);
                                    $text->setAnchorYOffset($t->anchorYOffset);
                                    $text->setAnchorUnits($t->anchorUnits);
                                }else if(isset($t->xPosition)){
                                    $text->setXPosition($t->xPosition);
                                    $text->setYPosition($t->yPosition);
                                }

                                if(isset($t->label))
                                    $text->setTabLabel($t->label);
                                // $text->setAnchorIgnoreIfNotPresent($t->anchorIgnoreIfNotPresent);
                                $text->setDocumentId($index+1);
                                if($t->page == -1){
                                    $text->setPageNumber($page_count);
                                }else{
                                    $text->setPageNumber($t->page);
                                }
                                $text->setRecipientId("1");

                                $text_tabs[]=$text;

                            }else if($t->type == 'dateTab'){

                                $date = new \DocuSign\eSign\Model\Date;

                                if(isset($t->anchorString)){
                                    $date->setAnchorString($t->anchorString);
                                    $date->setAnchorXOffset($t->anchorXOffset);
                                    $date->setAnchorYOffset($t->anchorYOffset);
                                    $date->setAnchorUnits($t->anchorUnits);
                                }else if(isset($t->xPosition)){
                                    $date->setXPosition($t->xPosition);
                                    $date->setYPosition($t->yPosition);
                                }

                                // $date->setAnchorIgnoreIfNotPresent($t->anchorIgnoreIfNotPresent);
                                $date->setDocumentId($index+1);
                                if($t->page == -1){
                                    $date->setPageNumber($page_count);
                                }else{
                                    $date->setPageNumber($t->page);
                                }
                                $date->setRecipientId(1);

                                $date_tabs[] = $date;
                            }
                        }

                        $index++;
                    }

                }else{
                    // Add a document to the envelope
                    $document = new \DocuSign\eSign\Model\Document();
                    $document->setDocumentBase64(base64_encode(file_get_contents($document_path)));
                    $document->setName($filename);
                    $document->setDocumentId("1");
                    $all_documents[] = $document;

                    $pdf = new FPDI();
                    $page_count = $pdf->setSourceFile($document_path);

                    $template_file = json_decode(file_get_contents($mappingPath .'/'. $template));

                    foreach($template_file as $t){
                        if($t->type == 'signHereTab'){
                            $signHere = new \DocuSign\eSign\Model\SignHere();

                            if(isset($t->anchorString)){
                                $signHere->setAnchorString($t->anchorString);
                                $signHere->setAnchorXOffset($t->anchorXOffset);
                                $signHere->setAnchorYOffset($t->anchorYOffset);
                                $signHere->setAnchorUnits($t->anchorUnits);
                            }else if(isset($t->xPosition)){
                                $signHere->setXPosition($t->xPosition);
                                $signHere->setYPosition($t->yPosition);
                            }

                            // $signHere->setAnchorIgnoreIfNotPresent($t->anchorIgnoreIfNotPresent);
                            $signHere->setDocumentId("1");
                            if($t->page == -1){
                                $signHere->setPageNumber($page_count);
                            }else{
                                $signHere->setPageNumber($t->page);
                            }
                            $signHere->setRecipientId("1");

                            $sign_here_tabs[]=$signHere;
                        }else if($t->type == 'fullNameTab'){
                            $fullName = new \DocuSign\eSign\Model\FullName;
                            if(isset($t->anchorString)){
                                $fullName->setAnchorString($t->anchorString);
                                $fullName->setAnchorXOffset($t->anchorXOffset);
                                $fullName->setAnchorYOffset($t->anchorYOffset);
                                $fullName->setAnchorUnits($t->anchorUnits);
                            }else if(isset($t->xPosition)){
                                $fullName->setXPosition($t->xPosition);
                                $fullName->setYPosition($t->yPosition);
                            }

                            // $fullName->setAnchorIgnoreIfNotPresent($t->anchorIgnoreIfNotPresent);
                            $fullName->setDocumentId(1);
                            if($t->page == -1){
                                $fullName->setPageNumber($page_count);
                            }else{
                                $fullName->setPageNumber($t->page);
                            }
                            $fullName->setRecipientId(1);

                            $full_name_tabs[]=$fullName;
                        }else if($t->type == 'textTab'){
                            $text = new \DocuSign\eSign\Model\Text;
                            if(isset($t->anchorString)){
                                $text->setAnchorString($t->anchorString);
                                $text->setAnchorXOffset($t->anchorXOffset);
                                $text->setAnchorYOffset($t->anchorYOffset);
                                $text->setAnchorUnits($t->anchorUnits);
                            }else if(isset($t->xPosition)){
                                $text->setXPosition($t->xPosition);
                                $text->setYPosition($t->yPosition);
                            }

                            if(isset($t->label))
                                $text->setTabLabel($t->label);
                            // $text->setAnchorIgnoreIfNotPresent($t->anchorIgnoreIfNotPresent);
                            $text->setDocumentId("1");
                            if($t->page == -1){
                                $text->setPageNumber($page_count);
                            }else{
                                $text->setPageNumber($t->page);
                            }
                            $text->setRecipientId("1");

                            $text_tabs[]=$text;

                        }else if($t->type == 'dateTab'){

                            $date = new \DocuSign\eSign\Model\Date;

                            if(isset($t->anchorString)){
                                $date->setAnchorString($t->anchorString);
                                $date->setAnchorXOffset($t->anchorXOffset);
                                $date->setAnchorYOffset($t->anchorYOffset);
                                $date->setAnchorUnits($t->anchorUnits);
                            }else if(isset($t->xPosition)){
                                $date->setXPosition($t->xPosition);
                                $date->setYPosition($t->yPosition);
                            }

                            // $date->setAnchorIgnoreIfNotPresent($t->anchorIgnoreIfNotPresent);
                            $date->setDocumentId(1);
                            if($t->page == -1){
                                $date->setPageNumber($page_count);
                            }else{
                                $date->setPageNumber($t->page);
                            }
                            $date->setRecipientId(1);

                            $date_tabs[] = $date;
                        }
                    }               
                }

                $tabs = new \DocuSign\eSign\Model\Tabs();

                if(count($sign_here_tabs) > 0)
                    $tabs->SetSignHereTabs($sign_here_tabs);
                if(count($full_name_tabs) > 0)
                    $tabs->setFullNameTabs($full_name_tabs);
                if(count($text_tabs) > 0)
                    $tabs->setTextTabs($text_tabs);
                if(count($date_tabs) > 0)
                    $tabs->setDateTabs($date_tabs);

                $signer = new \DocuSign\eSign\Model\Signer();
                $signer->setEmail(trim($contact->email));
                if(!is_null($contact))
                    $signer->setName($contact->first_name.' '.$contact->last_name);

                $signer->setRecipientId("1");                                                   
                $signer->setTabs($tabs);

                $emailNotification = new \DocuSign\eSign\Model\RecipientEmailNotification();
                $emailNotification->setEmailSubject('Please sign these document(s).');
                $signer->setEmailNotification($emailNotification);

                // Add a recipient to sign the document
                $recipients = new \DocuSign\eSign\Model\Recipients();
                $recipients->setSigners(array($signer));

                $envelope_events = [
                    // (new \DocuSign\eSign\Model\EnvelopeEvent())->setEnvelopeEventStatusCode("sent"),
                    // (new \DocuSign\eSign\Model\EnvelopeEvent())->setEnvelopeEventStatusCode("delivered"),
                    (new \DocuSign\eSign\Model\EnvelopeEvent())->setEnvelopeEventStatusCode("completed"),
                    // (new \DocuSign\eSign\Model\EnvelopeEvent())->setEnvelopeEventStatusCode("declined"),
                    // (new \DocuSign\eSign\Model\EnvelopeEvent())->setEnvelopeEventStatusCode("voided"),
                    // (new \DocuSign\eSign\Model\EnvelopeEvent())->setEnvelopeEventStatusCode("sent"),
                    // (new \DocuSign\eSign\Model\EnvelopeEvent())->setEnvelopeEventStatusCode("sent")
                ];

                $recipient_events = [
                    // (new \DocuSign\eSign\Model\RecipientEvent())->setRecipientEventStatusCode("Sent"),
                    // (new \DocuSign\eSign\Model\RecipientEvent())->setRecipientEventStatusCode("Delivered"),
                    // (new \DocuSign\eSign\Model\RecipientEvent())->setRecipientEventStatusCode("Completed"),
                    // (new \DocuSign\eSign\Model\RecipientEvent())->setRecipientEventStatusCode("Declined"),
                    // (new \DocuSign\eSign\Model\RecipientEvent())->setRecipientEventStatusCode("AuthenticationFailed"),
                    // (new \DocuSign\eSign\Model\RecipientEvent())->setRecipientEventStatusCode("AutoResponded")
                ];

                $event_notification = new \DocuSign\eSign\Model\EventNotification();
                $event_notification->setUrl(\Yii::$app->params['docusign_callback_url']);
                $event_notification->setLoggingEnabled("true");
                $event_notification->setRequireAcknowledgment("false");
                $event_notification->setUseSoapInterface("false");
                $event_notification->setIncludeCertificateWithSoap("false");
                $event_notification->setSignMessageWithX509Cert("false");
                $event_notification->setIncludeDocuments("true");
                $event_notification->setIncludeEnvelopeVoidReason("true");
                $event_notification->setIncludeTimeZone("true");
                $event_notification->setIncludeSenderAccountAsCustomField("true");
                $event_notification->setIncludeDocumentFields("true");
                $event_notification->setIncludeCertificateOfCompletion("false");
                $event_notification->setEnvelopeEvents($envelope_events);
                // $event_notification->setRecipientEvents($recipient_events);

                $email_settings = new \DocuSign\eSign\Model\EmailSettings();
                $email_settings->setReplyEmailAddressOverride($user->email);
                $email_settings->setReplyEmailNameOverride($user->first_name.' '.$user->last_name);

                $envelop_definition = new \DocuSign\eSign\Model\EnvelopeDefinition();
                $envelop_definition->setEmailSubject("Document(s) from: ".$user->first_name.' '.$user->last_name.' '.$organization->name);
                $envelop_definition->setEventNotification($event_notification);
                $envelop_definition->setEmailSettings($email_settings);

                // set envelope status to "sent" to immediately send the signature request
                $status = 'sent';
                $envelop_definition->setStatus($status);
                $envelop_definition->setRecipients($recipients);
                $envelop_definition->setDocuments($all_documents);

                $envelop_summary = $envelopeApi->createEnvelope($accountId, $envelop_definition, null);

                foreach($all_documents as $d){
                    $sd = new SignedDocument;
                    if($opportunity !== null)
                        $sd->opportunity_id = $opportunity->opportunity_id;
                    $sd->company_id = ($company == null) ? -1 : $company->company_id;
                    $sd->contact_id = ($contact == null) ? -1 : $contact->contact_id;
                    $sd->user_id = \Yii::$app->user->getIdentity()->id;
                    $sd->signature_id = $envelop_summary->getEnvelopeId();
                    $sd->save();
                }

                return 201;             
            }
        }
    }
    catch (DocuSign\eSign\ApiException $ex)
    {           
        Yii::error("Exception: " . $ex->getMessage().' '.$ex->getResponseBody(),'Signature');
        return 500;
    }
}

身份验证标头中指定的凭据将用于确定发件人帐户。在您的示例中,
$app->params['docusign\u username']
将接收发件人的电子邮件,因为发件人就是发送文档的人

如果您正在创建一个将由多个组织使用的应用程序,那么这不是正确的方法

您应该为您的用例使用流

用户应用程序

用户应用程序是使用DocuSign对每个最终用户进行身份验证的客户端。这些应用程序通常是web服务、移动应用程序或桌面程序,用于在DocuSign平台上对单个用户进行身份验证。一旦通过身份验证,用户同意应用程序显示、发送或签署其帐户中的信封。对于用户应用程序,建议使用OAuth2身份验证流

服务集成

服务集成是直接与DocuSign帐户集成的服务。这种集成通常保留给在DocuSign平台上进行身份验证的后端服务,而不需要最终用户的参与。例如,后端应用程序可以集成到业务线应用程序中,以自动发送新成员注册。对于服务集成,建议使用自定义X-DocuSign-Authentication标头


身份验证标头中指定的凭据将用于确定发件人帐户。在您的示例中,
$app->params['docusign\u username']
将接收发件人的电子邮件,因为发件人就是发送文档的人

如果您正在创建一个将由多个组织使用的应用程序,那么这不是正确的方法

您应该为您的用例使用流

用户应用程序

用户应用程序是使用DocuSign对每个最终用户进行身份验证的客户端。这些应用程序通常是web服务、移动应用程序或桌面程序,用于在DocuSign平台上对单个用户进行身份验证。一旦通过身份验证,用户同意应用程序显示、发送或签署其帐户中的信封。对于用户应用程序,建议使用OAuth2身份验证流

服务集成

服务集成是直接与DocuSign帐户集成的服务。这种集成通常保留给在DocuSign平台上进行身份验证的后端服务,而不需要最终用户的参与。例如,后端应用程序可以集成到业务线应用程序中,以自动发送新成员注册。对于服务集成,建议使用自定义X-DocuSign-Authentication标头


您使用的是哪种身份验证机制?你能发布一些你的信封创建代码吗?Hi@CodingDawg刚刚添加了一套完整的代码,用于发送文件供签名。谢谢。您使用的是哪种身份验证机制?你能发布一些你的信封创建代码吗?Hi@CodingDawg刚刚添加了一套完整的代码,用于发送文件供签名。谢谢。嗨@CodingDawg谢谢你的信息。那么,我可以继续在oAuth中使用PHPSDK吗?还是必须直接编码到RESTAPI?PHPSDK支持Docusign oAuth Api。看见另请参阅更多信息Hi@CodingDawg感谢您提供此信息。那么,我可以继续在oAuth中使用PHPSDK吗?还是必须直接编码到RESTAPI?PHPSDK支持Docusign oAuth Api。看见另请参阅更多信息