站長資訊網
        最全最豐富的資訊網站

        阿里云PHP SMS短信服務驗證碼發送方法詳解

        阿里云PHP SMS短信服務驗證碼發送方法詳解

        開通SMS服務

        首先去這個網站開通阿里云的SMS短信服務:https://www.aliyun.com/product/sms?spm=5176.8142029.388261.295.vU5T5g

        相關學習推薦:php編程(視頻)

        創建簽名、模板

        要使用短信服務器需要先創建簽名和模板,并提交給阿里云審核通過才可以正常使用短信服務。

        阿里云PHP SMS短信服務驗證碼發送方法詳解

        創建簽名

        創建簽名的時候注意一下簽名名稱,其他的話就不累贅了。

        阿里云PHP SMS短信服務驗證碼發送方法詳解

        記住簽名名稱

        現在請記住你創建的簽名名稱,一會在代碼中需要使用。

        創建模板

        創建模板也很簡單,阿里云已經把要如何填寫寫的很清楚了。

        阿里云PHP SMS短信服務驗證碼發送方法詳解

        查看并記住模板CODE

        返回你的控制臺,當你的模板審核通過時這就會出現大于0的數。

        點擊這個數,會進入模板管理面板就能看到你的模板CODE了,請記住他。

        阿里云PHP SMS短信服務驗證碼發送方法詳解

        阿里云PHP SMS短信服務驗證碼發送方法詳解

        創建并記住KeyId和KeySecret

        到控制臺,把鼠標放到右上角你的用戶名的位置會出現一個accessKeySecret點進去就可以創建KeyId和KeySecret了,如果他提醒你用RAM安全什么的,你看你要不要給你的員工分配權限,如果要的話就用RAM,否則就直接點擊繼續使用就行了。

        阿里云PHP SMS短信服務驗證碼發送方法詳解

        阿里云PHP SMS短信服務驗證碼發送方法詳解

        下載阿里云短信服務器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短信服務驗證碼發送方法詳解

        創建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,可能是我使用的姿勢不對吧,如果有大神搞得清,還勞煩賜教小弟,好人一生平安。
        移入后,打開RequestV20170525目錄里有一個SendSmsRequest.php的源文件。請屏蔽第一行的空間命名。 也就是這一行namespace DysmsapiReqestV20170525;最后效果如下

        <?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 DysmsapiRequestV20170525;//就是屏蔽這一行代碼?。。?! 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短信服務驗證碼發送方法詳解
        阿里云PHP SMS短信服務驗證碼發送方法詳解

        相關學習推薦:編程視頻

        贊(0)
        分享到: 更多 (0)
        網站地圖   滬ICP備18035694號-2    滬公網安備31011702889846號
        主站蜘蛛池模板: 精品无码人妻一区二区三区| 91麻豆精品国产自产在线观看一区 | 国产一精品一AV一免费| 国产综合精品久久亚洲| 久久er热视频在这里精品| 日韩人妻无码精品久久久不卡| 男女男精品视频网站在线观看| 99在线观看视频免费精品9| 国产高清在线精品二区一| 精品人妻人人做人人爽| 亚洲精品无码mv在线观看网站| 国产原创精品 正在播放| 成人国产精品日本在线观看| japanese乱人伦精品| 国产欧美精品一区二区三区| 亚洲av无码乱码国产精品fc2 | 国产精品亚洲а∨无码播放 | 久久精品国产亚洲AV不卡| 国产精品内射久久久久欢欢| 91自慰精品亚洲| 欧美巨大黑人精品videos| 久久精品一区二区三区不卡| 99精品免费视频| 国产精品日韩欧美一区二区三区| 久久久久亚洲精品天堂| 无码人妻精品一区二区三区99仓本 | 久久精品国产亚洲网站| 91麻豆精品国产| 99精品国产一区二区三区2021 | 亚洲精品午夜国产VA久久成人| 亚洲国产精品国产自在在线| 亚洲国产av无码精品| 亚洲午夜国产精品无码| 夜夜高潮夜夜爽国产伦精品| 亚洲精品二三区| 亚洲爆乳无码精品AAA片蜜桃| 亚洲国产精品一区二区第一页免| 欧美成人精品欧美一级乱黄一区二区精品在线 | 国产精品香蕉在线观看| 国产精品秘入口福利姬网站| 国产亚洲精品资在线|