1

通过 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 表现得这样的原因。

提前致谢。

4

2 回答 2

2

看起来您正在使用旧版本的传真 API。您能否在此处查看开发人员指南中的 API:

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

于 2015-11-06T19:34:48.730 回答
0

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

以下是来自的一些 PHP 代码README.md

$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);
于 2016-02-29T09:58:23.333 回答