luyisuifeng/aliyun-php-sdk-sms

This is a composer/packagist fot Aliyun-Sms OpenAPI

v1.0.1 2016-11-07 08:05 UTC

This package is not auto-updated.

Last update: 2024-04-27 18:09:28 UTC


README

阿里云短信服务提供composer解决方案

install

$ composer require luyisuifeng/aliyun-php-sdk-sms

发布v1.0.1版本,修复exception命名空间问题,增加demo

#demo use Aliyun\Core\Profile\DefaultProfile;
use Aliyun\Core\DefaultAcsClient;
use Aliyun\Core\Exception\ClientException;
use Aliyun\Core\Exception\ServerException;
use Aliyun\Core\Regions\Endpoint;
use Aliyun\Core\Regions\EndpointProvider;
use Aliyun\Core\Regions\EndpointConfig;
use Aliyun\Core\Sms\Request\V20160927\SingleSendSmsRequest;
$iClientProfile = DefaultProfile::getProfile('cn-hangzhou', 'your accessKeyId', 'your accessSecret);
$client = new DefaultAcsClient($iClientProfile);
$config = new EndpointConfig();
$endpoint = new Endpoint('cn-hangzhou', $config->getRegionIds(), $config->getProductDomains());
$endpoints = array( $endpoint );
EndpointProvider::setEndpoints($endpoints);
$request = new SingleSendSmsRequest();
$request->setSignName('XXXX'); //签名名称
$request->setTemplateCode('SMS_123456'); //模板id
$request->setRecNum('138xxx');//目标手机号
$request->setParamString("{"goodname":"商品名","specinfo":"商品属性"}");//模板变量,数字一定要转换为字符串
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());
}