阿里云短信发送示例

  • 之前一直用的是云片的短信,最近短信有需求,经过选择更改为阿里云通信,

  • 阿里短信发送官方API

https://api.alidayu.com/docs/api.htm?spm=a3142.7629065.4.7.cbhv6H&apiId=25450
  • 不同平台流程基本都是一样
首先要申请自己的

短信 【签名】->【短信模板】
           ->获取账号的【KEYSECRET           ->获取模板ID如:(SMS_1135020222,模板变量替换)

sdk申请账户签名这些都在账号控制台
  • 官方请求实例
$c = new TopClient;
$c->appkey = $appkey;
$c->secretKey = $secret;
$req = new AlibabaAliqinFcSmsNumSendRequest;
$req->setExtend("123456");
$req->setSmsType("normal");
$req->setSmsFreeSignName("阿里大于");
$req->setSmsParam("{\"code\":\"1234\",\"product\":\"alidayu\"}");
$req->setRecNum("13000000000");
$req->setSmsTemplateCode("SMS_585014");
$resp = $c->execute($req);
  • 推荐一个封装好的阿里短信接口
composer require flc/dysms

use Flc\Dysms\Client;
use Flc\Dysms\Request\SendSms;

$config = [
    'accessKeyId'    => 'LTAIbVA2LRQ1tULr',
    'accessKeySecret' => 'ocS48RUuyBPpQHsfoWokCuz8ZQbGxl',
];

$client  = new Client($config);
$sendSms = new SendSms;
$sendSms->setPhoneNumbers('1500000000');
$sendSms->setSignName('坑');
$sendSms->setTemplateCode('SMS_77670013');
$sendSms->setTemplateParam(['code' => rand(100000, 999999)]);
$sendSms->setOutId('demo');

print_r($client->execute($sendSms));

你可能感兴趣的:(PHP)