定制 walkboy/yii2-sms 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

walkboy/yii2-sms

最新稳定版本:1.0

Composer 安装命令:

composer require walkboy/yii2-sms

包简介

This is the base library for providing SMS support in your Yii2 application. You can make your own plugins for SMS providers off this base package. It is not to be directly used.

README 文档

README

This is the base library for providing SMS support in your Yii2 application. You can make your own plugins for SMS providers off this base package. It is not to be directly used.

NOTE: You can not use this library/package by itself. It is a parent/root package meant to be extended from! See Yii2 SMS Twilio for an example on how to make your own plugin extending this package.

This is just like the base mail namespace in Yii2. You don't use it directly, but rather use the Swiftmailer package which extends the built-in yii\mail classes.

The goal is to send SMS text messages similar to how you send emails in Yii2 and to be easily extended on to support an infinite number of SMS providers.

This package originaly was created by @WadeShuler but author removed it from Github and abandoned package maintenance.

Key take-aways

Configuration is in your main config (Advanced: common/config/main-local.php) as the sms component:

'components' => [
    'sms' => [
        'class' => 'namespace\to\ExtendedSms',  // Class that extends BaseSms
        'viewPath' => '@common/sms',            // Optional: defaults to '@app/sms'

        // send all sms to a file by default.
        'useFileTransport' => true,             // false for real sending

        'messageConfig' => [
            'from' => '+15552221234',           // From number to send from
        ],

        'apiKey' => 'xxxxxxxxxxxxxxx',          // Example where to put keys
    ]
]

Note: The above configuration is only an example and will not actually send SMS messages. You will need to make your own Sms class that extends BaseSms, as well as your own class that extends BaseMessage. Your extended classes will handle the logic for using your own SMS service provider of choice. My Yii2 SMS Twilio extension is a great example of how to make a plugin for this package.

When useFileTransport is set to true, it will dump the text messages in the fileTransportPath which defaults to @runtime/sms. I have made slight modifications so these are more readable.

Use the messageConfig array to set default message configurations, such as from, as the Message class will be instantiated with them automatically via the "getters" and "setters", thanks to Yii::createObject().

You can set API key params in the sms configuration array directly, not inside messageConfig, as they have to do with the transport (SMS provider) and not the message specifically. Note: apiKey is not defined in this package, and was simply an example of where to place them.

The viewPath defaults to @app/sms, same as the Yii2 mailer, and can be overridden in the config. This is for using a view file, specified within the compose() function, similar to the Yii2 mailer.

Note: There are only "text" views. Since these are text messages, HTML views are not applicable. Therefore you just pass the view as a string, not an array with a text param in it! I removed that to streamline usage, as it made more sense to take it out.

View file example:

Yii::$app->sms->compose('test-message', ['name' => 'Wade'])

Where test-message is a view file located in the viewPath destination.

View File: common/sms/test-message.php

Hello <?= $name ?> This is a test!

Thanks!

You will need to create the sms directory, as well as the view file, if you intend on using views and not just setting the message directly with setMessage().

Without view file example:

Yii::$app->sms->compose()
    //->setFrom('12345')  // if not set in config, or to override
    ->setTo('+15558881234')
    ->setMessage("Hey {$name} this is a test!\n\nThanks!")
    ->send();

If you set the from number in the main config, under the messageConfig array, you do not need to call setFrom() unless you want to override the number that was configured.

So how do I use this?

I recommend you look at Yii2 SMS Twilio package. You will see in the composer.json that it requires this package. It's Sms class extends this BaseSms, and Message extends this BaseMessage.

Packages using this library

Want to add yours to the list? Create an issue and I will add it so long as it works and extends this base package.

walkboy/yii2-sms 适用场景与选型建议

walkboy/yii2-sms 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 10 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 walkboy/yii2-sms 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-10-03