您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
这篇文章主要介绍了PHP实现云服务器短信sdk灵活应用在项目中的方法,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
首先安装
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);
感谢你能够认真阅读完这篇文章,希望小编分享的“PHP实现云服务器短信sdk灵活应用在项目中的方法”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。