带宽/虹膜

Bandwidth的PHP Iris SDK

v4.3.1 2024-08-19 13:24 UTC

README

Build Status

支持的PHP版本

安装

运行

composer require bandwidth/iris

使用

$client = new \Iris\Client($login, $password, ['url' => 'https://dashboard.bandwidth.com/api/']);

运行测试

composer install
php ./bin/phpunit --bootstrap ./vendor/autoload.php tests/

=======

示例

源代码树中有一个“examples”文件夹,其中包含如何使用简单示例代码与每个API对象一起工作的示例。要运行示例

$ cd examples
$ composer install
$ cp config.php.example config.php

编辑config.php以匹配您的IRIS凭据,然后单独运行示例。例如。

php availableNumbers-sample.php

如果示例接受命令行参数,您可以通过执行单个脚本来获取用法。

API对象

基本原则

在大多数情况下,您应该以Account对象作为起点。

$account = new \Iris\Account($your_account_id, $client);

Account有关联实体,如订单、站点等。

示例

$sites = $account->sites();

要获取存储的站点,您应该创建$sites对象并执行get()方法。

$items = $sites->getList(); // Array(Site1, Site2)

反映对象结构

echo json_encode($site->to_array());

可用号码

$account->availableNumbers([ "areaCode" => "818" ]);

可用NpaNxx

$account->availableNpaNxx(["state" => "CA"]);

城市

$cities = new \Iris\Cities($client);
$items = $cities->getList(["state" => "NC"]);

覆盖的费率中心

$rcs = new Iris\CoveredRateCenters($client);
$rateCenters = $rcs->getList(["page" => 1, "size" => 10 ]);

断开号码

$account->disnumbers(["areaCode" => "919"]);

断开号码

断开对象用于从账户断开号码。创建可以跟踪的断开订单

创建断开

$disconnect = $account->disconnects()->create([
    "name" => "test disconnect order 4",
    "CustomerOrderId" => "Disconnect1234",
    "DisconnectTelephoneNumberOrderType" => [
        "TelephoneNumberList" => [
            "TelephoneNumber" => [ "9192755378", "9192755703" ]
        ]
    ]
]);

获取断开

$disconnect = $account->disconnects()->disconnect("b902dee1-0585-4258-becd-5c7e51ccf5e1", true); // tnDetails: true

向断开添加注释

$disconnect->notes()->create([ "UserId" => "byo_dev", "Description" => "Test Note"]);

获取断开注释

$items = $disconnect->notes()->getList();

Dlda

创建Ddla

$order_data = [
    "CustomerOrderId" => "123",
    "DldaTnGroups" => [
        "DldaTnGroup" => [
            [
                "TelephoneNumbers" => [
                    "TelephoneNumber" => "4352154856"
                ],
                "AccountType" => "RESIDENTIAL",
                "ListingType" => "LISTED",
                "ListAddress" => "true",
                "ListingName" => [
                    "FirstName" => "FirstName",
                    "FirstName2" => "FirstName2",
                    "LastName" => "LastName",
                    "Designation" => "Designation",
                    "TitleOfLineage" => "TitleOfLineage",
                    "TitleOfAddress" => "TitleOfAddress",
                    "TitleOfAddress2" => "TitleOfAddress2",
                    "TitleOfLineageName2" => "TitleOfLineageName2",
                    "TitleOfAddressName2" => "TitleOfAddressName2",
                    "TitleOfAddress2Name2" => "TitleOfAddress2Name2",
                    "PlaceListingAs" => "PlaceListingAs",
                ],
                "Address" => [
                    "HousePrefix" => "HousePrefix",
                    "HouseNumber" => "915",
                    "HouseSuffix" => "HouseSuffix",
                    "PreDirectional" => "PreDirectional",
                    "StreetName" => "StreetName",
                    "StreetSuffix" => "StreetSuffix",
                    "PostDirectional" => "PostDirectional",
                    "AddressLine2" => "AddressLine2",
                    "City" => "City",
                    "StateCode" => "StateCode",
                    "Zip" => "Zip",
                    "PlusFour" => "PlusFour",
                    "Country" => "Country",
                    "AddressType" => "AddressType"
                ]
            ]
        ]
    ]
];

