guzzlehttp5.3 and guzzlehttp6.7 , 同时共存。同时安装2个版本guzzlehttp

应用场景 php的组件有些时候 需要同时支持 guzzlehttp5.3 and guzzlehttp6.7 

you call install guzzlehttp5.3 and guzzlehttp6.7 ,

like this 
vendor/guzzlehttp53
vendor/guzzlehttp

第二步 2.
fillup/walmart-partner-api-sdk-php

replace 

use GuzzleHttp\   - > use GuzzleHttp53\

GuzzleHttp\\ -> GuzzleHttp53\\


第三部 2.

composer\autoload_psr4

add  GuzzleHttp53

autoload_psr4

    'GuzzleHttp53\\Subscriber\\Retry\\' => array($vendorDir . '/guzzlehttp53/retry-subscriber/src'),
    'GuzzleHttp53\\Stream\\' => array($vendorDir . '/guzzlehttp53/streams/src'),
    'GuzzleHttp53\\Ring\\' => array($vendorDir . '/guzzlehttp53/ringphp/src'),
    'GuzzleHttp53\\Command\\Guzzle\\' => array($vendorDir . '/fillup/guzzle-services/src'),
    'GuzzleHttp53\\Command\\' => array($vendorDir . '/guzzlehttp53/command/src'),
    'GuzzleHttp53\\' => array($vendorDir . '/guzzlehttp53/guzzle/src'),
 
autoload_static

.......................

guzzle 增加header

$client = new Client([
		    //域名或者访问的api接口地址
		    'base_uri' => 'http://localhost/test',
		    // 超时,可设置可不设置
		    'timeout'  => 2.0,
		]);
// $api可以为空,一般为api接口后缀,也可以直接写到上面的base_uri里面,
$response = $client->request('POST/GET', '$api', [
		'headers' => [
       		 'name' => 'info'
   		 ],
	    'query' => [
	        'username' => 'webben',
	        'password' => '123456',
	    ]
	]);




$postData = [
            'platform_no'=> $rms_platform_no,
            'uuid' => $uuid,
            "data_info" => $param
        ];
//方法1

$rs =  $this->http($url , 'POST' , ['headers'=>$headers,'body'=>json_encode($postData)]);


//方法2
$rs =  $this->http($url , 'POST' , ['headers'=>$headers,'json'=>$postData]);

也可以用

oauth-subscriber:使用OAuth 1.0(Guzzle 6+)签署Guzzle请求

guzzle-oauth2-subscriber:适用于Guzzle 4、5和6的OAuth 2.0客户端-不再需要依赖了! ( 没有验证过)

Guzzle OAuth 2.0订阅者 使用Guzzle 4、5、6、7和PHP 5.4、5.5、5.6、7.0、7.1、7.2、7.3和7.4进行了测试。 这是Guzzle的OAuth 2.0客户端,旨在与Guzzle 4、5、6、7和单个软件包中的所有将来版本100%兼容。 尽管我喜欢Guzzle,但它的接口不断变化,每12个月左右会引起重大的更改,因此,我创建了此程序包来帮助减少大多数第三方Guzzle依赖项带来的依赖地狱。 我写了官方的Guzzle OAuth 2.0插件,该插件仍在oauth2分支上,,但是我看到他们已经放弃了对master上的Guzzle <v6的支持,这促使我将其拆分回一个单独的软件包中。 。 特征 通过支持的一种授权类型(代码,客户端凭据,用户凭据,刷新令牌)获取访问令牌。 或者,您可以自己设置访问令牌。 支持刷新令牌(存储它们并使用它们来获取新的访问

========================

getEmitter方法添加头信息

     $client = new Client();
     $client->getEmitter()->attach(new Mock([new Response(200), new Response(201), new Response(202)]));
     $history = new History();
     $client->getEmitter()->attach($history);

中间件

function oauth_1_stack($token = NULL, $token_secret = NULL)
{
    $stack = HandlerStack::create();
 
    $middleware = new Oauth1([
        'consumer_key'    => 'consumer_key',
        'consumer_secret' => 'consumer_secret',
        'token'           => $token,
        'token_secret'    => $token_secret,
    ]);
    $stack->push($middleware);
 
    $options = [
      'handler' => $stack,
      'auth' => 'oauth'
    ];
 
    unset($stack, $middleware);
 
    return $options;
}
 
echo memory_get_usage() . "
"; // 4017480
 
$options = oauth_1_stack();
 
echo memory_get_usage() . "
"; // 4509824
 
unset($options);
 
echo memory_get_usage() . "
"; // 4480032

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值