thinkstudeo/laravel-textlocal 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

thinkstudeo/laravel-textlocal

Composer 安装命令:

composer require thinkstudeo/laravel-textlocal

包简介

A Laravel wrapper for Textlocal API

README 文档

README

Latest Version on Packagist Software License Total Downloads

A convenience wrapper for the textlocal.in api requests for transactional as well as promotional accounts. The reseller account specific api are not available at this point in time.

Sms messaging can be used for transactional messages like:

  • Sending OTP for Two Factor Authentication
  • Confirmation of payment received or order placed etc

Transactional messages need to be sent through at any time without any DND (Do Not Disturb) restrictions. For this one needs to register a Transactional Account with Textlocal or request for conversion of the default account to a Transactional Account.

On the other hand Sms messaging may also be used for promotional activities like:

  • Announcing product launch or discount sale
  • Announcing an award receid=ved by the company or product
  • Sending coupon code etc

Promotional messages need to adhere to the DND (Do Not Disturb) restrictions. The default signup at Textlocal creates a Promotional Account by default.

Contents

Installation

$ composer require thinkstudeo/textlocal

Config

Package facilitates using Transactional as well as Promotional Account with Textlocal at the same time.

Add the following to your config/services.php file

'textlocal' => [
    'transactional' => [
		'apiKey' => env('TEXTLOCAL_TRANSACTIONAL_KEY')
    ],
    'promotional' => [
        'apiKey' => env('TEXTLOCAL_PROMOTIONAL_KEY')
    ]
]

Don't forget to add the keys to your .env file

If you have just one - i.e. Promotional Account or Transactional Account - make sure to enter the API key accordingly. For example, for just a Textlocal Promotional Account, declare TEXTLOCAL_PROMOTIONAL_KEY=api_key_for_your_promotional_account.

TEXTLOCAL_TRANSACTIONAL_KEY= <your textlocal transactional account api key here>
TEXTLOCAL_PROMOTIONAL_KEY= <your textlocal promotional account api key here>

Usage

There are two facades included with the package:

  • Sms for sending messages
  • Account for interacting with the Textlocal Account

For differentiating the api calls with respect to account type use transactional() or promotional() to set the account for the api call.

Messaging - Transactional Account

You must have a transactional account with Textlocal inorder to send transactional sms without DND restriction 24x7. Also don't forget to get your templates for the transactional messages approved by Textlocal. Finally, you must generate an API KEY from your Textlocal dashboard API KEY

Then you can use the facade like

To send to a single user

Sms::transactional()
    ->to('911234523451')
    ->from('SENDER')   //Your registered sender
    ->send('My message');  //as per your approved template

To send to multiple users at once

Sms::transactional()
    ->to('911234523451,919898456456')
    ->from('SENDER')   //Your registered sender
    ->send('My message');  //as per your approved template

OR, you can also provide the numbers as an array

Sms::transactional()
    ->to(['911234523451', '919898456456'])
    ->from('SENDER')   //Your registered sender
    ->send('My message');  //as per your approved template

And if you want to schedule a message to be sent at a specified time in future you can provide a datetime string in any of the formats supported by Carbon or you may also provide a unix timestamp.

$schedule = "2019-01-01 09:30:00"; 

Sms::transactional()
    ->to('911234523451,919898456456')
    ->at($schedule) 
    ->from('SENDER')   //Your registered sender
    ->send('My message');  //as per your approved template

To cancel a scheduled message

//Get a list of all the scheduled messages
$response = Account::transactional()->scheduledMessages();
$scheduledMessages = $response->scheduled;

//Identify the scheduled message you want to cancel
$msg = $scheduledMessages[0];

//Cancel the message
Account::transactional()->cancel($msg->id);

Messaging - Promotional Account

To send to a single user

Sms::promotional()
    ->to('911234523451')
    ->from('TXTLCL')   //or Your registered sender
    ->send('My message');  

To send to multiple users at once

Sms::promotional()
    ->to('911234523451,919898456456')
    ->from('TXTLCL')   //or Your registered sender
    ->send('My message');  

OR, you can also provide the numbers as an array

Sms::promotional()
    ->to(['911234523451', '919898456456'])
    ->from('TXTLCL')   //or Your registered sender
    ->send('My message');  

And if you want to schedule a message to be sent at a specified time in future you can provide a datetime string in any of the formats supported by Carbon or you may also provide a unix timestamp.

$schedule = "2019-01-01 09:30:00";

