1 Star 0 Fork 0

小马哥 / php-sms

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

PHP,SMS

简介

php发送短信类

gitee

composer

lastest version 1.0.1

平台支持

  1. 阿里云
  2. 腾讯云

后续开放将支持更多平台

模版变量

content值为变量的替换的时候 格式统一为

// json_encode编码得到的值
{name:"magein",phone:"13888888888"}

阿里云

验证码模版如:

验证码:${code},10分钟内有效。如非本人操作请忽略。

content值可以已传递:

// 传递整型的时候,会自动替换成{code:xxx}
123456 
// 或者 

// number是您自定义的模版变量
{number:"123456"}

在后台添加模版如:

您的订单已经开始配送,由${name}小哥进行配送,联系电话:${phone},祝您生活愉快

则content值可以传递:

// json_encode编码后的值
{name:"magein",phone:"13888888888"}

腾讯云

验证码模版如:

验证码:{1},10分钟内有效。如非本人操作请忽略。

content值可以已传递:

123456

在后台添加模版如:

您的订单已经开始配送,由{1}小哥进行配送,联系电话:{2},祝您生活愉快

则content值可以传递:

// json_encode编码后的值,请注意使用先后顺序
{name:"magein",phone:"13888888888"}

框架支持

  1. thinkphp6~ 默认使用composer extra加载
  2. laravel8~ 默认使用composer extra加载

需要在框架的config目录添加sms.php配置文件

sms.php配置文件说明

thinkphp(手动)

在app目录的service.php添加服务提供者

return [
    // 其他服务提供者......
    \magein\sms\service\think\SmsService::class,
];

laravel(手动)

在config目录下app.php的providers配置中添加以下配置

'providers' => [
    // 其他服务提供者......
    \magein\sms\service\laravel\SmsServiceProvider::class,
];

框架路由

使用服务提供者后默认注册了路由(post方式)

/sms/code       发送验证码
/sms/message    发送短信
/sms/batch      批量发送
/sms/delay      延迟发送

方法

// 获取发送类
sms_send()

// 发送验证码
sms_code()

批量和延迟发送

批量发送手机号码格 phone字段: 139xxxx,139xxxx

批量发送和延迟发送都需要用到队列

thinkphp使用

composer require topthink/think-queue:"^3.0.0"

安装后执行

php think queue:table
php think migrate:run

如果遇到错误:

SQLSTATE[HY000]: General error: 1709 Index column size too large. The maximum column size is 767 bytes.

修改database/migrations目录下的CreateJobsTable.php的代码

addColumn(Column::string('queue'))
// 修改一下长度
addColumn(Column::string('queue',100))

中间件

使用提供的路由需要执行中间件,可以在配置文件中配置 middleware 参数

return  [

    'default'=>'tencent'
    
    // 要执行的中间件
    'middleware'=>[],

    // 其他配置参数
];

更新日志

v1.0.1

2024-03-05

  1. 优化target->getContent()方法
MIT License Copyright (c) 2023 小马哥 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

php sms 展开 收起
PHP
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/magein/php-sms.git
git@gitee.com:magein/php-sms.git
magein
php-sms
php-sms
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891