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 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料