1

我正在尝试像这样使用 PHP CURL 调用 vtiger 网络服务。

$selectQuery = urlencode("SELECT title,firstname,lastname FROM Contacts;");
            $curl = curl_init($data['url'].'/webservice.php?operation=query&sessionName='.$this->sessionName.'&query='.$selectQuery); 
            curl_setopt($curl, CURLOPT_FAILONERROR, true); 
            curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/json'));
            curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0");
            curl_setopt($curl, CURLINFO_HEADER_OUT, true);
            curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); 
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);   
            $query = curl_exec($curl); 
            //$query = json_decode($query);
            print_r($query);

但我得到了错误

error:The requested URL returned error: 406 Not Acceptable

我只是在执行以下网址中提到的所有过程

http://community.vtiger.com/help/vtigercrm/developers/third-party-app-integration.html#list-types-operation

有人知道相同的解决方案吗?

4

1 回答 1

-1

嗨根巧妙请尝试

我的代码

$endURL = 'http://192.168.192.140/vtigercrm71'; //use ur url
$userName = 'admin'; //use ur username
$userAccessKey = 'h3fNwMr0Nc2hNQOL'; //use ur useraccesskey

$url = $endURL . '/webservice.php?operation=getchallenge&username=' . $userName;
$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, 0);
$output = curl_exec($ch);
curl_close($ch);
$res = json_decode($output);
$challengeToken = $res->result->token;

$generatedKey = md5($challengeToken . $userAccessKey);
$params = array(
    "operation" => 'login',
    "username" => $userName,
    "accessKey" => $generatedKey,
);

$postData = '';
foreach ($params as $k => $v) {
      $postData .= $k . '=' . $v . '&';
}
$postData = rtrim($postData, '&');
$url = $endURL . '/webservice.php';
$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);
$res = json_decode($output);

$sessionName = $res->result->sessionName;
$userId = $res->result->userId;

$domain_name = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
$selectQuery = urlencode("SELECT title,firstname,lastname FROM Contacts;");
$url = $endURL . '/webservice.php?operation=query&query=' . $selectQuery . '&sessionName=' . $sessionName;
$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, 0);
$output = curl_exec($ch);
curl_close($ch);
$res = json_decode($output);
echo "<pre>";
print_r($res);
exit;

结果

stdClass Object
(
    [success] => 1
    [result] => Array
        (
            [0] => stdClass Object
                (
                    [title] => 
                    [firstname] => asdfas
                    [lastname] => dfdsafdsf
                    [id] => 12x3
                )

        )

)
于 2017-11-13T07:31:10.060 回答