首先安裝
composer require alibabacloud/sdk
接著看alibabacloud官網(wǎng)文檔
https://packagist.org/packages/alibabacloud/sdk
示例
My_composer_aliyunsms.php
?php
// use Swoft\Task\Bean\Annotation\Task;
// use AlibabaCloud\Client\AlibabaCloud;
// use AlibabaCloud\Client\Exception\ClientException;
// use AlibabaCloud\Client\Exception\ServerException;
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
use AlibabaCloud\Ecs\Ecs;
/**
* 阿里信息發(fā)送類
* @Task("ali")
*/
class My_composer_aliyunsms
{
/**
* 發(fā)送短信驗(yàn)證碼
*/
public function sendCode($config,$phone,$code)
{
$param = [
'code' => $code
];
AlibabaCloud::accessKeyClient($config['accessKeyId'], $config['accessSecret'])
->regionId($config['regionId'])
->asGlobalClient();
try {
$result = AlibabaCloud::rpcRequest()
->product('Dysmsapi')
->version('2017-05-25')
->action('SendSms')
->method('POST')
->options([
'query' => [
'PhoneNumbers' => $phone,
'SignName' => $config['SignName'],
'TemplateCode' => $config['TemplateCode'],
'TemplateParam' => json_encode($param)
],
])
->request();
return $result->toArray();
} catch (ClientException $e) {
echo $e->getErrorMessage() . PHP_EOL;
} catch (ServerException $e) {
echo $e->getErrorMessage() . PHP_EOL;
}
}
}
demo
include 'My_composer_aliyunsms.php';
$sms = new My_composer_aliyunsms();
$phone='xxxxxx';
$code='99999';
$config = [
'accessKeyId' => 'LTAIMje******hS',
'accessSecret' => 'fMuQTLUrKQN******Z2m07',
'SignName' => '****',
'TemplateCode' => 'SMS_****04',
'regionId' => 'cn-hangzhou'
];
$re = $sms->sendCode($config,$phone,$code);
var_dump($re);
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:- Thinkphp集成抖音SDK的實(shí)現(xiàn)方法
- 微信sdk實(shí)現(xiàn)禁止微信分享(使用原生php實(shí)現(xiàn))
- PHP實(shí)現(xiàn)微信支付(jsapi支付)和退款(無(wú)需集成支付SDK)流程教程詳解
- thinkPHP微信分享接口JSSDK用法實(shí)例
- thinkPHP簡(jiǎn)單導(dǎo)入和使用阿里云OSSsdk的方法
- php一個(gè)文件搞定微信jssdk配置
- PHP實(shí)現(xiàn)微信JS-SDK接口選擇相冊(cè)及拍照并上傳的方法
- 微信支付PHP SDK之微信公眾號(hào)支付代碼詳解
- 微信公眾平臺(tái)開(kāi)發(fā)接口PHP SDK完整版
- PHP sdk實(shí)現(xiàn)在線打包代碼示例