加入收藏 | 设为首页 | 会员中心 | 我要投稿 辽源站长网 (https://www.0437zz.com/)- 云专线、云连接、智能数据、边缘计算、数据安全!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

阿里云PHP SMS短信服务验证码发送方法

发布时间:2021-02-01 05:30:38 所属栏目:PHP教程 来源:网络整理
导读:开通SMS服务 首先去这个网站开通阿里云的SMS短信服务: 创建签名、模板 要使用短信服务器需要先创建签名和模板,并提交给阿里云审核通过才可以正常使用短信服务。 创建签名 创建签名的时候注意一下签名名称,其他的话就不累赘了。 记住签名名称 现在请记住你

aliyun-php-sdk-core目录里包含了SMS短信服务的各种模块,所以必须得放在这里面才能使用服务

setPhoneNumbers("123456789"); //这里填你要发送的电话号码 //必填-短信签名 $request->setSignName("xx项目"); //这里就是刚才让你记住的项目签名 //必填-短信模板Code $request->setTemplateCode("SMS_123456"); //这里就是模板CODE //选填-假如模板中存在变量需要替换则为必填(JSON格式) $request->setTemplateParam("{"name":"郭涛","number":"316"}"); //选填-发送短信流水号 $request->setOutId("1234");//照填就行了 //发起访问请求 $acsResponse = $acsClient->getAcsResponse($request); var_dump($acsResponse);//返回结果

移入Requset

还是在下载的SDK文件夹中的api_sdk目录下,有一个交Dysmsapi的文件夹,打开这个文件夹就会看到一个叫Request的文件夹,把这个Reques。的件夹复制粘贴到aliyun-php-sdk-core里面。说实在的我搞不清阿里云这个为什么要这样分开装SDK,可能是我使用的姿势不对吧,如果有大神搞得清,还劳烦赐教小弟,好人一生平安。 移入后,打开RequestV20170525目录里有一个SendSmsRequest.php的源文件。请屏蔽第一行的空间命名。 也就是这一行namespace DysmsapiReqestV20170525;最后效果如下

outId; } public function setOutId($outId) { $this->outId = $outId; $this->queryParameters["OutId"]=$outId; } public function getSignName() { return $this->signName; } public function setSignName($signName) { $this->signName = $signName; $this->queryParameters["SignName"]=$signName; } public function getOwnerId() { return $this->ownerId; } public function setOwnerId($ownerId) { $this->ownerId = $ownerId; $this->queryParameters["OwnerId"]=$ownerId; } public function getResourceOwnerId() { return $this->resourceOwnerId; } public function setResourceOwnerId($resourceOwnerId) { $this->resourceOwnerId = $resourceOwnerId; $this->queryParameters["ResourceOwnerId"]=$resourceOwnerId; } public function getTemplateCode() { return $this->templateCode; } public function setTemplateCode($templateCode) { $this->templateCode = $templateCode; $this->queryParameters["TemplateCode"]=$templateCode; } public function getPhoneNumbers() { return $this->phoneNumbers; } public function setPhoneNumbers($phoneNumbers) { $this->phoneNumbers = $phoneNumbers; $this->queryParameters["PhoneNumbers"]=$phoneNumbers; } public function getResourceOwnerAccount() { return $this->resourceOwnerAccount; } public function setResourceOwnerAccount($resourceOwnerAccount) { $this->resourceOwnerAccount = $resourceOwnerAccount; $this->queryParameters["ResourceOwnerAccount"]=$resourceOwnerAccount; } public function getTemplateParam() { return $this->templateParam; } public function setTemplateParam($templateParam) { $this->templateParam = $templateParam; $this->queryParameters["TemplateParam"]=$templateParam; } }

完成

(编辑:辽源站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

推荐文章
    热点阅读