最近更新时间:2024-08-12 10:30:24
引入
composer require "aws/aws-sdk-php"
AWS签名demo
<?php
require 'vendor/autoload.php';
use Aws\Credentials\Credentials;
use Aws\Signature\SignatureV4;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
$ak = "Your AK"; // 请替换为您的AccessKey
$sk = "Your SK"; // 请替换为您的SecretKey
$service = "iam"; // 访问的服务
$region = "cn-beijing-6"; // 访问的区域
$credentials = new Credentials($ak, $sk);
$signer = new SignatureV4($service, $region);
$params = [
// 固定参数
"Action" => "ListUsers", // 接口名称
"Version" => "2015-11-01", // 接口版本
// 接口参数
"Marker" => "1",
"MaxItems" => "100",
];
ksort($params);
$queryString = http_build_query($params);
$request = new Request('GET', "http://$service.api.ksyun.com?$queryString", [
'Accept' => 'application/json',
'Host' => "$service.api.ksyun.com"
]);
$signedRequest = $signer->signRequest($request, $credentials);
$client = new Client();
$response = $client->send($signedRequest);
echo "Response Status: " . $response->getStatusCode() . "\n";
echo "Response Body: " . $response->getBody() . "\n";
纯净模式
鼠标选中内容,快速反馈问题