使用curl-php发送docx文件
我正在为docusign使用restapi 我正在将文档发送给另一个用户进行在线签名。代码中发生的情况是,正在上载文档,并且正在使用file_get_contents函数读取文件的内容,然后使用curl将此内容通过docusign发送给其他用户 这是我的密码:使用curl-php发送docx文件,php,docusignapi,Php,Docusignapi,我正在为docusign使用restapi 我正在将文档发送给另一个用户进行在线签名。代码中发生的情况是,正在上载文档,并且正在使用file_get_contents函数读取文件的内容,然后使用curl将此内容通过docusign发送给其他用户 这是我的密码: $data = "{ \"emailBlurb\":\"\", \"emailSubject\":\"DocuSign API - Please Sign This Document...\", \"documents\":[
$data = "{
\"emailBlurb\":\"\",
\"emailSubject\":\"DocuSign API - Please Sign This Document...\",
\"documents\":[
{
\"documentId\":\"1\",
\"name\":\"agreement.pdf\"
}
],
\"recipients\":{
\"signers\":[
{
\"email\":\"$email\",
\"name\":\"$name\",
\"recipientId\":\"1\",
\"tabs\":{
\"signHereTabs\":[
{
\"xPosition\":\"100\",
\"yPosition\":\"100\",
\"documentId\":\"1\",
\"pageNumber\":\"1\"
}
]
}
}
]
},
\"status\":\"sent\"
}";
$file_contents = file_get_contents("uploads/envelopes/" . $file_name);
$requestBody = "\r\n"
."\r\n"
."--myboundary\r\n"
."Content-Type: application/json\r\n"
."Content-Disposition: form-data\r\n"
."\r\n"
."$data\r\n"
."--myboundary\r\n"
."Content-Type:application/pdf\r\n"
."Content-Disposition: file; filename=\”document.pdf\"; documentid=1 \r\n"
."\r\n"
."$file_contents\r\n"
."--myboundary--\r\n"
."\r\n";
// *** append "/envelopes" to baseUrl and as signature request endpoint
$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);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 201 ) {
$msg = 'Error. Please try again';
}
上述代码适用于pdf文件,但不适用于docx文件。
对于docx文件,我更改了如下代码(更改了内容类型):
谢谢DocuSign不支持发送.docx文件,因此文件格式不会引起您的问题。尝试发送.docx文件时是否收到特定错误消息?如果是,那么错误是什么 FWIW,我能够通过docusignrestapi发送一个.docx文件——我在下面包含了我的完整请求。如果可能的话,我建议您使用Fiddler(或任何类似的实用程序)生成发送到服务器的完整请求的跟踪,并将其内容/结构与我在下面介绍的(成功的)示例请求进行比较。这样做有望让您识别(并解决)请求中的问题
POST https://demo.docusign.net/restapi/v2/accounts/ACCOUNT_NUMBER/envelopes HTTP/1.1
X-DocuSign-Authentication: {"Username":"USERNAME","Password":"PASSWORD","IntegratorKey":"INTEGRATOR_KEY"}
Content-Type: multipart/form-data; boundary=MY_BOUNDARY
Accept: application/json
Host: demo.docusign.net
Content-Length: 15384
--MY_BOUNDARY
Content-Type: application/json
Content-Disposition: form-data
{
"status" : "sent",
"emailBlurb":"Test Email Body",
"emailSubject": "-- Test Email Subject --",
"documents": [
{
"name": "CustomerAgreement.docx",
"documentId": 1
}],
"recipients": {
"signers" : [{
"email": "bobsemail@outlook.com",
"name": "Bob Adamson",
"recipientId": "1",
"routingOrder": "1",
"tabs": {
"signHereTabs": [
{
"recipientId": "1",
"tabLabel": "Customer_Signature",
"documentId": "1",
"pageNumber": "1",
"xPosition": "99",
"yPosition": "424"
}]
}
}]
}
}
--MY_BOUNDARY
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
Content-Disposition: file; filename="CustomerAgreement.docx"; documentid="1"
<document bytes removed>
--MY_BOUNDARY--
POSThttps://demo.docusign.net/restapi/v2/accounts/ACCOUNT_NUMBER/envelopes HTTP/1.1
X-DocuSign-Authentication:{“用户名”:“用户名”,“密码”:“密码”,“积分器密钥”:“积分器密钥”}
内容类型:多部分/表单数据;边界=我的边界
接受:application/json
主机:demo.docusign.net
内容长度:15384
--我的边界
内容类型:application/json
内容配置:表单数据
{
“状态”:“已发送”,
“emailBlurb”:“测试电子邮件正文”,
“emailSubject:”--测试电子邮件主题--“,
“文件”:[
{
“名称”:“CustomerAgreement.docx”,
“文档ID”:1
}],
“收件人”:{
“签署人”:[{
“电子邮件”:bobsemail@outlook.com",
“姓名”:“鲍勃·亚当森”,
“接收方ID”:“1”,
“路由顺序”:“1”,
“选项卡”:{
“signHereTabs”:[
{
“接收方ID”:“1”,
“tabLabel”:“客户签名”,
“documentId”:“1”,
“页码”:“1”,
“xPosition”:“99”,
“yPosition”:“424”
}]
}
}]
}
}
--我的边界
内容类型:application/vnd.openxmlformats-officedocument.wordprocessingml.document
内容配置:文件;filename=“CustomerAgreement.docx”;documentid=“1”
--我的边界--
粘贴不起作用的完整代码;据我们所知,您的$data
是错误的。还有,服务返回的错误是什么?您是否尝试联系DocuSign的商业支持?您知道他们为客户提供支持,并为RESTAPI提供示例吗?(是的,我知道这对他的问题没有直接帮助,但他似乎在问一个拥有该产品并支持该产品的公司应该提供的问题)另一个轶事,你从哪里看到DocuSign支持DOCX?
POST https://demo.docusign.net/restapi/v2/accounts/ACCOUNT_NUMBER/envelopes HTTP/1.1
X-DocuSign-Authentication: {"Username":"USERNAME","Password":"PASSWORD","IntegratorKey":"INTEGRATOR_KEY"}
Content-Type: multipart/form-data; boundary=MY_BOUNDARY
Accept: application/json
Host: demo.docusign.net
Content-Length: 15384
--MY_BOUNDARY
Content-Type: application/json
Content-Disposition: form-data
{
"status" : "sent",
"emailBlurb":"Test Email Body",
"emailSubject": "-- Test Email Subject --",
"documents": [
{
"name": "CustomerAgreement.docx",
"documentId": 1
}],
"recipients": {
"signers" : [{
"email": "bobsemail@outlook.com",
"name": "Bob Adamson",
"recipientId": "1",
"routingOrder": "1",
"tabs": {
"signHereTabs": [
{
"recipientId": "1",
"tabLabel": "Customer_Signature",
"documentId": "1",
"pageNumber": "1",
"xPosition": "99",
"yPosition": "424"
}]
}
}]
}
}
--MY_BOUNDARY
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
Content-Disposition: file; filename="CustomerAgreement.docx"; documentid="1"
<document bytes removed>
--MY_BOUNDARY--