正确形成使用RingCentral API发送的传真的HTML内容

时间:2015-11-06 06:36:39

标签: php html zend-framework fax ringcentral

通过RingCentral API为传真发送的HTML内容未按正确顺序格式化。

我使用的代码:

    // The HTML content to be sent
    $html = "<h3>Notification</h3><div>Lorem epsum Lorem epsum Lorem epsum Lorem epsum <b>My Site</b>Lorem epsum Lorem epsum</div><div><br></div><div>Lorem epsumLorem epsumLorem epsum<i><b>Lorem epsumLorem epsumLorem epsum</b></i>.</div><div><br></div><div>To view more and print more details,&nbsp;please log in to&nbsp;<a href='http://www.demo.mysite.com' target='_blank'>www.demo.mysite.com</a>&nbsp;using your email address.</div><div><br></div><div>Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum</div>";

    // Creating a file
    $fileRand = rand();
    $filename = 'faxfile_'.$fileRand.'.html';

    // Open the file in write mode
    $faxFile = fopen('ringfax/'.$filename, 'w');

    // Write the contents to the html file.
    fwrite($faxFile, $html);

    // Close the file.
    fclose($faxFile);

    // Setting up data for the RingCentral API
    $faxData['Username']  = "XXXXXXXXXX";
    $faxData['Password']  = "XXXXXXXXXX";
    $faxData['Recipient'] = "XXXXXXXXXX";   
    $faxData['Sendtime']  = gmdate('d:m:y h:m');
    $faxData['Coverpage'] = 0;
    $faxData['Attachment'] = '@'.realpath('ringfax/'.$filename).';filename='.$filename.';content-type=text/html';

    // Open connection
    $ch = curl_init();

    // Set the url, number of POST vars and other data
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_URL, 'https://service.ringcentral.com/faxapi.asp?');
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: text/html", "charset: UTF-8"));
    curl_setopt($ch, CURLOPT_POST, count($faxData));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $faxData);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // Execute post
    $result = curl_exec($ch);

    // Receives curl error
    $cErr = curl_error($ch);
    // curl curl info
    $cInfo = curl_getinfo($ch); 

    // Write the error to the log file
    ini_set("log_errors", 1);
    ini_set("error_log", "logs/ring_central_error");
    error_log($result);

    //close connection
    curl_close($ch);

    // Delete the file
    unlink('ringfax/'.$filename);

传真正在发送,但传真中的内容未按照我们希望的格式进行格式化。 传真中的内容如下所示:

Notification Lorem epsum Lorem epsum Lorem epsum Lorem epsum&Acirc;&nbsp;My Site&Acirc;&nbsp;Lorem epsum Lorem epsumLorem epsumLorem epsumLorem epsum Lorem epsumLorem epsumLorem epsum To view more and print more details, please log in to&Acirc;&nbsp;www.demo.mysite.com&Acirc;&nbsp;using your email address.Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum.

我很确定它必须是标题类型或者没有正确设置的东西,这就是RingCentral API的行为如此。

提前致谢。

2 个答案:

答案 0 :(得分:2)

您好像使用旧版传真API。您可以在开发者指南中查看API:

https://developer.ringcentral.com/api-docs/latest/index.html#!#FaxMessages.html

答案 1 :(得分:0)

您还可以将RingCentral PHP SDK用于新API,它将创建格式正确的请求:

这里有README.md的一些PHP代码:

$request = $rcsdk->createMultipartBuilder()
                 ->setBody(array(
                     'to' => array(
                         array('phoneNumber' => '16501112233'),
                     ),
                     'faxResolution' => 'High',
                 ))
                 ->add('Plain Text', 'file.txt')
                 ->add(fopen('path/to/file', 'r'))
                 ->request('/account/~/extension/~/fax'); // also has optional $method argument

$response = $platform->sendRequest($request);