開發要用到騰訊云的短信,自己就注冊申請了一個
按流程來走準沒錯

接下來審核通過的話可以在這兩個地方查看具體的內容,涉及隱私不過多展示了

然后使用線上的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://www.uj5u.com/qita/273665.html
標籤:其他
上一篇:小白入門ROS-關鍵組件