Sms::promotional()
    ->to('911234523451,919898456456')
    ->at($schedule) //unix timestamp
    ->from('TXTLCL')   //or Your registered sender
    ->send('My message');  //as per your approved template

To cancel a scheduled message

//Get a list of all the scheduled messages
$response = Account::promotional()->scheduledMessages();
$scheduledMessages = $response->scheduled;

//Identify the scheduled message you want to cancel
$msg = $scheduledMessages[0];

//Cancel the message
Account::promotional()->cancel($msg->id);

Message Status

To get the details of status of a message sent

//Capture the message id and or batch id when you send the message
$response = Sms::promotional()->to(['911234523451', '919898456456'])->from('TXTLCL')->send('My Message');
$msgId = $response->messages[1]->id;
$batchId = $response->batch_id;

//Get the status
Account::promotional()->messageStatus($msgId);
//Or
Account::promotional()->batchStatus($batchId);

Received Messages from Inbox

To retrieve the received messages from specific inbox

//Get a list of all inboxes in your account
$inboxList = Account::promotional()->inboxes();

//Identify the inbox you want to fetch the messages from, and get its id
$inboxId = $inboxList[0]->id;

//Fetch the messages from the inbox
$messages = Account::promotional()->messages($inboxId);

Templates in Account

To fetch all the templates associated with the account

$templates = Account::transactional()->templates();

Sender names

To fetch all the approved sender names from your account

$senders = Account::transactional()->senders();

Account Balance

To get the current account balance (credits remaining)

$balance = Account::promotional()->balance();

Check the availability of keyword

$availability = Account::promotional()->checkKeyword('KEYWRD');

Check if a Contact Group exists

$exists = Account::promotional()->groupExists('Customers')

Create a New Contact Group

$groupId = Account::promotional()->createGroup('Tech')->group->id;

Get a list of all Groups

$groupList = Account::promotional()->groups();

Delete a Contact Group

//Note the id of the group when you create a new one
$customersId = Account::promotional()->createGroup('Customers')->group->id;
//Or get a list of all groups
$groupList = Account::promotional()->groups();
//Get the id of the group you want to delete
$groupId = $groupList[0]->id;

//Delete the group
$status = Account::promotional()->deleteGroup($customerId);
//Or
$status = Account::promotional()->deleteGroup($groupId);
//Or just give the name of the group to the command
$status = Account::promotional()->deleteGroup('Customers');

List of all Members of a Contact Group

$groupId = '66455';
$members = Account::promotional()->members($groupId);

Add numbers to an existing contact group

$groupId = '66455';
$numbers = '919033100026,919879612326';
$response = Account::promotional()->addNumbers($numbers, $groupId);

Add Contacts to an existing group

$groupId = '66455';

$members = [
	['number' => '911234567894', 'first_name' => 'John', 'last_name' => 'Doe'],
	['number' => '913355667798', 'first_name' => 'Jane', 'last_name' => 'Mclane']
];

$response = Account::promotional()->addMembers($members);

Remove a contact from the group

$response = Account::promotional()->removeMember('913355667798', $groupId);

Get a list of all who have opted out

$response = Account::promotional()->optOuts();

History

//Single message histr=ory
$response = Account::promotional()->history('single');

//Group message history
$response = Account::promotional()->history('group');

//Api message history
$response = Account::promotional()->history('api');

Surveys

To fetch a list of all active surveys

$response = Account::promotional()->surveys();

To get the details of a specific survey

//Get a list of active surveys
$surveys = Account::promotional()->surveys();
//Identify the survey for which you want the details
$surveyId = $surveys->survey_ids[0]->id;
//Fetch the details
$response = Account::promotional()->surveyDetails($surveyId);

To get the results of a specific survey

//Get a list of active surveys
$surveys = Account::promotional()->surveys();
//Identify the survey for which you want the results
$surveyId = $surveys->survey_ids[0]->id;
//Fetch the results
$response = Account::promotional()->surveyResults($surveyId);

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

Please note that all test are integration tests meaning they will actually hit the textlocal api and consume the credits.

$ composer test

Security

If you discover any security related issues, please email neerav@thinkstudeo.com instead of using the issue tracker.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

thinkstudeo/laravel-textlocal 适用场景与选型建议

thinkstudeo/laravel-textlocal 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 59 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 04 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「textlocal」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 thinkstudeo/laravel-textlocal 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 thinkstudeo/laravel-textlocal 我们能提供哪些服务?
定制开发 / 二次开发

基于 thinkstudeo/laravel-textlocal 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 59
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-04-22