腾讯云短信 PHP SDK
===
## 腾讯短信服务
目前`腾讯云短信`为客户提供`国内短信`、`国内语音`和`海外短信`三大服务,腾讯云短信SDK支持以下操作:
### 国内短信
国内短信支持操作:
- 单发短信
- 指定模板单发短信
- 群发短信
- 指定模板群发短信
- 拉取短信回执和短信回复状态
> `Note` 短信拉取功能需要联系腾讯云短信技术支持(QQ:3012203387)开通权限,量大客户可以使用此功能批量拉取,其他客户不建议使用。
### 海外短信
海外短信支持操作:
- 单发短信
- 指定模板单发短信
- 群发短信
- 指定模板群发短信
- 拉取短信回执和短信回复状态
> `Note` 海外短信和国内短信使用同一接口,只需替换相应的国家码与手机号码,每次请求群发接口手机号码需全部为国内或者海外手机号码。
### 语音通知
语音通知支持操作:
- 发送语音验证码
- 发送语音通知
## 开发
### 准备
在开始开发云短信应用之前,需要准备如下信息:
- [x] 获取SDK AppID和AppKey
云短信应用SDK `AppID`和`AppKey`可在[短信控制台](https://console.cloud.tencent.com/sms)的应用信息里获取,如您尚未添加应用,请到[短信控制台](https://console.cloud.tencent.com/sms)中添加应用。
- [x] 申请签名
一个完整的短信由短信`签名`和短信正文内容两部分组成,短信`签名`须申请和审核,`签名`可在[短信控制台](https://console.cloud.tencent.com/sms)的相应服务模块`内容配置`中进行申请。
- [x] 申请模板
同样短信或语音正文内容`模板`须申请和审核,`模板`可在[短信控制台](https://console.cloud.tencent.com/sms)的相应服务模块`内容配置`中进行申请。
## 安装
### Composer
qcloudsms_php采用composer进行安装,要使用qcloudsms功能,只需要在composer.json中添加如下依赖:
```json
{
"require": {
"qcloudsms/qcloudsms_php": "0.1.*"
}
}
```
> `Note` Composer的使用可以参考demo目录下面的示例。
### 手动
1. 手动下载或clone最新版本qcloudsms_php代码
2. 把qcloudsms_php src目录下的代码放入Autoloading目录
## 用法
若您对接口存在疑问,可以查阅 [开发指南](https://cloud.tencent.com/document/product/382/13297) 、[API文档](https://qcloudsms.github.io/qcloudsms_php/) 和 [错误码](https://cloud.tencent.com/document/product/382/3771)。
- **准备必要参数**
```php
// 短信应用SDK AppID
$appid = 1400009099; // 1400开头
// 短信应用SDK AppKey
$appkey = "9ff91d87c2cd7cd0ea762f141975d1df37481d48700d70ac37470aefc60f9bad";
// 需要发送短信的手机号码
$phoneNumbers = ["21212313123", "12345678902", "12345678903"];
// 短信模板ID,需要在短信应用中申请
$templateId = 7839; // NOTE: 这里的模板ID`7839`只是一个示例,真实的模板ID需要在短信控制台中申请
$smsSign = "腾讯云"; // NOTE: 这里的签名只是示例,请使用真实的已申请的签名,签名参数使用的是`签名内容`,而不是`签名ID`
```
- **单发短信**
```php
use Qcloud\Sms\SmsSingleSender;
try {
$ssender = new SmsSingleSender($appid, $appkey);
$result = $ssender->send(0, "86", $phoneNumber[0],
"【腾讯云】您的验证码是: 5678", "", "");
$rsp = json_decode($result);
echo $result;
} catch(\Exception $e) {
echo var_dump($e);
}
```
> `Note` 如需发送海外短信,同样可以使用此接口,只需将国家码 `86` 改写成对应国家码号。
> `Note` 无论单发/群发短信还是指定模板ID单发/群发短信都需要从控制台中申请模板并且模板已经审核通过,才可能下发成功,否则返回失败。
- **指定模板ID单发短信**
```php
use Qcloud\Sms\SmsSingleSender;
try {
$ssender = new SmsSingleSender($appid, $appkey);
$params = ["5678"];
$result = $ssender->sendWithParam("86", $phoneNumbers[0], $templateId,
$params, $smsSign, "", ""); // 签名参数未提供或者为空时,会使用默认签名发送短信
$rsp = json_decode($result);
echo $result;
} catch(\Exception $e) {
echo var_dump($e);
}
```
> `Note` 无论单发/群发短信还是指定模板ID单发/群发短信都需要从控制台中申请模板并且模板已经审核通过,才可能下发成功,否则返回失败。
- **群发**
```php
use Qcloud\Sms\SmsMultiSender;
try {
$msender = new SmsMultiSender($appid, $appkey);
$result = $msender->send(0, "86", $phoneNumbers,
"【腾讯云】您的验证码是: 5678", "", "");
$rsp = json_decode($result);
echo $result;
} catch(\Exception $e) {
echo var_dump($e);
}
```
> `Note` 无论单发/群发短信还是指定模板ID单发/群发短信都需要从控制台中申请模板并且模板已经审核通过,才可能下发成功,否则返回失败。
- **指定模板ID群发**
```php
use Qcloud\Sms\SmsMultiSender;
try {
$msender = new SmsMultiSender($appid, $appkey);
$params = ["5678"];
$result = $msender->sendWithParam("86", $phoneNumbers,
$templateId, $params, $smsSign, "", ""); // 签名参数未提供或者为空时,会使用默认签名发送短信
$rsp = json_decode($result);
echo $result;
} catch(\Exception $e) {
echo var_dump($e);
}
```
> `Note` 群发一次请求最多支持200个号码,如有对号码数量有特殊需求请联系腾讯云短信技术支持(QQ:3012203387)。
> `Note` 无论单发/群发短信还是指定模板ID单发/群发短信都需要从控制台中申请模板并且模板已经审核通过,才可能下发成功,否则返回失败。
- **发送语音验证码**
```php
use Qcloud\Sms\SmsVoiceVerifyCodeSender;
try {
$vvcsender = new SmsVoiceVerifyCodeSender($appid, $appkey);
$result = $vvcsender->send("86", $phoneNumber[0], "5678", 2, "");
$rsp = json_decode($result);
echo $result;
} catch (\Exception $e) {
echo var_dump($e);
}
```
> `Note` 语音验证码发送只需提供验证码数字,例如当msg=“5678”时,您收到的语音通知为“您的语音验证码是5678”,如需自定义内容,可以使用语音通知。
- **发送语音通知**
```php
use Qcloud\Sms\SmsVoicePromptSender;
try {
$vpsender = new SmsVoicePromptSender($appid, $appkey);
$result = $vpsender->send("86", $phoneNumber[0], 2, "5678", "");
$rsp = json_decode($result);
echo $result;
} catch (\Exception $e) {
echo var_dump($e);
}
```
- **拉取短信回执以及回复**
```php
use Qcloud\Sms\SmsStatusPuller;
try {
$sspuller = new SmsStatusPuller($appid, $appkey);
// 拉取短信回执
$callbackResult = $spuller->pullCallback(10);
$callbackRsp = json_decode($callbackResult);
echo $callbackResult;
// 拉取回复
$replyResult = $spuller->pullReply(10);
$replyRsp = json_decode($replyResult);
echo $replyResult;
} catch (\Exception $e) {
echo var_dump($e);
}
```
> `Note` 短信拉取功能需要联系腾讯云短信技术支持(QQ:3012203387),量大客户可以使用此功能批量拉取,其他客户不建议使用。
- **拉取单个手机短信状态**
```php
use Qcloud\Sms\SmsMobileStatusPuller;
try {
$beginTime = 1511125600; // 开始时间(unix timestamp)
$endTime = 1511841600; // 结束时间(unix timestamp)
$maxNum = 10; // 单次拉取最大量
$mspuller = new SmsMobileStatusPuller($appid, $appkey);
// 拉取短信回执
$callbackResult = $mspuller->pullCallback("86", $phoneNumbers[0],
$beginTime, $endTime, $maxNum);
$callbackRsp = json_decode($callbackResult);
echo $callbackResult;
没有合适的资源?快使用搜索试试~ 我知道了~
腾讯云-短信接口demo PHP
共258个文件
html:64个
php:50个
sample:22个
需积分: 50 75 下载量 139 浏览量
2018-05-22
17:01:08
上传
评论 4
收藏 1.21MB RAR 举报
温馨提示
为了防止用户恶意获取验证码, 需要有一个60秒倒计时, 让用户60秒后才能第二次获取验证码。 当然这个60秒是你自己设置的, 也可以是30秒。
资源推荐
资源详情
资源评论
收起资源包目录
腾讯云-短信接口demo PHP (258个子文件)
config 484B
config 484B
bootstrap.min.css 112KB
bootstrap.min.css 112KB
bootstrap.min.css 112KB
bootstrap.min.css 112KB
bootstrap-theme.min.css 20KB
bootstrap-theme.min.css 20KB
bootstrap-theme.min.css 20KB
bootstrap-theme.min.css 20KB
sami.css 7KB
sami.css 7KB
sami.css 7KB
sami.css 7KB
description 73B
description 73B
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.eot 20KB
exclude 240B
exclude 240B
.gitignore 44B
.gitignore 44B
.gitignore 39B
.gitignore 39B
HEAD 591B
HEAD 591B
HEAD 238B
HEAD 238B
HEAD 32B
HEAD 32B
HEAD 23B
HEAD 23B
SmsSenderUtil.html 16KB
SmsSenderUtil.html 16KB
SmsSenderUtil.html 16KB
SmsSenderUtil.html 16KB
doc-index.html 16KB
doc-index.html 16KB
doc-index.html 15KB
doc-index.html 15KB
SmsMultiSender.html 11KB
SmsMultiSender.html 11KB
SmsSingleSender.html 11KB
SmsSingleSender.html 11KB
SmsMultiSender.html 11KB
SmsMultiSender.html 11KB
SmsSingleSender.html 11KB
SmsSingleSender.html 11KB
SmsMobileStatusPuller.html 10KB
SmsMobileStatusPuller.html 10KB
SmsMobileStatusPuller.html 10KB
SmsMobileStatusPuller.html 10KB
SmsStatusPuller.html 9KB
SmsStatusPuller.html 9KB
SmsStatusPuller.html 8KB
SmsStatusPuller.html 8KB
SmsVoicePromptSender.html 8KB
SmsVoicePromptSender.html 8KB
SmsVoiceVerifyCodeSender.html 8KB
SmsVoiceVerifyCodeSender.html 8KB
SmsVoicePromptSender.html 8KB
SmsVoicePromptSender.html 8KB
SmsVoiceVerifyCodeSender.html 8KB
SmsVoiceVerifyCodeSender.html 8KB
classes.html 6KB
classes.html 6KB
Sms.html 6KB
Sms.html 6KB
classes.html 6KB
classes.html 6KB
Sms.html 6KB
Sms.html 6KB
search.html 6KB
search.html 6KB
search.html 6KB
search.html 6KB
namespaces.html 4KB
namespaces.html 4KB
index.html 4KB
index.html 4KB
namespaces.html 4KB
namespaces.html 4KB
index.html 4KB
Qcloud.html 4KB
index.html 4KB
Qcloud.html 4KB
Qcloud.html 3KB
Qcloud.html 3KB
traits.html 3KB
traits.html 3KB
traits.html 3KB
traits.html 3KB
interfaces.html 3KB
interfaces.html 3KB
interfaces.html 3KB
interfaces.html 3KB
pack-4935f48312401acb5885d299b74c7485d3c8614b.idx 4KB
pack-4935f48312401acb5885d299b74c7485d3c8614b.idx 4KB
共 258 条
- 1
- 2
- 3
资源评论
hou1988426
- 粉丝: 47
- 资源: 30
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功