guzzle http异步 post

锺离嘉容
2023-12-01
 
 
use GuzzleHttp\Pool;
use GuzzleHttp\Client;
//use GuzzleHttp\Psr7\Request;
use Psr\Http\Message\ResponseInterface;
use GuzzleHttp\Exception\RequestException;
$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() . "\n");
Log::info($reason = $res->getReasonPhrase());
$body = $res->getBody();

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

} else {

} },     function (RequestException $e) {
      Log::info('exception:'.$e->getMessage() . "\n");
      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() . "\n");
    //$reason = $res->getReasonPhrase();
    $body = $res->getBody();
    Log::info('body'. $body); },
    function (RequestException $e) {
      Log::info($e->getMessage() . "\n");
      Log::info($e->getRequest()->getMethod());
  });

  $promise->wait();
 
 
 类似资料: