creativecrafts/laravel-twillio-sms
Composer 安装命令:
composer require creativecrafts/laravel-twillio-sms
包简介
A simple package to send sms messages using twillio
README 文档
README
Laravel Twilio SMS
Laravel Twilio SMS is a simple, elegant package for sending SMS messages using the Twilio API within your Laravel applications. This package allows you to validate phone numbers and send SMS messages effortlessly.
Table of Contents
Requirements
- PHP 8.2 or higher
- Laravel 10.x or higher
Installation
You can install the package via Composer:
composer require creativecrafts/laravel-twillio-sms
Configuration
After installing the package, you need to publish the configuration file:
php artisan vendor:publish --tag="twillio-sms-config"
This will create a config/twillio-sms.php file where you can set up your Twilio credentials:
return [ 'account_sid' => env('TWILIO_ACCOUNT_SID'), 'auth_token' => env('TWILIO_AUTH_TOKEN'), 'sms_from' => env('TWILIO_SMS_FROM'), // The Lookup v2 API allows you to query information on a phone number so that you can make a trusted interaction with your user. // With this, you can format and validate phone numbers with the free Basic Lookup request // and add on data packages to get even more in-depth carrier and caller information. // currently supported fields: 'line_type_intelligence', 'sms_pumping_risk' for more information 'phone_number_lookup' => [ 'fields' => [ 'line_type_intelligence', 'sms_pumping_risk', ], 'sms_pumping_risk' => [ // low risk: 0 - 59 // mild risk: 60 - 74 // moderate risk: 75 - 89 // high risk: 90 - 100 // visit https://www.twilio.com/docs/lookup/v2-api/sms-pumping-risk for more information 'max_allowed_sms_pumping_risk_score' => 59, ], ], ];
Ensure you have the following environment variables set in your .env file:
TWILIO_ACCOUNT_SID=your_twilio_account_sid TWILIO_AUTH_TOKEN=your_twilio_auth_token TWILIO_SMS_FROM=your_twilio_phone_number
Usage
To send an SMS, you can create an instance of the LaravelTwillioSms class and chain the methods to set the recipient’s phone number, the message content, and the sender’s number.
Example
use CreativeCrafts\LaravelTwillioSms\LaravelTwillioSms; $sms = LaravelTwillioSms::init() ->setPhoneNumber('+1234567890') ->setMessage('Hello, this is a test message!') ->send(); if ($sms) { echo "Message sent successfully!"; } else { echo "Failed to send the message."; }
Method Reference
init()
public static function init(): self
Creates a new instance of the LaravelTwillioSms class.
setFrom(string $from): self
Sets the ‘from’ phone number for the SMS messages.
setPhoneNumber(string $number): self
Sets the recipient’s phone number for the SMS message.
setMessage(string $message): self
Sets the content of the SMS message.
send(): bool
Sends the SMS message. Returns true if the message is sent successfully, or throws a TwilioException if an error occurs.
sendSms(string $number, string $message): bool
- Deprecated. Use send() instead. This method sends an SMS using the provided number and message directly.
Getters
• getPhoneNumber(): string
• getMessage(): string
• getSentFrom(): string
validatePhoneNumber(): bool
Validates the recipient’s phone number using Twilio’s Lookup API.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
creativecrafts/laravel-twillio-sms 适用场景与选型建议
creativecrafts/laravel-twillio-sms 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 684 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 08 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「creativeCrafts」 「laravel-twillio-sms」 「laravel-send-sms」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 creativecrafts/laravel-twillio-sms 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 creativecrafts/laravel-twillio-sms 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 creativecrafts/laravel-twillio-sms 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This is a handy package the can send email via AWS SES
A simple package that will provide a fluent api to interact with third party authentication providers
A handy package to access and interact with OpenAi endpoint
Laravel API Response is a powerful and flexible package that provides a standardized way to structure API responses in Laravel applications. It offers a range of features to enhance your API development experience, including consistent response formatting, conditional responses, pagination support,
A handy package to paginate laravel collection
A simple package to sort query collections.
统计信息
- 总下载量: 684
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-08-22