$dlda = $account->dldas()->create($order_data);

获取Dlda

$dlda = $account->dldas()->dlda("7802373f-4f52-4387-bdd1-c5b74833d6e2");

获取Dlda历史记录

$dlda->history();

列出Dldas

$account->dldas()->getList(["telephoneNumber" => "9195551212"]);

在服务号码

列出在服务号码

$account->inserviceNumbers(["areaCode" => "919"]);

Lidb

创建

$order_data = [
    "LidbTnGroups" => [
        "LidbTnGroup" => [
            [
                "TelephoneNumbers" => [
                    "TelephoneNumber" => "4352154856"
                ],
                "SubscriberInformation" => "Steve",
                "UseType" => "RESIDENTIAL",
                "Visibility" => "PUBLIC"
            ],
            [
                "TelephoneNumbers" => [
                    "TelephoneNumber" => "4352154855"
                ],
                "SubscriberInformation" => "Steve",
                "UseType" => "RESIDENTIAL",
                "Visibility" => "PUBLIC"
            ]
        ]
    ]
];

$lidb = $account->lidbs()->create($order_data);

获取Lidb

$lidb = $account->lidbs()->lidb("7802373f-4f52-4387-bdd1-c5b74833d6e2");

列出Lidbs

$lidbs = $account->lidbs()->getList(["lastModifiedAfter" => "mm-dd-yy", "telephoneNumber"=> "888"]);

LNP检查器

检查LNP

$account->lnpChecker(["4109255199", "9196190594"], "true");

订单

创建订单

$order = $account->orders()->create([
    "Name" => "Available Telephone Number order",
    "SiteId" => "2297",
    "CustomerOrderId" => "123456789",
    "ExistingTelephoneNumberOrderType" => [
        "TelephoneNumberList" => [
            "TelephoneNumber" => [ "9193752369", "9193752720", "9193752648"]
        ]
    ]
]);

获取订单

$response = $account->orders()->order("f30a31a1-1de4-4939-b094-4521bbe5c8df", true); // tndetail=true
$order = $response->Order;

列出订单

$items = $account->orders()->getList();

向订单添加注释

$order->notes()->create([ "UserId" => "byo_dev", "Description" => "Test Note"]);

获取订单的所有Tns

$order->tns()->getList();

端口入

创建端口入

$portin = $account->portins()->create(array(
    "BillingTelephoneNumber" => "6882015002",
    "Subscriber" => array(
        "SubscriberType" => "BUSINESS",
        "BusinessName" => "Acme Corporation",
        "ServiceAddress" => array(
            "HouseNumber" => "1623",
            "StreetName" => "Brockton Ave",
            "City" => "Los Angeles",
            "StateCode" => "CA",
            "Zip" => "90025",
            "Country" => "USA"
        )
    ),
    "LoaAuthorizingPerson" => "John Doe",
    "ListOfPhoneNumbers" => array(
        "PhoneNumber" => array("9882015025", "9882015026")
    ),
    "SiteId" => "365",
    "Triggered" => "false"
));

获取端口入

$portin = $account->portins()->portin("d28b36f7-fa96-49eb-9556-a40fca49f7c6"));

列出端口入

$portins = $account->portins()->getList(["pon" => "a pon" ]);

端口入实例方法

$portin->update();
$portin->delete();
$portin->get_activation_status();
$status = $portin->set_activation_status([
    "AutoActivationDate" => "2014-08-30T18:30:00+03:00"
]);
$portin->history();
$portin->totals();
$portin->notes()->getList();

端口入文件管理

