2016-04-13 41 views
0

我在Bitrise上工作,我試圖在PHP中使用那裏的API。 於是,我就這個shell命令在PHP轉換:PHP Curl與JSON數據

curl https://www.bitrise.io/app/[APP-SLUG]/build/start.json --data '{"hook_info":{"type":"bitrise","api_token":"[API-TOKEN]"},"build_params":{"tag":"1.0.0"}}' 

有人能幫助我嗎?我的結果每次都是錯誤的。使用 我的代碼:

$data_json = '{"hook_info":{"type":"bitrise","api_token":"[API-TOKEN]"},"build_params":{"tag":"1.0.0"}}'; 
$url = 'https://www.bitrise.io/app/[APP-SLUG]/build/start.json'; 

$ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    $response = curl_exec($ch); 
    curl_close($ch); 
    var_dump($response); 

Bitrise給我的「祕密」 URL和數據信息,在這裏它只是一個給定的URL和數據的示例模板。

謝謝。

回答

0

,捲曲使用的代碼IM是因爲這一點,唯一的區別是標題

$contact = json_decode(file_get_contents("https://api.xxxxx.com/contacts/v1/search/query")); 
if ($contact->contacts){ 
     $vid = $contact->contacts['0']->vid; 


     //Need to populate these varilables with values from the form. 
     $str_post = '{"properties": [{"property": "resume_link", "value": "'.$link.'"}]} '; 

     //replace the values in this URL with your portal ID and your form GUID 
     $endpoint = 'https://api.xxxx.com/contacts/v1/contact/vid/' . $vid . '/profile?hapikey=xxxx'; 

     $ch = @curl_init(); 
     @curl_setopt($ch, CURLOPT_POST, true); 
     @curl_setopt($ch, CURLOPT_POSTFIELDS, $str_post); 
     @curl_setopt($ch, CURLOPT_URL, $endpoint); 
     @curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/javascript')); 
     @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
     @curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS ,4000); 
     @curl_setopt($ch, CURLOPT_TIMEOUT_MS, 4000); 
     $response = @curl_exec($ch); //Log the response from HubSpot as needed. 
     @curl_close($ch); 

它返回我的數據,你確定端點返回true時成功??