douju1852 2015-11-12 14:40
浏览 199

在Laravel中使用Guzzle而不是cURL

I was using Virtual Pos on my own classes. But i want to decide to convert my project to laravel project.

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $this->_server);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 90);
curl_setopt($ch, CURLOPT_POSTFIELDS, $vPOSData);

$ch = curl_exec($ch);
@curl_close ($ch);
echo $ch;

When I'm using this code directly in Laravel it is not working. When I check internet, Guzzle is best choice for handling this process.

How can I do it exactly in Guzzle ?

UPDATE:

Here is my data

array:20 [
"clientid" => "*********"
"amount" => "27.87"
"oid" => 14532858
"okUrl" => "http://laravel/tr/order/**1/success"
"failUrl" => "http://laravel/tr/order/**1/fail"
"islemtipi" => "Auth"
"taksit" => ""
"commission" => null
"storetype" => "3d_pay"
"cardHolder" => "cihan küsmez"
"pan" => "4531****31442283"
"Ecom_Payment_Card_ExpDate_Month" => "12"
"Ecom_Payment_Card_ExpDate_Year" => "18"
"cv2" => "001"
"rnd" => "0.88093200 1447345882"
"hash" => "1phjMQWYUkmJRXj283lonh7GAZE="
"lang" => "tr"
"currency" => 949
"customerIP" => "127.0.0.1"
"vpos_name" => "****** vPOS"

]

when i post with guzzle like the code below i'm getting a blank page.

    $client = new Client();
    return $client->post($this->_server, $vPOSData);
  • 写回答

2条回答 默认 最新

  • douba1067 2015-11-12 14:54
    关注

    If you still want to request with cURL

    First make sure you have enabled cURL extension

    cURL Request Function

    function httpPost($url,$params)
    {
      $postData = '';
       //create name value pairs seperated by &
       foreach($params as $k => $v) 
       { 
          $postData .= $k . '='.$v.'&'; 
       }
       rtrim($postData, '&');
    
        $ch = curl_init();  
    
        curl_setopt($ch,CURLOPT_URL,$url);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
        curl_setopt($ch,CURLOPT_HEADER, false); 
        curl_setopt($ch, CURLOPT_POST, count($postData));
            curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);    
    
        $output=curl_exec($ch);
    
        curl_close($ch);
        return $output;
    
    }
    

    How to use the function

    $params = array(
       "name" => "Ravishanker Kusuma",
       "age" => "32",
       "location" => "India"
    );
    
    echo httpPost("http://hayageek.com/examples/php/curl-examples/post.php",$params);
    

    reference : http://hayageek.com/php-curl-post-get/

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看