multiotp/smsgateway
Composer 安装命令:
composer require multiotp/smsgateway
包简介
Flat-file based SMS gateway PHP class using an open source Android app
README 文档
README
Features
- SMS gateway using the open source Android app SMS Gateway - use the generic release
License
This software is distributed under the LGPL-3.0-only license. Please read LICENSE for information on the software availability and distribution.
Installation & loading
SMSGateway is available on Packagist (using semantic versioning), and installation via Composer is the recommended way to install SMSGateway. Just add this line to your composer.json file:
"multiotp/smsgateway": "^1.0"
or run
composer require multiotp/smsgateway
Note that the vendor folder and the vendor/autoload.php script are generated by Composer; they are not part of SMSGateway.
Alternatively, if you're not using Composer, you
can download SMSGateway as a zip file, then copy the contents of the SMSGateway folder into one of the include_path directories specified in your PHP configuration and load each class file manually:
<?php use multiOTP\SMSGateway\SMSGateway; require 'path/to/SMSGateway/src/SMSGateway.php';
Two simple examples
<?php //Import SMSGateway classes into the global namespace //These must be at the top of your script, not inside a function use multiOTP\SMSGateway\SMSGateway; //Load Composer's autoloader require 'vendor/autoload.php'; //Create an instance $smsgateway = new SMSGateway(); // Set the data folder $smsgateway->setDataPath(__DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR); // Set the shared secret $smsgateway->setSharedSecret("secret"); $device_id = "demo"; $to = "+1234567890"; $message = "Demo message"; $device_h = $smsgateway->calculateAuthenticationHash($device_id); $message_id = $smsgateway->sendMessage($device_id, $to, $message); echo "Full URL for Android app URL: https://......./?id=$device_id&h=$device_h";
<?php //Import SMSGateway classes into the global namespace //These must be at the top of your script, not inside a function use multiOTP\SMSGateway\SMSGateway; //Load Composer's autoloader require 'vendor/autoload.php'; // Please note that implementing a new_message_handling callback function // will flag the new messages as read when returning from the function. function new_message_handling($array) { // Handling $array of new received messages // [["device_id" => "device id", // "message_id" => "message id", // "from" => "from phone number", // "sms_sent" => "sms_sent timestamp (ms)", // "sms_received" => "sms_received timestamp (ms)", // "content" => "message content", // "last_update" => "last update timestamp (ms)", // "status" => "UNREAD|READ" // ], // [...] // ] } function update_handling($array) { // Handling $array of status updates for sent messages // [["device_id" => "device id", // "message_id" => "message id", // "to" => "to phone number", // "content" => "content", // "last_update" => "last update timestamp (ms)", // "status" => "NEW|PUSHED|PENDING|SENT|DELIVERED|FAILED" // ], // [...] // ] } function timeout_handling($array) { // Handling $array of devices not seen during the last "DeviceTimeout" seconds // [["device_id" => "device_id", // "last_update" => "device_last_update" // ], // [...] // ] } //Create an instance $smsgateway = new SMSGateway(); // Set the data folder $smsgateway->setDataPath(__DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR); // Launch the API server with callback functions definition $smsgateway->apiServer("secret", "new_message_handling", "update_handling", "timeout_handling");
SMS messages status
Received message
- UNREAD: message has never been read on the gateway
- READ: message has already been read on the gateway
Sent message
- NEW: new created message, not transfered yet to the Android device
- PUSHED: message pushed to the Android device
- PENDING: message is pending in the Android device
- SENT: message has been sent to the gateway's network
- DELIVERED: message has been received by the recipient's phone
- FAILED: message delivery has failed and will not be retried
- MISSING: message with this message id is missing, no state available
Online demo
A full working gateway implementation is available here : Online SMSGateway demo. Click the link and everything is self-explanatory. You will simply have to install and configure the companion open source Android app in order to send and receive SMS messages through this demo gateway (as explained after sending a first SMS message using the online demo gateway).
When sending a message, the following information will be returned in the http header and in the html meta tags:
- X-SMSGateway-State: state of the sent message (NEW|FAILED)
- X-SMSGateway-State-Url: full url to check the state of the message
- X-SMSGateway-Message-Id: message id
Documentation
Example of how to use SMSGateway for a common scenario can be found in the examples folder. If you're looking for a good starting point, we recommend you start with the gateway example.
Android specific parameters
Using adb shell, you should change these two parameters:
- sms_outgoing_check_max_count
- sms_outgoing_check_interval_ms
Example for a limit of 200 messages per minute:
adb shell
settings put global sms_outgoing_check_max_count 200
settings put global sms_outgoing_check_interval_ms 60000
You need to reboot your Android phone. after these changes
Changelog
See CHANGELOG.
That's it. You should now be ready to use SMSGateway!
multiotp/smsgateway 适用场景与选型建议
multiotp/smsgateway 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 108 次下载、GitHub Stars 达 22, 最近一次更新时间为 2022 年 10 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「sms」 「gateway」 「class」 「android」 「flat-file」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 multiotp/smsgateway 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 multiotp/smsgateway 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 multiotp/smsgateway 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
Payyo Gateway for the Omnipay payment processing library
SDK for payment gateway PlatbaMobilom.sk for PHP7.0
Extensible library for building notifications and sending them via different delivery channels.
yii2-sms expand
Client library to send SMS using Comilio SMS Gateway API (https://www.comilio.it)
统计信息
- 总下载量: 108
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 23
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: LGPL-3.0-only
- 更新时间: 2022-10-11