You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过DocuSign eSignature API移除签署页多余非签名字段

问题描述

我通过DocuSign eSignature REST API创建信封并生成了签署链接,代码如下。但点击链接进入签署页时,页面会显示文本框、复选框、标题、姓名等多余字段,用户甚至只需添加复选框就能点击完成按钮跳转,这不符合预期。我希望签署页仅保留签名字段,移除其他所有多余字段,请问该如何实现?

public function makeSignlinkTest($docusign_parameters){
    
    $config = new Configuration();
    $apiClient = new ApiClient($config);
    $this->apiClient = $apiClient;
    $this->config = $config;
    $apiClient->getOAuth()->setOAuthBasePath($docusign_parameters['authwebserver']);
    $privateKey = file_get_contents($docusign_parameters['private_key_path'], true);
    $jwt_scope =  "signature impersonation"; 

    $result = $apiClient->requestJWTUserToken(
        $docusign_parameters['client_id'],
        $docusign_parameters['user_id'],
        $privateKey,
        $jwt_scope
    );

    $access_token = $result[0]->getAccessToken();
    
    $uinfo = $apiClient->getUserInfo($access_token);
    $accs = $uinfo[0]->getAccounts();
    $acc_id = '';
    $acc_base_path = '';
    foreach($accs as $ac){
        
        $acc_id = $ac->getAccountId();
        $acc_base_path = $ac->getBaseUri();
        
    }

    
    $args = [];
    $args['envelope_args'] = [
        'signer_email' => $this->user_data['user_email'],
        'signer_name' => $this->user_data['user_name'],
        'signer_client_id' => $this->user_data['user_client_id']
    ];
    $args['account_id'] = $docusign_parameters['api_account_id'];//API Account ID
    $demoPath = $this->file_data['file_dirname'];//
    $pdfFile = $this->file_data['file_name'].'.'.$this->file_data['file_extension'];//
    $envelope_definition = $this->makeEnvelope($args["envelope_args"], $demoPath, $pdfFile);
    $apiClient->getOAuth()->setOAuthBasePath($acc_base_path.'/restapi');//'account-d.docusign.com'
    $apiClient->getOAuth()->setBasePath($acc_base_path.'/restapi');//'demo.docusign.net'
    $config->setHost($acc_base_path.'/restapi');//https://demo.docusign.net/restapi
    $envelope_api = new EnvelopesApi($apiClient);
    # Call Envelopes::create API method
    # Exceptions will be caught by the calling function
    try {
        $envelopeSummary = $envelope_api->createEnvelope($args['account_id'], $envelope_definition);
        
    } catch (ApiException $e) {
        $rb = $e->getResponseBody();
        $msg = $rb->message;
        return $msg;
    }
    $envelope_id = $envelopeSummary->getEnvelopeId();
    $rec_req = new RecipientViewRequest(
                [
                    'authentication_method' => 'None',
                    'client_user_id' => $this->user_data['user_client_id'],
                    'recipient_id' => $this->user_data['user_id'].'',
                    'return_url' => $this->docusign_parameters['redirect_uri'].'&state='.$this->file_hash,
                    'user_name' => $this->user_data['user_name'],
                    'email' => $this->user_data['user_email']
                ]
            );

    $view_url = $envelope_api->createRecipientView($acc_id, $envelope_id,$rec_req);
    $sign_url = '';
    if(is_object($view_url) && method_exists($view_url, 'getUrl') ){
        $sign_url = $view_url->getUrl();
    }
    return $sign_url;
}
解决方案

多余字段的根源在于makeEnvelope方法的实现——这个方法负责定义信封包含的文档和签署控件,你需要修改它,只添加签名字段,移除所有不必要的控件。

1. 重写makeEnvelope方法,仅保留签名字段

以下是仅添加签名字段的示例实现,替换你当前的makeEnvelope方法即可:

private function makeEnvelope($envelopeArgs, $demoPath, $pdfFile) {
    // 读取目标PDF文件并转成base64编码
    $contentBytes = file_get_contents($demoPath . DIRECTORY_SEPARATOR . $pdfFile);
    $base64File = base64_encode($contentBytes);

    // 创建文档对象
    $document = new Document([
        'document_base64' => $base64File,
        'name' => '待签署文件',
        'document_id' => '1' // 文档ID需唯一
    ]);

    // 创建签署人对象
    $signer = new Signer([
        'email' => $envelopeArgs['signer_email'],
        'name' => $envelopeArgs['signer_name'],
        'recipient_id' => '1',
        'client_user_id' => $envelopeArgs['signer_client_id'] // 适配嵌入式签署
    ]);

    // 创建签名字段(可调整x/y坐标匹配PDF上的签署位置)
    $signHere = new SignHere([
        'document_id' => '1',
        'page_number' => '1',
        'recipient_id' => '1',
        'x_position' => '150', // 签署框的X坐标
        'y_position' => '400'  // 签署框的Y坐标
    ]);

    // 给签署人绑定签名字段
    $signer->setSignHereTabs([$signHere]);

    // 构建信封定义
    $envelopeDefinition = new EnvelopeDefinition([
        'email_subject' => '请完成签署',
        'documents' => [$document],
        'recipients' => new Recipients(['signers' => [$signer]]),
        'status' => 'sent' // 直接发送信封
    ]);

    return $envelopeDefinition;
}

2. 检查模板配置(如果使用了DocuSign模板)

如果你的makeEnvelope是基于DocuSign平台上的模板创建的,需要:

  • 登录DocuSign后台,找到对应模板,删除模板内的文本框、复选框等多余控件,只保留签名字段
  • 或者在API调用中覆盖模板的字段配置,强制只添加签名字段

3. 确认RecipientViewRequest无额外配置

确保你的RecipientViewRequest没有开启强制显示额外字段的配置,当前代码中的设置是合理的,无需修改。

注意事项

  • 签名字段的x_position和y_position需要根据你的PDF实际布局调整,确保签署框显示在正确位置
  • 如果需要多个签名字段,只需添加多个SignHere对象到signHereTabs数组即可

内容的提问来源于stack exchange,提问作者olevacho

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 13:44:57