我只是写信给你,因为我正在努力得到这段代码的工作。我可以根据需要从命令行调用api。一旦我尝试从php函数调用它转换为php可读的curl后,它似乎发送,但我只是得到一个空数组作为响应。这是相当令人困惑的,因为我得到有效的错误消息,从api之前的响应。我将列出php和html表单的代码。
<?php
$name = $_POST['testName'];
$email = $_POST['testEmail'];
$file = $_FILES['testFile'];
$url = $_POST['testURL'];
runSend($file, $name, $email);
function runSend($file, $name, $email){
echo "Success, message sent";
echo $file;
echo $name;
echo $email;
echo $url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.boldsign.com/v1/document/send');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$post = array(
'Title' => 'Commercial Agreement',
'Message' => 'Terms, purpose and duration of agreement ',
'UseTextTags' => 'true',
'EnableSigningOrder' => 'false',
'Signers[0][Name]' => 'Example Name',
'Signers[0][EmailAddress]' => 'example@example.com.au',
'Signers[0][SignerOrder]' => '0',
'Signers[0][FormFields][0][FieldType]' => 'Signature',
'Signers[0][FormFields][0][Name]' => 'sign_field',
'Signers[0][FormFields][0][PageNumber]' => '1',
'Signers[0][FormFields][0][Bounds][X]' => '50',
'Signers[0][FormFields][0][Bounds][Y]' => '50',
'Signers[0][FormFields][0][Bounds][Width]' => '200',
'Signers[0][FormFields][0][Bounds][Height]' => '30',
'Signers[0][FormFields][0][IsRequired]' => 'true',
'Files' => new CURLFILE($file)
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$headers = array();
$headers[] = 'X-Api-Key: EXAM76242$PLEA32PIK555EY';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
<form action="/wp-content/themes/hello-theme-child-master/send-test-file.php" method="post" enctype="multipart/form-data">
name:
<input type="text" id="testName" name="testName" value="[7401]"><br>
email
<input type="text" id="testEmail" name="testEmail" value="testEmail"><br>
Select pdf to upload:
<input type="file" name="testFile" id="testFile">
<input type="text" id="testURL" name="testURL" value="[e2pdf-download id="31" output='url']"><br>
<input type="submit" value="Send File" name="submit">
</form>
我已经试着重构代码很多次了,坦率地说,我被难住了。
---------------- 编辑/更新 -------------------------------------
你好,谢谢你。在你们的帮助下,我离目标越来越近了。下面是我当前的代码和我得到的错误。谁能再看一遍看看能不能想出什么可能的原因。再次感谢!
<?php
if ($_FILES['testFile']['error'] !== UPLOAD_ERR_OK) {
die("File upload failed with error code " . $_FILES['testFile']['error']);
}
//$name = $_POST['testName'];
//$email = $_POST['testEmail'];
//$url = $_POST['testURL'];
//fopen($_FILES["UploadFileName"]["tmp_name"], 'r');
$file = $_FILES['testFile'];
runSend($file);
/*
$location = "/uploads/test/"_.$_FILENAME['testFile']['name']_;
$tmp_file = $_FILES['testFile']['tmp_name'];
move_uploaded_file($tmp_file, $location);
*/
function runSend($file){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.boldsign.com/v1/document/send');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$post = array(
'DisableExpiryAlert' => 'false',
'ReminderSettings.ReminderDays' => '5',
'BrandId' => '',
'ReminderSettings.ReminderCount' => '3',
'EnableReassign' => 'false',
'Message' => '',
'Signers[0][Name]' => 'Enter Name',
'Signers[0][EmailAddress]' => 'example@example.com.au',
'Signers[0][SignerOrder]' => '0',
'Signers[0][FormFields][0][FieldType]' => 'Signature',
'Signers[0][FormFields][0][Name]' => 'sign_field',
'Signers[0][FormFields][0][PageNumber]' => '1',
'Signers[0][FormFields][0][Bounds][X]' => '50',
'Signers[0][FormFields][0][Bounds][Y]' => '50',
'Signers[0][FormFields][0][Bounds][Width]' => '200',
'Signers[0][FormFields][0][Bounds][Height]' => '30',
'Signers[0][FormFields][0][IsRequired]' => 'true',
'ExpiryDays' => '30',
'EnablePrintAndSign' => 'false',
'AutoDetectFields' => 'false',
'OnBehalfOf' => '',
'EnableSigningOrder' => 'false',
'UseTextTags' => 'true',
'SendLinkValidTill' => '',
'Files' => new CURLFILE($file['tmp_name'].'.pdf'),
'Title' => 'testing',
'HideDocumentId' => 'false',
'EnableEmbeddedSigning' => 'false',
'ExpiryDateType' => 'Days',
'ReminderSettings.EnableAutoReminder' => 'true',
'ExpiryValue' => '60',
'DisableEmails' => 'false'
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$headers = array();
$headers[] = 'Accept: application/json';
$headers[] = 'X-API-Key: GWAGsagsgaEAWT2545q3AF';
$headers[] = 'Content-Type: multipart/form-data';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
echo $result;
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo $httpcode;
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
};
?>
我目前得到的错误信息:0错误:无法打开文件"/tmp/phpWQLlLP.pdf">
不清楚预期的最终结果是什么,但是一旦为curl请求提供了适当的参数来处理api的SSL端点,下面的操作似乎就可以正常工作了。在本例中,这将打印出example.com页面
<?php
function runSend( $url, $file, $name, $email ){
/*
Download a valid cacert.pem from
https://curl.haxx.se/docs/caextract.html
and edit the path below to suit your setup.
*/
$cacert='c:/wwwroot/cacert.pem';
$ch = curl_init();
/*
supply the various SSL details
*/
if( parse_url( $url, PHP_URL_SCHEME )=='https' ){
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 2 );
curl_setopt( $ch, CURLOPT_CAINFO, $cacert );
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$post = array(
'Title' => 'Commercial Agreement',
'Message' => 'Terms, purpose and duration of agreement ',
'UseTextTags' => 'true',
'EnableSigningOrder' => 'false',
'Signers[0][Name]' => 'Example Name',
'Signers[0][EmailAddress]' => 'example@example.com.au',
'Signers[0][SignerOrder]' => '0',
'Signers[0][FormFields][0][FieldType]' => 'Signature',
'Signers[0][FormFields][0][Name]' => 'sign_field',
'Signers[0][FormFields][0][PageNumber]' => '1',
'Signers[0][FormFields][0][Bounds][X]' => '50',
'Signers[0][FormFields][0][Bounds][Y]' => '50',
'Signers[0][FormFields][0][Bounds][Width]' => '200',
'Signers[0][FormFields][0][Bounds][Height]' => '30',
'Signers[0][FormFields][0][IsRequired]' => 'true',
'Files' => new CURLFILE( $file )
);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $post );
$headers = array();
$headers[] = 'X-Api-Key: EXAM76242$PLEA32PIK555EY';
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
$result = curl_exec( $ch );
if( curl_errno( $ch ) ) echo 'Error:' . curl_error( $ch );
curl_close( $ch );
return $result;
}
# emulate POST array
$_POST=array(
'testName' => 'Griselda Grizzleguts',
'testEmail' => 'gg@gmail.com',
'testURL' => 'https://example.com'
);
# configure curl request parameters
$url='https://api.boldsign.com/v1/document/send';
$name = $_POST['testName'];
$email = $_POST['testEmail'];
$url = $_POST['testURL'];
$file='c:tempssldebug.txt';
# make the request & print result
$result=runSend( $url, $file, $name, $email );
if( $result ){
printf('<pre>%s</pre>',print_r($result,true));
}
?>