首先安装
composer require alibabacloud/sdk
接着看alibabacloud官网文档
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;
/**
* 阿里信息发送类
* @Task("ali")
*/
class My_composer_aliyunsms
{
/**
* 发送短信验证码
*/
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);
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:- Thinkphp集成抖音SDK的实现方法
- 微信sdk实现禁止微信分享(使用原生php实现)
- PHP实现微信支付(jsapi支付)和退款(无需集成支付SDK)流程教程详解
- thinkPHP微信分享接口JSSDK用法实例
- thinkPHP简单导入和使用阿里云OSSsdk的方法
- php一个文件搞定微信jssdk配置
- PHP实现微信JS-SDK接口选择相册及拍照并上传的方法
- 微信支付PHP SDK之微信公众号支付代码详解
- 微信公众平台开发接口PHP SDK完整版
- PHP sdk实现在线打包代码示例