아 리 클 라 우 드 PHP SMS 문자 서비스 인증 코드 전송 방법

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 폴 더 에 있 는 apisdk 의 aliyun-phop-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 폴 더 에 있 는 apisdk 디 렉 터 리 아래 Dysmsapi 를 건 네 주 는 폴 더 가 있 습 니 다.이 폴 더 를 열 면 Request 라 는 폴 더 가 있 습 니 다.이 Reques 를 보 세 요.의 폴 더 를 복사 하여 aliyun-phop-sdk-core 에 붙 여 넣 습 니 다.솔직히 아 리 운 이라는 사람 이 왜 이렇게 SDK 를 따로 설치 해 야 하 는 지 모 르 겠 어 요.제 가 사용 하 는 자세 가 틀 렸 나 봐 요.큰 신 이 알 면 동생 에 게 가르쳐 주 고 좋 은 사람 은 평생 평안 할 거 예요.
옮 긴 후 Request\V2070525 디 렉 터 리 에 SendSmsRequest.php 의 원본 파일 이 있 습 니 다.첫 줄 의 공간 이름 을 차단 하 십시오.즉,이 줄 namespace Dysmsapi\Reqest\\V2070525;마지막 효 과 는 다음 과 같다.

<?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 문자 서비스 인증 코드 발송 방법 입 니 다.여러분 께 도움 이 되 셨 으 면 좋 겠 습 니 다.궁금 한 점 이 있 으 시 면 메 시 지 를 남 겨 주세요.편집장 님 께 서 바로 답 해 드 리 겠 습 니 다.여기 서도 저희 사이트 에 대한 여러분 의 지지 에 감 사 드 립 니 다!

좋은 웹페이지 즐겨찾기