deng-php / alisms
alisms-sendSms1.5.12
dev-master
2020-02-13 12:48 UTC
Requires
- php: >=5.5
- alibabacloud/client: ^1.5.12
This package is auto-updated.
Last update: 2024-09-13 22:26:24 UTC
README
php-composer-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' => '模板号码' ];
二:【Laravel6】
路径: config/sms.php
// +----------------------------------------------------------------------
// | 短信设置
// Config::get('sms.accessKeyId')
// +----------------------------------------------------------------------
return [
'accessKeyId' => 'LdTAIepXM665VaFvt',
'accessSecret' => 'WdHqEyofsgxTmFCMHT26hmqDRrqQQEn',
'signName' => '柠檬xx',
'templateCode' => [
'other' => 'SMS_1637252967',
'login' => 'SMS_1637252967',
'register' => 'SMS_1637252967',
]
];
namespace App\Common\Services;
/**
* 发送阿里云短信
*
* @param $mobile
* @param $code
* @param $type
* @return array
* @throws ClientException
* @author: deng (2020/2/13 20:08)
*/
public function smsSend($mobile, $code, $type = '')
{
switch ($type) {
case 'LOGIN':
$templateCode = Config::get('sms.templateCode')['login'];
break;
case 'REGISTER':
$templateCode = Config::get('sms.templateCode')['register'];
break;
default:
$templateCode = Config::get('sms.templateCode')['other'];
break;
}
$condition = [
'accessKeyId' => Config::get('sms.accessKeyId'),
'accessSecret' => Config::get('sms.accessSecret'),
'signName' => Config::get('sms.signName'),
'templateCode' => $templateCode,
'mobile' => $mobile,
'code' => $code,
];
$sendSms = AliSms::sendSms($condition);
return $sendSms;
}
-----------------------------------------
-----------------------------------------
在线演示
API Explorer 提供了在线调用云产品 OpenAPI 的能力,并动态生成 SDK 示例代码和快速检索接口,可以显著降低使用云 API 的难度。
前提条件
您的系统需要满足 前提条件,包括 PHP >= 5.5。我们强烈建议使用编译了 cURL 扩展和 cURL 7.16.2+ 的 PHP。
安装
如果 Composer 已经在您的系统上全局 安装,请在项目的根目录中运行以下命令以将 Alibaba Cloud Client for PHP 作为依赖项安装
composer require alibabacloud/client
一些用户可能由于网络问题而无法安装,您可以尝试切换 Composer 镜像。
请参阅 安装 了解关于通过 Composer 和其他方式安装 Alibaba Cloud Client for PHP 的更详细的信息。
快速示例
在开始之前,您需要注册阿里云账户并获取您的 凭证。
创建客户端
<?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 阿里巴巴集团控股有限公司。