deng-tp5 / alisms
alisms-sendSms1.5.12
dev-master
2019-08-17 03:30 UTC
Requires
- php: >=5.5
- alibabacloud/client: ^1.5.12
This package is auto-updated.
Last update: 2024-09-17 15:08:54 UTC
README
php-composer-tp5-alisms 英文 | 简体中文
阿里云PHP客户端
阿里云PHP客户端是一个帮助PHP开发者管理凭证和发送请求的客户端工具,它依赖于阿里云SDK for PHP。
ThinkPhp5.1
1. application/common.php文件
/** * 发送验证码公共方法 * @param $mobile * @param $code * @return array * @throws ClientException * @author deng (2019/8/17 10:55) */ function sendSms($mobile, $code) { $condition = [ 'accessKeyId' => config('sms.accessKeyId'), 'accessSecret' => config('sms.accessSecret'), 'code' => $code, 'mobile' => $mobile, 'signName' => config('sms.signName'), 'templateCode' => config('sms.templateCode'), ]; $sendSms = AliSms::sendSms($condition); return $sendSms; }
2. config/sms.php
// +---------------------------------------------------------------------- // | 短信设置 // +---------------------------------------------------------------------- return [ 'accessKeyId' => 'LTAIepxxx5VaFvt', 'accessSecret' => 'WHqEyofsxxxxxxxMHT26hmqDRrqQQEn', 'signName' => '模板名称', 'templateCode' => '模板号码' ];
在线演示
API Explorer提供在线调用云产品OpenAPI的能力,并动态生成SDK示例代码和快速检索接口,可以显著降低使用云API的难度。
先决条件
您的系统需要满足先决条件,包括PHP >= 5.5。我们强烈建议使用编译了cURL扩展和cURL 7.16.2+的PHP。
安装
如果Composer已经在您的系统上全局安装,请在项目的根目录中运行以下命令以将阿里云客户端作为依赖项安装
composer require alibabacloud/client
由于网络问题,某些用户可能无法安装,您可以尝试切换Composer镜像。
有关通过Composer和其他方式安装阿里云客户端的详细信息,请参阅安装。
快速示例
在开始之前,您需要注册阿里云账户并获取您的凭证。
创建客户端
<?php use AlibabaCloud\Client\AlibabaCloud; AlibabaCloud::accessKeyClient('accessKeyId', 'accessKeySecret')->asDefaultClient();
ROA请求
<?php use AlibabaCloud\Client\AlibabaCloud; use AlibabaCloud\Client\Exception\ClientException; use AlibabaCloud\Client\Exception\ServerException; try { $result = AlibabaCloud::roa() ->regionId('cn-hangzhou') // Specify the requested regionId, if not specified, use the client regionId, then default regionId ->product('CS') // Specify product ->version('2015-12-15') // Specify product version ->action('DescribeClusterServices') // Specify product interface ->serviceCode('cs') // Set ServiceCode for addressing, optional ->endpointType('openAPI') // Set type, optional ->method('GET') // Set request method ->host('cs.aliyun.com') // Location Service will not be enabled if the host is specified. For example, service with a Certification type-Bearer Token should be specified ->pathPattern('/clusters/[ClusterId]/services') // Specify path rule with ROA-style ->withClusterId('123456') // Assign values to parameters in the path. Method: with + Parameter ->request(); // Make a request and return to result object. The request is to be placed at the end of the setting print_r($result->toArray()); } catch (ClientException $exception) { print_r($exception->getErrorMessage()); } catch (ServerException $exception) { print_r($exception->getErrorMessage()); }
RPC请求
<?php use AlibabaCloud\Client\AlibabaCloud; use AlibabaCloud\Client\Exception\ClientException; use AlibabaCloud\Client\Exception\ServerException; try { $result = AlibabaCloud::rpc() ->product('Cdn') ->version('2014-11-11') ->action('DescribeCdnService') ->method('POST') ->request(); print_r($result->toArray()); } catch (ClientException $exception) { print_r($exception->getErrorMessage()); } catch (ServerException $exception) { print_r($exception->getErrorMessage()); }
文档
问题
打开问题,不符合指南的问题可能会立即被关闭。
更新日志
每个版本的详细更改都记录在发行说明中。
贡献
在提交拉取请求之前,请务必阅读贡献指南。
参考
许可
版权所有1999-2019阿里巴巴集团控股有限公司。