PHP使用短信SDK返回 ForbiddenUser not authorized to operate on the specified resource
代码如下:
<?php
header("Content-type:text/html;charset=utf-8");
//调用短信SDK
include_once 'aliyun-php-sdk-core/Config.php';
use Sms\Request\V20160927 as Sms;
require_once "public.php";
//$config = parse_ini_file('../conf/config.ini', true);
$config = $pgsql->config;
//下发短信
$phoneNumber = 'xxxxxxxxxxx';
$code = '854666';
$iClientProfile = DefaultProfile::getProfile($config['alicloudsms']['City'], $config['alicloudsms']['AccessKeyID'], $config['alicloudsms']['AccessKeySecret']);
$client = new DefaultAcsClient($iClientProfile);
$request = new Sms\SingleSendSmsRequest();
$request->setSignName($config['alicloudsms']['SignName']);/*签名名称*/
$request->setTemplateCode($config['alicloudsms']['VcodeTemplateCode']);/*模板code*/
$request->setRecNum($phoneNumber);/*目标手机号*/
$request->setParamString("{code:$code}");/*模板变量,数字一定要转换为字符串*/
try {
$response = $client->getAcsResponse($request);
print_r($response);
}
catch (ClientException $e) {
print_r($e->getErrorCode());
print_r($e->getErrorMessage());
}
catch (ServerException $e) {
print_r($e->getErrorCode());
print_r($e->getErrorMessage());
}
?>
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。