PHP code example of ion-bazan / aliyun-http-signer
1. Go to this page and download the library: Download ion-bazan/aliyun-http-signer library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ion-bazan / aliyun-http-signer example snippets
onBazan\AliyunSigner\Key;
use IonBazan\AliyunSigner\RequestSigner;
use Psr\Http\Message\RequestInterface;
function signRequest(RequestInterface $request): RequestInterface
{
// Provide credentials
$appId = '12345678';
$secret = base64_encode('secret');
// Create signer
$signer = new RequestSigner(new Key($appId, $secret));
return $signer->signRequest($request);
}
uzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use IonBazan\AliyunSigner\Key;
use IonBazan\AliyunSigner\RequestSigner;
use IonBazan\AliyunSigner\Guzzle\RequestSignerMiddleware;
// Provide credentials
$appId = '12345678';
$secret = base64_encode('secret');
// Create signer and middleware
$signer = new RequestSigner(new Key($appId, $secret));
$middleware = new RequestSignerMiddleware($signer);
$stack = HandlerStack::create();
$stack->push($middleware);
$client = new Client(['handler' => $stack]);
$response = $client->get('https://example.com/api/v1/test');
ttp\Client\Common\PluginClient;
use Http\Discovery\HttpClientDiscovery;
use IonBazan\AliyunSigner\Key;
use IonBazan\AliyunSigner\RequestSigner;
use IonBazan\AliyunSigner\HttPlug\RequestSignerPlugin;
// Provide credentials
$appId = '12345678';
$secret = base64_encode('secret');
// Create signer and plugin
$signer = new RequestSigner(new Key($appId, $secret));
$plugin = new RequestSignerPlugin($signer);
$pluginClient = new PluginClient(
HttpClientDiscovery::find(),
[$plugin]
);
$pluginClient->sendRequest($request);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.