guzzle / plugin-mardy-hmac
Guzzle 日志插件,用于将 HMAC 注入到头部
dev-master
2014-06-20 22:03 UTC
Requires
- guzzle/guzzle: 3.8.*
- mardy-git/hmac: 2.*
This package is not auto-updated.
Last update: 2024-09-14 13:57:40 UTC
README
此插件将 HMAC 哈希/数据/时间值直接注入到 Guzzle 请求的头部。
Mardy-Git Hmac: https://github.com/mardy-git/hmac
Guzzle: https://github.com/guzzle/guzzle
安装
要安装此插件,请使用 composer,并在您的 composer.json 文件中添加以下内容:
"require": {
"guzzle/plugin-mardy-hmac": "dev-master"
}
使用示例
use Mardy\Hmac\Manager; use Mardy\Hmac\Adapters\Hash; use Mardy\HmacPlugins\HmacGuzzlePlugin; use Guzzle\Http\Client; $manager = new Manager(new Hash); $client = new Client('http://127.0.0.1'); $this->manager->ttl(0) ->data('test') //string containing either a URI or other related data string ->time(1396901689) //timestamp for now or whatever other time you want to base the hmac on ->key('1234'); //a secure key string that is kept private in the database or config files $client->addSubscriber(new HmacGuzzlePlugin($this->manager)); $request = $client->get(); $request->send(); //to check what data has been placed in the header it can be retrieved with by using the following code echo $request->getHeader('Mardy-Hmac-Hash'); echo $request->getHeader('Mardy-Hmac-Time'); echo $request->getHeader('Mardy-Hmac-Data');