thinkphp 短信api接口调用
- https://docs.topthink.com/think-api/2203721购买短信接口
2选择套餐
3.我的服务->短信服务,申请签名和模板,具体要求查看文档。
4.申请成功如下:
5.调用api首先需要在你的项目里面安装think-api
库(适用于任何PHP5.6+
项目,对框架没有任何要求)。
composer require topthink/think-api
6.测试
<?php
namespace app\api\controller;
use think\Controller;
use think\api\Client;
Class Sms extends controller
{
public function send(){
$client = new Client("YourAppCode");//用户授权码
$result = $client->smsSend()
->withSignId('116')// 签名id
->withTemplateId('4')// 模板id
->withPhone('13480****30')//要发送的国内手机号码
->withParams('{"code": "7865"}')
->request();
dump($result);
}
}