zoukankan      html  css  js  c++  java
  • 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();
     
     
  • 相关阅读:
    Centos/RHEL上查看主板型号
    搞定:Enter passphrase for key提示
    Netd学习笔记
    Android查看stdout 和stderr
    Android中java层使用LocalSocket和底层进行通讯
    测试:通过Office world 2007发布博文
    Android中的socket本地通讯框架
    【转】DHCP的请求过程
    Android中的java层的线程暂停和恢复实现
    转:SpringMVC 上传文件出现 Provisional headers are shown 和 response 数据 无法输出问题
  • 原文地址:https://www.cnblogs.com/yuanxiaoping_21cn_com/p/7351833.html
Copyright © 2011-2022 走看看