guzzle http异步 post

 
 
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();
 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值