# php-sms
**Repository Path**: magein/php-sms
## Basic Information
- **Project Name**: php-sms
- **Description**: php sms
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2024-02-29
- **Last Updated**: 2024-03-05
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
PHP,SMS
### 简介
php发送短信类
[gitee](https://gitee.com/magein/php-sms)
[composer](https://packagist.org/packages/magein/sms)
[lastest version 1.0.1](https://gitee.com/magein/php-sms/tags)
### 平台支持
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配置文件说明](./config.md)
#### thinkphp(手动)
在app目录的service.php添加服务提供者
```php
return [
// 其他服务提供者......
\magein\sms\service\think\SmsService::class,
];
```
#### laravel(手动)
在config目录下app.php的providers配置中添加以下配置
```php
'providers' => [
// 其他服务提供者......
\magein\sms\service\laravel\SmsServiceProvider::class,
];
```
#### 框架路由
使用服务提供者后默认注册了路由(post方式)
/sms/code 发送验证码
/sms/message 发送短信
/sms/batch 批量发送
/sms/delay 延迟发送
#### 方法
```php
// 获取发送类
sms_send()
// 发送验证码
sms_code()
```
### 批量和延迟发送
批量发送手机号码格 phone字段: 139xxxx,139xxxx
批量发送和延迟发送都需要用到队列
thinkphp使用
```php
composer require topthink/think-queue:"^3.0.0"
```
安装后执行
```php
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的代码
```php
addColumn(Column::string('queue'))
// 修改一下长度
addColumn(Column::string('queue',100))
```
### 中间件
使用提供的路由需要执行中间件,可以在配置文件中配置 middleware 参数
```php
return [
'default'=>'tencent'
// 要执行的中间件
'middleware'=>[],
// 其他配置参数
];
```
### 更新日志
#### v1.0.1
2024-03-05
1. 优化target->getContent()方法