百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>网页制作> 阿里云PHP SMS短佩服务验证码发送办法详解
分享文章到:

阿里云PHP SMS短佩服务验证码发送办法详解

发布时间:09/01 来源:未知 浏览: 关键词:

开通SMS效劳

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

相关学习引荐:php编程(视频)

创立签名、模板

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

这里写图片描述

创立签名

创立签名的时候留意一下签名名称,其他的话就不负担了。

这里写图片描述

记住签名名称

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

创立模板

创立模板也很简便,阿里云已经把要怎样填写写的很分明了。

这里写图片描述

查看并记住模板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短佩服务的各种模块,所以必需得放在这里面才能使用效劳

<?php
  include 'Config.php';
  include_once 'Request/V20170525/SendSmsRequest.php';
  include_once 'Request/V20170525/QuerySendDetailsRequest.php';
  $accessKeyId = "LTAIvAaNs61JeBiN";
//阿里云KeyId 
  $accessKeySecret = "Y3H7durYJ6GIqmJJrsdbJwPi6E8O8M";
//阿里云KeySecret
  //短信API产品名
  $product = "Dysmsapi";
//照写就行了
  //短信API产品域名
  $domain = "dysmsapi.aliyuncs.com";
//照着写就行了
  //临时不支撑多Region
  $region = "cn-hangzhou";
//照着写就行了
  //初始化拜访的acsCleint
  $profile = DefaultProfile::getProfile($region, $accessKeyId, $accessKeySecret);
  DefaultProfile::addEndpoint("cn-hangzhou", "cn-hangzhou", $product, $domain);
  $acsClient= new DefaultAcsClient($profile);
  $request = new SendSmsRequest;
  //必填-短信接收号码。支撑以逗号分隔的情势停止大量调取,大量上限为20个手机号码,大量调取相关于单条调取及时性稍有延迟,验证码类型的短信引荐使用单条调取的方式
  $request->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,大概是我使用的姿势不合错误吧,假如有大神搞得清,还劳烦赐教小弟,好人一生安然。
移入后,翻开Request\V20170525名目里有一个SendSmsRequest.php的源文件。请屏蔽第一行的空间命名。 也就是这一行namespace Dysmsapi\Reqest\V20170525;最后结果如下

<?php
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
//namespace Dysmsapi\Request\V20170525;//就是屏蔽这一行代码!!!!
class SendSmsRequest extends \RpcAcsRequest
{
  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;
  }
}

完成

运转试试吧

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

相关学习引荐:编程视频

以上就是阿里云PHP SMS短佩服务验证码发送办法详解的具体内容,更多请关注百分百源码网其它相关文章!

打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有150人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板