$portin->list_loas(true); // metadata = true
$portin->loas_send("./1.txt");
$portin->loas_update("./1.txt", "1.txt");
$portin->loas_delete("1.txt");
$portin->get_metadata("1.txt");
$meta_new = array(
    "DocumentName" => "text.txt",
    "DocumentType" => "INVOICE"
);
$portin->set_metadata('test.txt', $meta_new);
$portin->delete_metadata('test.txt');

端口入文件管理:获取文件名

$response = $portin->loas_send('./hello.txt', array("Content-Type" => "text/plain"));
$tmp = explode("/", $response);
$id = end($tmp);
print_r($id);

费率中心

列出费率中心

$rc = new \Iris\RateCenter($client);
$cities = $rc->getList(["state" => "CA", "available" => "true"]);

SIP对等方

创建SIP对等方

$sippeer = $account->sippeers()->create(array(
        "PeerName" => "Test5 Peer",
        "IsDefaultPeer" => false,
        "ShortMessagingProtocol" => "SMPP",
        "VoiceHosts" => array(
            "Host" => array(
                "HostName" => "192.168.181.90"
            )
        ),
        "SmsHosts" => array(
            "Host" => array(
                "HostName" => "192.168.181.90"
            )
        ),
        "TerminationHosts" => array(
            "TerminationHost" => array(
                "HostName" => "192.168.181.90",
                "Port" => 0,
                "CustomerTrafficAllowed" => "DOMESTIC",
                "DataAllowed" => true
            )
        )
));

获取SIP对等方

$sippeer = $account->sippeers->sippeer("500651");

列出SIP对等方

$sippeers = $account->sippeers()->getList();

删除SIP对等方

$sippeer->delete();

移动TNs

$sippeer->movetns([ "FullNumber" => [ "9192000046", "9192000047", "9192000048" ]]);

获取TNs

$tns = $sippeer->tns()->getList();

获取TN

$tn = $sippeer->tns()->tn("8183386251");

总TN数

$count = $sippeer->totaltns();

设置TN选项

$sippeer->tns()->tn("8183386251")->set_tn_options([
    "FullNumber" => "8183386251",
    "CallForward" => "9194394706",
    "RewriteUser" => "JohnDoe",
    "NumberFormat" => "10digit",
    "RPIDFormat" => "e164"
]);

站点

创建站点

$site = $account->sites()->create(
    array("Name" => "Test Site",
        "Address" => array(
            "City" => "Raleigh",
            "AddressType" => "Service",
            "HouseNumber" => "1",
            "StreetName" => "Avenue",
            "StateCode" => "NC"
    )));

更新站点

$site->Name = "New Name";
$site->update();

删除站点

$site->delete();

列出所有站点

$sites = $account->sites()->getList();

站点的订单

$site->orders()->getList(["status" => "disabled"]);

站点的总TN数

$site->totaltns();

站点的端口入

$site->portins()->getList(["status" => "disabled" ]);

Sippeers

$site->sippeers()->create([...])

[见SIP对等方]

订阅

创建订阅

$subscription = $account->subscriptions()->create([
    "OrderType" => "portins",
    "OrderId" => "98939562-90b0-40e9-8335-5526432d9741",
    "EmailSubscription" => [
        "Email" => "test@test.com",
        "DigestRequested" => "DAILY"
    ]
]);

获取订阅

$subscription = $account->subscriptions()->subscription($id);

列出订阅

$account->subscriptions()->getList(["orderType" => "portins"]);

更新

$subscription->OrderType = "portins";
$subscription->update();

DELETE

$subscription->delete();

TNs

获取TN

$tns = new Iris\Tns(null, $client);
$tn = $tns->tn($id);

列出TNs

$tns = new Iris\Tns(null, $client);
$tns_items = $tns->getList(["page" => 1, "size" => 10 ]);

TN实例方法

$tn = $tns->tn("7576768750");
$site = $tn->site();
$sippeer = $tn->sippeer();
$tnreservation = $tn->tnreservation();
$tn->tndetails();
$rc = $tn->ratecenter();
$lata = $tn->lata();
$lca = $tn->lca();

