2017-05-10 52 views
-6

我有一個家庭作業,現在不怎麼做。我需要連接vtiger rest api並顯示一些字段,但不知道如何做到這一點。也許有人有一些代碼示例或類似的東西?我已閱讀文檔,但不知道如何連接和抓取字段。有人幫忙?如何創建連接,vtiger,php

+1

在(因此)我們希望你去嘗試自己**編寫代碼**。後** [做更多的研究](//meta.stackoverflow.com/questions/261592)**如果你有問題,你可以**發佈你已經嘗試**與清楚的解釋是什麼是'工作**並提供[** Minimal,Complete和Verifiable示例**](// stackoverflow.com/help/mcve)。我建議閱讀[問]一個好問題和[完美問題](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/)。另外,一定要參加[遊覽]並閱讀[this](// meta.stackoverflow.com/questions/347937/)**。 –

+1

看起來你有一種習慣讓別人爲你做你的工作。如果你自己不這樣做,你如何期望學習任何東西? –

+0

家庭作業是指想要走得更遠的人;這個意思是「你」,那不是「我們的」作業,它是「你的」。 –

回答

0

您可以使用下面的示例代碼。欲瞭解更多信息,請閱讀webservice文檔! https://wiki.vtiger.com/index.php/Webservices_tutorials

function callvtiger($url, $params, $type = "GET") 
{ 
    $is_post = 0; 
    if ($type == "POST") { 
     $is_post = 1; 
     $post_data = $params; 
    } else { 
     $url = $url . "?" . http_build_query($params); 
    } 
    $ch = curl_init($url); 
    if (!$ch) { 
     die("Cannot allocate a new PHP-CURL handle"); 
    } 
    if ($is_post) { 
     curl_setopt($ch, CURLOPT_POST, $is_post); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); 
    } 

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    $data = curl_exec($ch); 

    $return = null; 
    if (curl_error($ch)) { 
     $return = false; 
    } else { 
     $return = json_decode($data, true); 
    } 

    curl_close($ch); 

    return $return; 
} 
$userName = "admin"; 
$userAccessKey = "bjwedjndwejndwjnd"; 
$Url = 'http://vtigerurl/webservice.php'; 


$sessionData = callvtiger($Url, array(
    "operation" => "getchallenge", 
    "username" => $userName 
)); 
$challengeToken = $sessionData['result']['token']; 
$generatedKey = md5($challengeToken . $userAccessKey); 
$dataDetails = call($endpointUrl, array(
    "operation" => "login", 
    "username" => $userName, 
    "accessKey" => $generatedKey 
), "POST"); 
$sessionid  = $dataDetails['result']['sessionName']; 
$phoneNumber = "0014242222222"; 
$query = "SELECT accountname,id FROM Accounts where phone = '$phoneNumber'"; 


$getUserDetail = callvtiger($Url, array(
    "operation" => "query", 
    "sessionName" => $sessionid, 
    'query' => $query 
)); 

$response = $getDetail['result'][0];