定制 ion-bazan/aliyun-http-signer 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ion-bazan/aliyun-http-signer

最新稳定版本:v1.3.0

Composer 安装命令:

composer require ion-bazan/aliyun-http-signer

包简介

PSR-7-compatible Alibaba Cloud API Gateway request signing implementation. Integrates with Guzzle ⛽️ and HttPlug 🐘.

README 文档

README

Latest version GitHub Workflow Status PHP version Codecov Mutation testing badge Scrutinizer Code Quality Downloads License

This library implements Alibaba Cloud API Gateway request signature calculation for PSR-7 compatible requests. It integrates with Guzzle and HttPlug but can be used with any PSR-7-compatible client.

Installation

Use Composer to install the package using:

composer require ion-bazan/aliyun-http-signer

Usage

Symfony integration

The easiest way to integrate the package with Symfony is using GuzzleBundleAliyunSignerPlugin with Guzzle Bundle.

To use it with HttplugBundle or any other Bundle, simply register RequestSigner, Key and RequestSignerPlugin as services and inject the credentials to the Key service.

Sign a PSR-7-compatible API request

<?php

require_once 'vendor/autoload.php';

use IonBazan\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);
}

Sign an API request using Guzzle middleware

<?php

require_once 'vendor/autoload.php';

use GuzzleHttp\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');

Sign an API request using HttPlug plugin

<?php

require_once 'vendor/autoload.php';

use Http\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);

Bugs & issues

If you found a bug or security vulnerability, please open an issue

Contributing

Please feel free to submit Pull Requests adding new features or fixing bugs.

Please note that code must follow PSR-1, PSR-2, PSR-4 and PSR-7.

统计信息

  • 总下载量: 45.44k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-04-28