TN预订

创建TN预订

$resertation = $account->tnsreservations()->create(["ReservedTn" => "2512027430"]);

获取TN预订

$resertation = $account->tnsreservations()->tnsreservation("0099ff73-da96-4303-8a0a-00ff316c07aa");

删除TN预订

$resertation = $account->tnsreservations()->tnsreservation("0099ff73-da96-4303-8a0a-00ff316c07aa");
$resertation->delete();

账单报告

列出所有账单报告实例

$billingReports = $account->billingreports()->getList();

请求新的账单报告

$billingReport = $account->billingreports()->request(
    array("Type" => "bdr",
        "DateRange" => array(
            "StartDate" => "2018-02-05",
            "EndDate" => "2018-02-06",
    )));

检查账单报告的状态

$billingReport = $account->billingreports()->billingreport('a12b456c8-abcd-1a3b-a1b2-0a2b4c6d8e0f2');

下载包含账单报告内容的zip文件

$zipStream = $billingReport->file();

下载包含账单报告内容的zip文件并保存到文件

$outFile = '/tmp/report.zip';
$billingReport->file(['stream' => true, 'sink' => $outFile]);

TN选项

获取TN选项订单

$tnoptions = $account->tnoptions();
$response = $tnoptions->getList();
print_r($response[0]->OrderId);

GET TN选项订单

$tnoptions = $account->tnoptions();
$response = $tnoptions->tnoption("order_id");
print_r($response->OrderCreateDate);

获取TN选项订单(错误)

$tnoptions = $account->tnoptions();
$response = $tnoptions->tnoption("error_order_id");
print_r($response->ErrorList->Error->Description); //note: Error could be an array or a single object
//depending on how many errors are returned

创建端口出密码

$tnoptions = $account->tnoptions();
$data = array(
    "TnOptionGroups" => array(
        "TnOptionGroup" => array(
            "PortOutPasscode" => "12abd38",
            "TelephoneNumbers" => array(
                "TelephoneNumber" => "2018551020"
            )
        ),
    )
);
$response = $tnoptions->create($data);
print_r($response->OrderCreateDate);

创建呼叫前转号码

$tnoptions = $account->tnoptions();
$data = array(
    "TnOptionGroups" => array(
        "TnOptionGroup" => array(
            "CallForward" => "2018551022",
            "TelephoneNumbers" => array(
                "TelephoneNumber" => "2018551020"
            )
        ),
    )
);
$response = $tnoptions->create($data);
print_r($response->OrderCreateDate);

启用短信

$tnoptions = $account->tnoptions();
$data = array(
    "TnOptionGroups" => array(
        "TnOptionGroup" => array(
            "Sms" => "on",
            "TelephoneNumbers" => array(
                "TelephoneNumber" => "2018551020"
            )
        ),
    )
);
$response = $tnoptions->create($data);
print_r($response->OrderCreateDate);

托管消息功能

获取导入TN订单

$resp = $account->getImportTnOrders(array(
    "createdDateFrom" => "2013-10-22T00:00:00.000Z",
    "createdDateTo" => "2013-10-25T00:00:00.000Z"
));

print_r($resp->ImportTnOrderSummary[0]->OrderId);

创建导入TN订单

$importTnOrder = new \Iris\ImportTnOrder(array(
    "CustomerOrderId" => "id",
    "TelephoneNumbers" => array(
        "TelephoneNumber" => array("5554443333")
    ),
    "SiteId" => "12345",
    "Subscriber" => array(
        "Name" => "Company INC",
        "ServiceAddress" => array(
            "HouseNumber" => "1",
            "StreetName" => "Street",
            "City" => "City",
            "StateCode" => "XY",
            "Zip" => "54345",
            "County" => "County"
        )
    ),
    "LoaAuthorizingPerson" => "Test Person"
));

print_r($account->createImportTnOrder($importTnOrder)->ImportTnOrder->OrderId);

按ID获取导入TN订单

