Docusignapi I';当我们使用带docusign的api发送邮件时,我获得状态0

Docusignapi I';当我们使用带docusign的api发送邮件时,我获得状态0,docusignapi,Docusignapi,我正在使用DocuSign帐户的沙盒帐户。通过使用curl和PHP,我在API的帮助下发送邮件。但它显示的结果如下所示 [确定]=>[errMsg]=>调用DocuSign时出错,状态为:0 我正在使用下面的代码。为了得到结果 define('DS_ACCOUNT_EMAIL', 'xyzmail@gmail.com'); define('DS_ACCOUNT_PW', 'xyzaccount'); define('DS_INTEGRATOR', 'YYPO-f28ccbb9-

我正在使用DocuSign帐户的沙盒帐户。通过使用curl和PHP,我在API的帮助下发送邮件。但它显示的结果如下所示

[确定]=>[errMsg]=>调用DocuSign时出错,状态为:0

我正在使用下面的代码。为了得到结果

define('DS_ACCOUNT_EMAIL',  'xyzmail@gmail.com');
define('DS_ACCOUNT_PW',     'xyzaccount');
define('DS_INTEGRATOR',     'YYPO-f28ccbb9-1cba-4f00-b03d-39814d76e700');
$documentName           = 'test';
$recipientEmail         = 'abcmail84@gmail.com';
$recipientName          = 'xyznamefortest';
$documentFileName       = 'New Text Document.txt';
 $opt =  request_signature_on_a_document($recipientEmail,$recipientName,$documentName,$documentFileName);
 print_r($opt);

