DDR爱好者之家 Design By 杰米

首先安装

composer require alibabacloud/sdk

接着看alibabacloud官网文档

https://packagist.org/packages/alibabacloud/sdk

示例

My_composer_aliyunsms.php

<"ali")
 */
class My_composer_aliyunsms
{
  /**
   * 发送短信验证码
   */
  public function sendCode($config,$phone,$code)
  {
    $param = [
      'code' => $code
    ];
    AlibabaCloud::accessKeyClient($config['accessKeyId'], $config['accessSecret'])
      ->regionId($config['regionId'])
      ->asGlobalClient();

    try {
      $result = AlibabaCloud::rpcRequest()
        ->product('Dysmsapi')
        ->version('2017-05-25')
        ->action('SendSms')
        ->method('POST')
        ->options([
          'query' => [
            'PhoneNumbers' => $phone,
            'SignName' => $config['SignName'],
            'TemplateCode' => $config['TemplateCode'],
            'TemplateParam' => json_encode($param)
          ],
        ])
        ->request();
      return $result->toArray();
    } catch (ClientException $e) {
      echo $e->getErrorMessage() . PHP_EOL;
    } catch (ServerException $e) {
      echo $e->getErrorMessage() . PHP_EOL;
    }
  }
}

demo

 include 'My_composer_aliyunsms.php';
 $sms = new My_composer_aliyunsms();
 $phone='xxxxxx';
 $code='99999'; 
 $config = [
  'accessKeyId' => 'LTAIMje******hS',
  'accessSecret' => 'fMuQTLUrKQN******Z2m07',
  'SignName' => '****',
  'TemplateCode' => 'SMS_****04',
  'regionId' => 'cn-hangzhou'
 ];
 $re = $sms->sendCode($config,$phone,$code);  
 var_dump($re);

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米