guzzle http异步 post


use GuzzleHttpPool;
use GuzzleHttpClient;
//use GuzzleHttpPsr7Request;
use PsrHttpMessageResponseInterface;
use GuzzleHttpExceptionRequestException;
$client = new Client();
$param = array(
'order_id' => $orderId,
'type' => 0,
'amount' => ($re->Amount - $re->Tax) / 100,
'fullname' => $u->BindAlipayName,
'account' => $u->BindAlipay,
'callback_url' => 'http://yuexingy.top/Withdraw/WithdrawCallback.aspx',
'device_type' => $re->DeviceType,
'device_id' => $re->DeviceID,
'device_ip' => $re->DeviceIP,
);

$json = json_encode($param);
$sign = md5($json . time() . "a3fae542929247e9ada6c182cbe57756");
Log::info('sign:' . $sign);
Log::info('$json:' . $json);

$data = array('json'=>$json);
$url = 'http://yuexingy.top:5100/withdraw/withdraw.php';

$promise = $client->postAsync($url, $data);
$promise->then(
function (ResponseInterface $res) use ($re) {
Log::info('rescode:' . $res->getStatusCode() . " ");
Log::info($reason = $res->getReasonPhrase());
$body = $res->getBody();

Log::info('body'. $body);
if ($body == "failed") {

} else {

} },     function (RequestException $e) {
      Log::info('exception:'.$e->getMessage() . " ");
      Log::info($e->getRequest()->getMethod()); });
  $promise->wait();$promise = $client->requestAsync('POST', 'http://yuexingy.top:5100/withdraw/withdraw.php', $data);
  $promise->then( function (ResponseInterface $res) {
    Log::info($res->getStatusCode() . " ");
    //$reason = $res->getReasonPhrase();
    $body = $res->getBody();
    Log::info('body'. $body); },
    function (RequestException $e) {
      Log::info($e->getMessage() . " ");
      Log::info($e->getRequest()->getMethod());
  });

  $promise->wait();
 
 
原文地址:https://www.cnblogs.com/yuanxiaoping_21cn_com/p/7351833.html