print_r($account->getImportTnOrder("some_id_value")->ProcessingStatus);

获取导入TN订单历史记录

print_r($account->getImportTnOrderHistory("some_id_value")->OrderHistory[0]->Status);

获取导入TN订单LOAs

$response = $account->getImportTnOrderLoas("order_id");
print_r($response->resultMessage);
echo "\n";
print_r($response->fileNames); //this can be a single string (if there's 1 file) or an array of strings (if there's multiple files)

为导入TN订单上传LOA文件

有效的 mime_types 可以在 仪表板 API 参考 中找到,在 /accounts/{accountId}/importTnOrders/{orderid}/loas 下。

MIME 类型预期格式为 x/y,例如 application/pdftext/plain

$account->uploadImportTnOrderLoaFile("order_id", "binary_file_contents", "mime_type");
$filename = "loa.pdf";
$file = fopen($filename, "rb") or die("Unable to open file");
$file_contents = fread($file, filesize($filename));
$account->uploadImportTnOrderLoaFile("order_id", $file_contents, "application/pdf");
fclose($file);

下载导入 TN 订单的 LOA 文件(bonked. 回到此处)

注意:请确保从 $account->getImportTnOrderLoas($order_id) 的响应中获取所需的文件 ID,位于 $response->fileNames 字段中

$response = $account->downloadImportTnOrderLoaFile("order_id", "file_id");
$file = fopen("write.pdf", "wb") or die("Unable to open file");
fwrite($file, $response);
fclose($file);

替换导入 TN 订单的 LOA 文件

$account->replaceImportTnOrderLoaFile("order_id", "file_id", "binary_file_contents", "mime_type");

删除导入 TN 订单的 LOA 文件

$account->deleteImportTnOrderLoaFile("order_id", "file_id");

获取导入 TN 订单的 LOA 文件元数据

$response = $account->getImportTnOrderLoaFileMetadata("order_id", "file_id");
print_r($response->DocumentName);
echo "\n";
print_r($response->DocumentType);

更新导入 TN 订单的 LOA 文件元数据

$file_metadata = new \Iris\FileMetaData(array(
    "DocumentName" => "Updated",
    "DocumentType" => "LOA"
));
$account->updateImportTnOrderLoaFileMetadata("order_id", "file_id", $file_metadata);

删除导入 TN 订单的 LOA 文件元数据

$account->deleteImportTnOrderLoaFileMetadata("order_id", "file_id");

检查 TN 可移植性

print_r($account->checkTnsPortability(array("5554443333", "5553334444"))->ImportTnCheckerPayload);

获取在网号码

print_r($account->getInserviceNumbers(array("areacode" => "919"))->TelephoneNumbers->Count);

检查在网号码

print_r($account->checkInserviceNumber("5554443333"));

获取移除导入的 TN 订单

$resp = $account->getRemoveImportedTnOrders(array(
    "createdDateFrom" => "2013-10-22T00:00:00.000Z",
    "createdDateTo" => "2013-10-25T00:00:00.000Z"
));

print_r($resp->RemoveImportedTnOrderSummary[0]->OrderStatus);

创建移除导入的 TN 订单

$removeImportedTnOrder = new \Iris\RemoveImportedTnOrder(array(
    "CustomerOrderId" => "custom string",
    "TelephoneNumbers" => array(
        "TelephoneNumber" => array("5554443333", "5553332222")
    )
));

print_r($account->createRemoveImportedTnOrder($removeImportedTnOrder)->Location);

获取移除导入的 TN 订单

print_r($account->getRemoveImportedTnOrder("some_id_value")->ProcessingStatus);

获取移除导入的 TN 订单历史记录

print_r($account->getRemoveImportedTnOrderHistory("some_id_value")->OrderHistory[0]->Status);

CSR

创建 CSR 订单

$csrOrder = new \Iris\Csr(array(
    "CustomerOrderId" => "order id",
    "WorkingOrBillingTelephoneNumber" => "5554443333"
));

