2017-02-22 45 views
0

誰かが私を助けることができますか?私はコードの下で要求をしようとしているが、何か起こる、任意のメッセージが表示されます。私は私のコードは、それが正しいだと信じて:cURLを使用したApiコールのリクエスト

public function subscribe(){ 
$json_url = 'https://apisandbox.cieloecommerce.cielo.com.br/1/sales/'; 

$json_string = json_encode(array(  

"MerchantOrderId"=>"2014113245231706", 
"Customer" => array(
    "Name" => "Comprador rec programada" 
), 

"Payment" => array(
    "Type" => "CreditCard", 
    "Amount" => 1500, 
    "Installments" => 1, 
    "SoftDescriptor" => "Assinatura Fraldas" 
)  


)); 


$ch = curl_init($json_url); 

$options = array(
CURLOPT_RETURNTRANSFER => true, 
CURLOPT_HTTPHEADER => array('Content-type: application/json') , 
CURLOPT_POSTFIELDS => $json_string 
); 

curl_setopt_array($ch, $options); 
$result = curl_exec($ch); // Getting jSON result string 

print_r($result);     

} 

は、サイトの指示にリンクを探す:

+0

あなたが必要なすべてのヘッダを送信しないので、あなたは、あなたのカールリクエスト...あなたは101を得る –

答えて

0

それはあなたが得る面白いものをHTTPステータスコードのようになります。

print_r(curl_getinfo($ch, CURLINFO_HTTP_CODE)); 
+0

夫婦複数のヘッダを送信する必要がAPIドキュメントでリクエストヘッダで ルックをデバッグShuld –

+0

@SimonMüllerはおそらくあまりにも速く、あまりにも不注意でした:-)あなたからの良い答え。 – pwunderlich

1

あなたがreiceiveますこれは:

[ 
    { 
    "Code": 114, 
    "Message": "The provided MerchantId is not in correct format" 
    } 
] 

このコードで:

function subscribe(){ 
$json_url = 'https://apisandbox.cieloecommerce.cielo.com.br/1/sales/'; 
$json_string = json_encode(
    array(  
     "MerchantOrderId"=>"2014113245231706", 
     "Customer" => array(
      "Name" => "Comprador rec programada" 
      ), 
     "Payment" => array(
      "Type" => "CreditCard", 
      "Amount" => 1500, 
      "Installments" => 1, 
      "SoftDescriptor" => "Assinatura Fraldas" 
      ) 
     ) 
    ); 


$headers = array(
    'Content-Type: application/json', 
    'MerchantId: xxxxxxxx-xxxxx-xxxxx-xxxxx-xxxxxxxxxxxx', 
    'MerchantKey: xxxxxxxx-xxxxx-xxxxx-xxxxx-xxxxxxxxxxxx', 
    'RequestId: xxxxxxxx-xxxxx-xxxxx-xxxxx-xxxxxxxxxxxx' 
    ); 

$ch = curl_init($json_url); 
$options = array(
    CURLOPT_RETURNTRANSFER => true, 
    CURLOPT_HTTPHEADER => $headers, 
    CURLOPT_POSTFIELDS => $json_string 
    ); 

curl_setopt_array($ch, $options); $result = curl_exec($ch); 
print_r($result); 
} 
subscribe() 
関連する問題