程序员

thinkphp6+腾讯云

作者:admin 2021-05-15 我要评论

开发要用到腾讯云的短信自己就注册申请了一个 按流程来走准没错 接下来审核通过的话可以在这两个地方查看具体的内容涉及隐私不过多展示了 然后使用线上的API Exp...

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)

开发要用到腾讯云的短信,自己就注册申请了一个
按流程来走准没错
在这里插入图片描述
接下来审核通过的话可以在这两个地方查看具体的内容,涉及隐私不过多展示了

然后使用线上的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里面看一下

在这里插入图片描述
完事。码字不易,点个赞在走呗

;原文链接:https://blog.csdn.net/weixin_44088587/article/details/115486244

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
  • thinkphp6+腾讯云

    thinkphp6+腾讯云

  • 操作系统:银行家算法(C语言代码)详

    操作系统:银行家算法(C语言代码)详

  • Linux常用命令精讲(全)

    Linux常用命令精讲(全)

  • 项目实战之自己动手用python编写一个服

    项目实战之自己动手用python编写一个服

腾讯云代理商
海外云服务器