$response = $account->createCsrOrder($csrOrder);
print_r($response->OrderId);

替换 CSR 订单

$csrOrder = new \Iris\Csr(array(
    "CustomerOrderId" => "order id",
    "WorkingOrBillingTelephoneNumber" => "5554443333"
));

$response = $account->replaceCsrOrder("order_id", $csrOrder);
print_r($response->OrderId);

获取 CSR 订单

$response = $account->getCsrOrder("order_id");
print_r($response->OrderId);

获取 CSR 订单备注

$response = $account->getCsrOrderNotes("order_id");
print_r($response->Note[0]->Description);

添加 CSR 订单备注

$note = new \Iris\CsrNote(array(
    "UserId" => "id",
    "Description" => "description"
));

$account->addNoteToCsr("order_id", $note);

更新 CSR 订单备注

$note = new \Iris\CsrNote(array(
    "UserId" => "id",
    "Description" => "description"
));

$account->updateCsrOrderNote("order_id", "note_id", $note);

紧急通知接收者

创建紧急通知接收者

$data = array(
  "Description" => "Email to Bldg. 3 Front Desk",
  "Type" => "EMAIL",
  "EmailAddress" => "foo@bar.com"
);
$response = $account->createEmergencyNotificationRecipient($data);

获取紧急通知接收者

$response = $account->getEmergencyNotificationRecipients();

获取紧急通知接收者

$response = $account->getEmergencyNotificationRecipient("id");

替换紧急通知接收者

$data = array(
  "Description" => "Email to Bldg. 3 Front Desk",
  "Type" => "EMAIL",
  "EmailAddress" => "foo@bar.com"
);
$response = $account->replaceEmergencyNotificationRecipient("id", $data);

删除紧急通知接收者

$account->deleteEmergencyNotificationRecipient("id");

紧急通知组

创建紧急通知组订单

$data = array(
  "CustomerOrderId" => "value",
  "AddedEmergenyNotificationGroup" => array(
    "EmergencyNotificationRecipient" => array(
      "Identifier" => "123"
    )
  )
);
$response = $account->createEmergencyNotificationGroupOrder($data);

获取紧急通知组订单

$response = $account->getEmergencyNotificationGroupOrders();

获取紧急通知组订单

$response = $account->getEmergencyNotificationGroupOrder("id");

获取紧急通知组

$response = $account->getEmergencyNotificationGroups();

获取紧急通知组

$response = $account->getEmergencyNotificationGroup("id");

紧急通知端点

创建紧急通知端点订单

$data = array(
  "CustomerOrderId" => "123",
  "EmergencyNotificationEndpointAssociations" => array(
    "EmergenyNotificationGroup" => array(
      "Identifier" => "456"
    )
  )
);
$response = $account->createEmergencyNotificationEndpointOrder($data);

获取紧急通知端点订单

$response = $account->getEmergencyNotificationEndpointOrders();

获取紧急通知端点订单

$response = $account->getEmergencyNotificationEndpointOrder("id");

替代终端用户标识

获取替代终端用户信息

$response = $account->getAlternateEndUserInformation();

获取替代呼叫者信息

$response = $account->getAlternateCallerInformation("id");

应用程序管理

获取应用程序

$response = $account->getApplications();
print_r($response);

获取应用程序

$response = $account->getApplication("id");
print_r($response);

创建应用程序

$data = array(
    'ServiceType' => 'Messaging-V2',
    'AppName' => 'sample',
    'MsgCallbackUrl' => 'https://test.com'
);
$response = $account->createApplication($data);
print_r($response);

更新应用程序

$data = array(
    'ServiceType' => 'Messaging-V2',
    'AppName' => 'sample',
    'MsgCallbackUrl' => 'https://test2.com'
);
$response = $account->updateApplication("id", $data);
print_r($response);

删除应用程序

$account->deleteApplication("id");

获取应用程序 SipPeers

$response = $account->getApplicationSippeers("id");
print_r($response);