安装:composer require alibabacloud/dysmsapi-20170525 2.0.24
官方文档:短信服务_SDK中心-阿里云OpenAPI开发者门户 (aliyun.com)
特别注意:传入参数获得值形式
这样也不行
$sendSmsRequest = new SendSmsRequest($addData);
还有一个大坑:
官方给的参数字段首字母是大写,实际只传参首字母只能是小定
正确是:首字母小写
正确:
$PhoneNumbers = $postData['PhoneNumbers'];
$signName = $postData['signName'];
try {
$sendSmsRequest = new SendSmsRequest([
"phoneNumbers" => $PhoneNumbers,
"signName" => $signName,
"templateCode" => 'SMS_xxx',
"templateParam" => json_encode(array('code' => $code))
]);
$runtime = new RuntimeOptions([]);
错误:
try {
$sendSmsRequest = new SendSmsRequest([
"phoneNumbers" => $postData['phoneNumbers'],
"signName" => $postData['signName'],
"templateCode" => 'SMS_xxxx',
"templateParam" => json_encode(array('code' => $code))
]);
$runtime = new RuntimeOptions([]);
参考:php利用阿里云短信SDK实现短信发送功能_php 阿里云短信-CSDN博客