msogl/sfax
Sfax 的 PHP API
v1.0.2
2024-07-12 16:13 UTC
Requires
- php: >=7.3
This package is not auto-updated.
Last update: 2024-09-21 15:12:32 UTC
README
PHP API 用于通过 Sfax 发送传真。
基于 https://sfax.scrypt.com/category/1309-getting-started 上的文档。
该处的 PHP 代码示例已过时,并使用 PHP 中的旧 mcrypt 库。此版本使用 OpenSSL。
安装
composer require msogl/sfax
配置
此脚本使用一个 $config 数组,如下所示
$config = [
'SFAX_USERNAME' => 'your sfax username',
'SFAX_APIKEY' => 'your sfax api key'',
'SFAX_ENCKEY' => 'your sfax encryption key',
'SFAX_IV' => 'your sfax init vector',
'SFAX_CLIENT' => 'your sfax client',
];
您可以根据需要构建 $config 数组。
注意:SFAX_CLIENT 是可选的。您可以省略它,也可以保留它,但留空。
发送传真
// $fromFaxNumber should either be specified, or, if using the default fax number
// associated with the user account for the API, set it to the literal
// string, "DEFAULT".
$fromFaxNumber = 'DEFAULT';
// Fax number including area code. The API assumes as U.S. number, so will auto-add
// the country code of "1". The API will auto-format the number to all numbes, so
// you can leave dashes in, if you want.
$recipientFaxNumber = '555-555-5555';
// A recipient name is required. You may use free-text. If you don't have a name,
// just put the fax number in here as well.
$recipientFaxName = 'Some Company Name';
$sfax = new SfaxApi($config);
$resp = $sfax->sendFax($fromFaxNumber, $recipientFaxNumber, $recipientFaxName, $faxFilePath);
if ($resp === false) {
echo $sfax->lastError . "\n";
} else {
var_dump($resp);
}
测试模式
您可以将 API 设置为测试模式。这样做将允许您在不实际调用 Sfax 的 API 的情况下调用我们的 API 代码。相反,它将在 $lastError 字段中返回 API 的组合 URL 并在调用 Sfax 的 API 之前返回 false。
$sfax = new SfaxApi($config);
$sfax->testMode();
$resp = $sfax->sendFax($fromFaxNumber, $recipientFaxNumber, $recipientFaxName, $faxFilePath);
if ($resp === false) {
echo $sfax->lastError . "\n";
} else {
var_dump($resp);
}
使用命名封面页
Sfax 支持通过其系统定义的模板封面页包含封面页。
遗憾的是,它不支持单独发送其模板封面页。仍然需要发送一个 PDF 文件。
封面页的名称默认为 "None"。如果名称与 "None" 不同(不区分大小写),则将发送封面页。只使用已填充的参数。此处的逻辑不多,因此请小心使用数组参数名称。
$sfax = new \Msogl\Sfax\SfaxApi($config);
$sfax->setCoverPage([
'name' => 'Sfax traditional cover page',
'subject' => 'Testing only',
'reference' => 'Ref # here',
'remarks' => 'This is just a test. Please ignore.',
'fromname' => 'Your name nere',
'fromphone' => 'Your phone nere',
'timezone' => 'see the API specifications',
]);
$resp = $sfax->sendFax($fromFaxNumber, $recipientFaxNumber, $recipientFaxName, $pdfFile);
获取使用报告
$startDate 可以为 null 或特定日期。如果为 null,则将自动设置为当前日期前 30 天。$endDate 可以为 null 或特定日期。如果为 null,则将是当前日期。
// Get usage report for last 30 days
$sfax = new SfaxApi($config);
$resp = $sfax->usageReport(null, null);