2016-12-27 55 views
0
public function create_plan_paystack(){ 
    $data = array(
     "name"=> "Monthly retainer", "interval"=>"monthly", "amount"=>500,'currency'=>'NGN','description'=>'test' 
    ); 

    $sendjson = array(); 
    $opts = array(
     'http'=>array(
      'header'=> ["Authorization: Bearer ".$this->config->item('paystack_sk')."\r\n" ,"Content-Type: application/json\r\n"] , 
      'method' => 'GET', 
      'content' => json_encode($data)// http_build_query($data), 
     ) 
    ); 
    print_r($opts); 
    $context = stream_context_create($opts); 
    $json = file_get_contents("https://api.paystack.co/plan/".'PLN_lp20ulqhzezihrc',false,$context); 

    $obj = json_decode($json); 
    print_r($obj); 
} 

我想发布$data数组为json。 “https://developers.paystack.co/docs/create-plan”这是他们给予.plaese帮助我的方式。在php中发布数据为json

+0

'方法'=> 'POST',我chaged张贴方法 –

回答

0

使用卷曲

$data = array("name" => "Hagrid", "age" => "36");                  
    $data_string = json_encode($data);                     

    $ch = curl_init('http://api.local/rest/users');                  
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                  
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                  
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(                   
     'Content-Type: application/json',                     
     'Content-Length: ' . strlen($data_string))                  
    );                             

    $result = curl_exec($ch); 

或者您可以使用这些

https://github.com/yabacon/paystack-php

https://github.com/MalikAbiola/paystack-php-lib