开发要用到腾讯云的短信,自己就注册申请了一个
按流程来走准没错
接下来审核通过的话可以在这两个地方查看具体的内容,涉及隐私不过多展示了
然后使用线上的API Explorer在线调用,
这里需要注意的是不要勾选只看必填参数,
因为我这里是验证码业务,需要带上参数所以有一些选填的内容也要填
PhoneNumberSet.N 这里国内的话(我暂时用不到国际) 开头+86138xxxxxxxx
TemplateID 这个自己看模板上面的id
SmsSdkAppid 这个是签名上面的Appid
Sign 短信签名内容
TemplateParamSet.N 这里是模板参数内容,因为是验证码,咱们测试写个123
这里成功的展示
如果配置在本地的话,会有一个问题
这个问题是php环境证书需要两部操作
https://github.com/TencentCloud/tencentcloud-sdk-php 下载证书文件
并放到 “D:\phpstudy_pro\Extensions\php\php7.3.4nts\extras\ssl” (这个自己看自己的目录)
接着到php.ini
搜索 curl.cainfo 把注释打开
curl.cainfo ="D:\phpstudy_pro\Extensions\php\php7.3.4nts\extras\ssl\cacert.pem"
然后重启Nginx服务
tp6中添加依赖
composer require tencentcloud/tencentcloud-sdk-php
/**
* Created by PhpStorm.
* User: lenovo
* Date: 2021/4/7
* Time: 11:00
* Note: 加油为了曾经吹过的牛逼
*/
namespace app\api\lib;
use TencentCloud\Common\Credential;
use TencentCloud\Common\Profile\ClientProfile;
use TencentCloud\Common\Profile\HttpProfile;
use TencentCloud\Common\Exception\TencentCloudSDKException;
use TencentCloud\Sms\V20190711\SmsClient;
use TencentCloud\Sms\V20190711\Models\SendSmsRequest;
class BaiduSms
{
public static function sendSms(){
try {
$cred = new Credential("SecretId", "SecretKey");
$httpProfile = new HttpProfile();
$httpProfile->setEndpoint("sms.tencentcloudapi.com");
$clientProfile = new ClientProfile();
$clientProfile->setHttpProfile($httpProfile);
$client = new SmsClient($cred, "", $clientProfile);
$req = new SendSmsRequest();
$params = array(
"PhoneNumberSet" => array( "+86电话号码" ),
"TemplateID" => "xxxx",
"Sign" => "xxxx",
"TemplateParamSet" => array( "验证码(int)" ),
"SmsSdkAppid" => "xxxxx"
);
$req->fromJsonString(json_encode($params));
$resp = $client->SendSms($req);
print_r($resp->toJsonString());
}
catch(TencentCloudSDKException $e) {
echo $e;
}
}
}
然后咱们去postman里面看一下
完事。码字不易,点个赞在走呗