Coder Social home page Coder Social logo

smsdev-php's Introduction

smsdev-php

Build Status Code Coverage Scrutinizer Code Quality Latest version Downloads total License

Send and receive SMS using SmsDev.com.br

Installation

Require this package with Composer in the root directory of your project.

composer require enricodias/smsdev

Usage

Create a new instance with your API key:

$SmsDev = new \enricodias\SmsDev('API_KEY');

If the API key is not provided, the library will look for the environment variable SMSDEV_API_KEY

Set any date format to be used in all date methods:

$SmsDev->setDateFormat('Y-m-d H:i:s'); // default is 'U', timestamp

Sending an SMS message

$SmsDev->send(5511988881111, 'SMS Message'); // returns true if the API accepts the message

var_dump($SmsDev->getResult()); // Returns the raw API response.

The country code optional. The default is 55 (Brazil).

Phone number validation

If you have the package giggsey/libphonenumber-for-php installed, it will be used to validate numbers locally. You can disable this feature with the method setNumberValidation before sending:

$SmsDev->setNumberValidation(false); // disables phone number validation

Note that SmsDev will charge you for messages sent to invalid numbers.

Receiving SMS messages

Get unread messages in a specific date interval:

$SmsDev->setDateFormat('Y-m-d');

$SmsDev->setFilter()
            ->isUnread()
            ->dateBetween('2018-01-19', '2019-01-19')
        ->fetch();

Search for a specific message id:

$SmsDev->setFilter()
            ->byId(2515974)
        ->fetch();

Parsing the response

After fetching the messages you can either access the raw API response using getResult() or use the function parsedMessages() to get a simplified array:

$SmsDev->setDateFormat('U'); // timestamp

$messages = $SmsDev->parsedMessages();

var_dump($messages);

/*
array(1) {
    ['date']    => '1529418914'
    ['number']  => '5511988887777'
    ['message'] => 'Message'
}
*/

Dates are converted to the format specified in setDateFormat().

Date filters

The following filters are equivalent:

$SmsDev->setFilter()
            ->dateBetween('2018-01-19', '2019-01-19')
        ->fetch();

$SmsDev->setFilter()
            ->dateBetween('2018-01-19', '')
            ->dateTo('2019-01-19')
        ->fetch();

$SmsDev->setFilter()
            ->dateBetween('', '2019-01-19')
            ->dateFrom('2018-01-19')
        ->fetch();

$SmsDev->setFilter()
            ->dateFrom('2018-01-19')
            ->dateTo('2019-01-19')
        ->fetch();

Timezone problems

The API uses the timezone America/Sao_Paulo. Using another timezone in your application will force you to convert dates locally in order to get correct values.

Ex: if you are using UTC-4 and receive a new message, it will look like the message came from the future because America/Sao_Paulo is UTC-3.

This class solves this problem by automatically correcting dates both in search filters and in parsed messages. Only the dates in raw API responses are not converted.

TODO

  • Check the status of sent messages.
  • Send multiple SMS messages.

smsdev-php's People

Contributors

enricodias avatar wesleygoncalves avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

smsdev-php's Issues

Problema no Envio de URL

Ola.

Quando realizo envio de SMS contendo URL por algum motivo a api da smsdev faz um replace pelo texto "[LINK_CONTA_GRATIS]".
Poderiam avaliar esse bug?

Conta bloqueada no site

Tive minha conta bloqueada no site smsdev, poderia me dizer por qual motivo isso ocorreu? Tem algo a ver com a minha implementação?

Jobtime e jobdate

Boa tarde, será que seria possível implementar a possibilidade de enviar os parametros jobdate e jobtime?

Conflict Package

Problem 1
- Root composer.json requires enricodias/smsdev ^0.3.0 -> satisfiable by enricodias/smsdev[v0.3].
- enricodias/smsdev v0.3 requires guzzlehttp/guzzle ^6.4 -> found guzzlehttp/guzzle[6.4.0, ..., 6.5.x-dev] but it conflicts with your root composer.json require (^7.2).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.