twizo/lib-api-php

Library to connect to Twizo to send SMS, Number Lookup or Verifications

0.13.0 2018-05-02 12:22 UTC

This package is auto-updated.

Last update: 2025-03-11 01:31:58 UTC


README

Twizo

Twizo PHP API

Connect to the Twizo API using PHP. This API includes functions to send verifications (2FA), SMS and Number Lookup.

Requirements

  • PHP >= 5.4
  • Composer

Get application secret and api host

To use the Twizo API client, the following things are required:

Installation

The easiest way to start using the the Twizo API is to require it with Composer.

$ composer require twizo/lib-api-php

Getting started

Use the auto loader to load all required classes. If you're using Composer, you can skip this step and use the composer auto loader.

require "autoload.php";

Initializing the Twizo Api using your api secret and api host

$twizo = Twizo\Api\Twizo::getInstance('43reFDSrewrfet425rtefdGDSGds54twegdsgHaFST2refwd', 'api-asia-01.twizo.com');
	

Create a new verification

$verification = $twizo->createVerification('610123456789');
$verification->send();

Verify token

try {
    $result = $twizo->getTokenResult($verification->getMessageId(), '12345');

    print 'Success' . PHP_EOL;
} catch (Verification\Exception $e) {
    print 'Failed: ' . $e->getMessage() . PHP_EOL;
} catch (Twizo\Api\Exception $e) {
    print 'Exception: ' . $e->getMessage() . PHP_EOL;
}

Send sms

$sms = $twizo->createSms('test message body', '610123456789', 'sender');
$sms->sendSimple();

Examples

In the examples directory you can find a collection of cli examples of how to use the api. When first running an example you will be asked for a host name and secret; this will be written to a config file.

License

The MIT License. Copyright (c) 2016-2017 Twizo

Support

Contact: www.twizo.comsupport@twizo.com