标签:exception echo default method err 根据 ror secret param
1.登录阿里云控制台选择免费开通短信服务(百度阿里云)
2.申请签名和模板(根据要求操作)
(1)签名就是我们收到的验证码短信开头开头【】中的内容
(2)模板就是文本内容
注意模板CODE,接口中会用到
(3)鼠标移到右上角头像,看到AccessKey管理,申请一个,接口中使用
(4)安装SDK
composer require alibabacloud/sd
(5)发送验证码的API接口
简单封装一个类,调用即可
<?php
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
// Download:https://github.com/aliyun/openapi-sdk-php
// Usage:https://github.com/aliyun/openapi-sdk-php/blob/master/README.md
class Sms
{
public function sendSms($phoneNum, $code)
{
AlibabaCloud::accessKeyClient(‘你的<accessKeyId>‘, ‘你的<accessSecret>‘)
->regionId(‘cn-hangzhou‘)
->asDefaultClient();
try {
$result = AlibabaCloud::rpc()
->product(‘Dysmsapi‘)
// ->scheme(‘https‘) // https | http
->version(‘2017-05-25‘)
->action(‘SendSms‘)
->method(‘POST‘)
->host(‘dysmsapi.aliyuncs.com‘)
->options([
‘query‘ => [
‘RegionId‘ => "cn-hangzhou",
‘PhoneNumbers‘ => $phoneNum,
‘SignName‘ => "申请的签名",
‘TemplateCode‘ => "申请的模板CODE",
‘TemplateParam‘ => $code(json格式),
],
])
->request();
print_r($result->toArray());
} catch (ClientException $e) {
echo $e->getErrorMessage() . PHP_EOL;
} catch (ServerException $e) {
echo $e->getErrorMessage() . PHP_EOL;
}
}
}
这些内容根据实际情况修改
AlibabaCloud::accessKeyClient(‘你的<accessKeyId>‘, ‘你的<accessSecret>‘)
‘PhoneNumbers‘ => $phoneNum,
‘SignName‘ => "申请的签名",
‘TemplateCode‘ => "申请的模板CODE",
‘TemplateParam‘ => $code(json格式),
以上便是短信验证码的简单发送接口
更多内容,见阿里云短信服务文档https://help.aliyun.com/document_detail/101414.html?spm=a2c4g.11186623.4.4.145650a4HUKi5u
标签:exception echo default method err 根据 ror secret param
原文地址:https://www.cnblogs.com/tutuut/p/13058185.html