您当前的位置: 首页 >  阿里云

暂无认证

  • 3浏览

    0关注

    92582博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

阿里云PHP-SMS短信服务——验证码发送教程

发布时间:2017-11-07 19:17:58 ,浏览量:3

  • 开通SMS服务
  • 创建签名模板
    • 创建签名
    • 记住签名名称
    • 创建模板
    • 查看并记住模板CODE
  • 创建并记住KeyId和KeySecret
  • 下载阿里云短信服务器PHP-SDK
  • 创建PHP-SMS项目
    • 创建代码文件
    • 移入Requset
  • 完成
  • SMS短信服务DEMO打包
开通SMS服务

首先去这个网站开通阿里云的SMS短信服务:https://www.aliyun.com/product/sms?spm=5176.8142029.388261.295.vU5T5g

创建签名、模板

要使用短信服务器需要先创建签名和模板,并提交给阿里云审核通过才可以正常使用短信服务。

这里写图片描述

创建签名

创建签名的时候注意一下签名名称,其他的话就不累赘了。

这里写图片描述

记住签名名称

现在请记住你创建的签名名称,一会在代码中需要使用。

创建模板

创建模板也很简单,阿里云已经把要如何填写写的很清楚了。

这里写图片描述

查看并记住模板CODE

返回你的控制台,当你的模板审核通过时这就会出现大于0的数。  点击这个数,会进入模板管理面板就能看到你的模板CODE了,请记住他。

这里写图片描述

这里写图片描述

创建并记住KeyId和KeySecret

到控制台,把鼠标放到右上角你的用户名的位置会出现一个accessKeySecret点进去就可以创建KeyId和KeySecret了,如果他提醒你用RAM安全什么的,你看你要不要给你的员工分配权限,如果要的话就用RAM,否则就直接点击继续使用就行了。

这里写图片描述

这里写图片描述)

下载阿里云短信服务器PHP-SDK

官方下载地址:https://help.aliyun.com/document_detail/55359.html?spm=5176.8195934.507901.12.b1ngGK  本教程使用SDK下载地址:http://pan.baidu.com/s/1bpF5B8z  密匙:pult  这里写图片描述

创建PHP-SMS项目 创建代码文件

创建你的代码文件,并把这个文件放在刚才下载的SDK文件夹中的api_sdk的aliyun-php-sdk-core目录下,并把以下代码写入代码文件。  aliyun-php-sdk-core目录里包含了SMS短信服务的各种模块,所以必须得放在这里面才能使用服务

 function __construct() { parent::__construct("Dysmsapi", "2017-05-25", "SendSms");
    } private $outId; private $signName; private $ownerId; private $resourceOwnerId; private $templateCode; private $phoneNumbers; private $resourceOwnerAccount; private $templateParam; public function getOutId() { return $this->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;
    }

}
		
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
完成

运行试试吧

这里写图片描述  这里写图片描述

SMS短信服务DEMO打包

这是我自己弄的DEMO已经测试可用啦,只要修改S\SMS\aliyun-php-sdk-core目录下的smsDemo就可以使用啦!,其他的东西都不要改,要保证S文件目录下的完整性。  百度云  链接:http://pan.baidu.com/s/1pLkFgVp 密码:1fi1

原文地址:http://blog.csdn.net/a735311619/article/details/74939887

关注
打赏
1653961664
查看更多评论
立即登录/注册

微信扫码登录

0.4706s