function request_signature_on_a_document(
    $recipientEmail,  // signer's email
    $recipientName,   // signer's name -- first name last name
    $documentName,    // the "human" name for the document
    $documentFileName // including directory information
    ) {

    $email          = DS_ACCOUNT_EMAIL; // your account email.
    $password       = DS_ACCOUNT_PW;        // your account password
    $integratorKey  = DS_INTEGRATOR; // your account integrator key, found on (Preferences -> API page)
    // api service point
    $url            = "https://demo.docusign.net/restapi/v2/login_information"; // change for production

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

    $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 ) {
        return (['ok' => false, 'errMsg' => "Error calling DocuSign, status is: " . $status]);
    }
    $response = json_decode($json_response, true);
    $accountId = $response["loginAccounts"][0]["accountId"];
    $baseUrl = $response["loginAccounts"][0]["baseUrl"];
    curl_close($curl);

    $data = 
        array (
            "emailSubject" => "DocuSign API - Please sign " . $documentName,
            "documents" => array( 
                array("documentId" => "1", "name" => $documentName)
                ),
            "recipients" => array( 
                "signers" => array(
                    array(
                        "email" => $recipientEmail,
                        "name" => $recipientName,
                        "recipientId" => "1",
                        "tabs" => array(
                            "signHereTabs" => array(
                                array(
                                    "xPosition" => "100",
                                    "yPosition" => "100",
                                    "documentId" => "1",
                                    "pageNumber" => "1"
                                )
                            )
                        )
                    )
                )
            ),
        "status" => "sent"
    );
    $data_string    = json_encode($data);  
    $file_contents  = file_get_contents($documentFileName);
    // Create a multi-part request. First the form data, then the file content
    $requestBody = 
         "\r\n"
        ."\r\n"
        ."--myboundary\r\n"
        ."Content-Type: application/json\r\n"
        ."Content-Disposition: form-data\r\n"
        ."\r\n"
        ."$data_string\r\n"
        ."--myboundary\r\n"
        ."Content-Type:application/pdf\r\n"
        ."Content-Disposition: file; filename=\"$documentName\"; documentid=1 \r\n"
        ."\r\n"
        ."$file_contents\r\n"
        ."--myboundary--\r\n"
        ."\r\n";
    // Send to the /envelopes end point, which is relative to the baseUrl received above. 
    $curl = curl_init($baseUrl . "/envelopes" );
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $requestBody);                                                                  
    curl_setopt($curl, CURLOPT_HTTPHEADER, array(                                                                          
        'Content-Type: multipart/form-data;boundary=myboundary',
        'Content-Length: ' . strlen($requestBody),
        "X-DocuSign-Authentication: $header" )                                                                       
    );
    $json_response = curl_exec($curl) or die("err 116"); // Do it!
    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    if ( $status != 201 ) {
    //  echo "Error calling DocuSign, status is:" . $status . "\nerror text: ";
        print_r($json_response); echo "\n";
        exit(-1);
    }
    $response = json_decode($json_response, true);
    $envelopeId = $response["envelopeId"];

    return [
                'ok' => true,
        'envelopeId' => $envelopeId,
         'accountId' => $accountId,
           'baseUrl' => $baseUrl
    ];

} // end of function request_signature_on_a_document
define('DS\U帐户\U电子邮件','xyzmail@gmail.com');
定义('DS_账户''xyzaccount');
定义(“DS_积分器”、“YYPO-f28ccbb9-1cba-4f00-b03d-39814d76e700”);
$documentName='test';
$recipientEmail=abcmail84@gmail.com';
$recipientName='xyznamefortest';
$documentFileName='newtext Document.txt';
$opt=在文档上请求签名($recipientEmail、$recipientName、$documentName、$documentFileName);
打印(可选);
功能请求\u文件上的签名\u(
$recipientEmail,//签名者的电子邮件
$recipientName,//签名者的姓名--姓
$documentName,//文档的“人类”名称
$documentFileName//包括目录信息
) {
$email=DS\u ACCOUNT\u email;//您的帐户电子邮件。
$password=DS\u ACCOUNT\u PW;//您的帐户密码
$integratorKey=DS_INTEGRATOR;//在(首选项->API页)上找到您的帐户集成器密钥
//api服务点
$url=”https://demo.docusign.net/restapi/v2/login_information“;//生产变更
$header=“”.$email。“$password。”“$integratorKey。””;
$curl=curl\u init($url);
curl_setopt($curl,CURLOPT_头,false);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_HTTPHEADER,数组(“X-DocuSign-Authentication:$header”);
$json\u response=curl\u exec($curl);
$status=curl\u getinfo($curl,CURLINFO\u HTTP\u代码);
如果($status!=200){
返回(['ok'=>false,'errMsg'=>“调用DocuSign时出错,状态为:“.$status”);
}
$response=json\u decode($json\u response,true);
$accountId=$response[“loginAccounts”][0][“accountId”];
$baseUrl=$response[“loginAccounts”][0][“baseUrl”];
curl_close($curl);
$data=
排列(
“emailSubject”=>“DocuSign API-请签署”..$documentName,
“文档”=>数组(
数组(“documentId”=>“1”,“name”=>$documentName)
),
“收件人”=>数组(
“签名者”=>数组(
排列(
“电子邮件”=>$recipientEmail,
“名称”=>$recipientName,
“recipientId”=>“1”,
“制表符”=>数组(
“signHereTabs”=>数组(
排列(
“xPosition”=>“100”,
“yPosition”=>“100”,
“documentId”=>“1”,
“页码”=>“1”
)
)
)
)
)
),
“状态”=>“已发送”
);
$data\u string=json\u encode($data);
$file\u contents=file\u get\u contents($documentFileName);
//创建一个由多个部分组成的请求。首先是表单数据,然后是文件内容
$requestBody=
“\r\n”
.“\r\n”
.“--myboundary\r\n”
“内容类型:application/json\r\n”
“内容处置:表单数据\r\n”
.“\r\n”
.“$data\u字符串\r\n”
.“--myboundary\r\n”
“内容类型:应用程序/pdf\r\n”
“内容处置:文件;文件名=\”$documentName\“documentid=1\r\n”
.“\r\n”
.“$file\u contents\r\n”
.“--我的边界--\r\n”
.“\r\n”;
//发送到/envelopes端点,该端点相对于上面接收到的baseUrl。
$curl=curl_init($baseUrl./envelopes”);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_POST,true);
curl_setopt($curl,CURLOPT_POSTFIELDS,$requestBody);
curl_setopt($curl,CURLOPT_HTTPHEADER,数组(
'内容类型:多部分/表单数据;边界=myboundary',
“内容长度:”.strlen($requestBody),
“X-DocuSign-Authentication:$header”)
);
$json_response=curl_exec($curl)或die(“err 116”);//做吧!
$status=curl\u getinfo($curl,CURLINFO\u HTTP\u代码);
如果($status!=201){
//echo“调用DocuSign时出错,状态为:“.$status”。\n错误文本:”;
打印($json\U响应);回显“\n”;
出口(-1);
}
$response=json\u decode($json\u response,true);
$envelopeId=$response[“envelopeId”];
返回[
“ok”=>正确,
'envelopeId'=>$envelopeId,
“accountId”=>$accountId,
“baseUrl”=>$baseUrl
];
}//函数结束请求\u签名\u在\u文档上

此代码的用途是发送邮件。但它总是将状态显示为0。与api或设置沙盒帐户有关。

您提供的文件不正确

$documentFileName = 'New Text Document.txt';
这应该是Pdf文件,因为您正在请求正文中将
内容类型指定为
应用程序/Pdf

."--myboundary\r\n"
."Content-Type:application/pdf\r\n"
还要确保PDF文件存在于应用程序目录中。如果没有,请提供文件的完整路径