我正在尝试使用 vTiger REST API,但我一直在碰壁 - 我无法通过登录身份验证(!)。
我已经按照指南和说明做了所有事情,但是应该是一个相当简单的过程却不起作用,总是给我带来同样的错误。
我已经通过 python 和 php 在两个不同的服务器上使用它,但结果是相同的。
我究竟做错了什么?
PHP代码:
<?php
$usercode = 'x5pox9oihbjp1pna';
$service_url = '<VTIGER ROOT>/webservice.php';
$curl = curl_init($service_url);
$curl_post_data = array(
'operation'=> 'getchallenge',
'username' => 'admin',
);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
curl_setopt($curl ,CURLOPT_SSL_VERIFYPEER, false); //one server is ssl so i use this, the other isn't so i discard this when i try that one.
$curl_response = curl_exec($curl);
curl_close($curl);
echo "<p> First response: $curl_response<p>";
$x = json_decode($curl_response);
$token = var_export($x->result->token, true);
$token = substr($token, 1, -1); //getting rid of excess quote marks
echo "<p> token: $token </p>";
echo "<p> finished part 1 of php script</p>";
$combined = $token.$usercode;
echo "<p> token: $token </p>";
echo "<p> userAccessKey: $usercode </p>";
echo "<p> token + userAccessKey: $combined </p>";
$accessKeyHash= md5($combined);
echo "<p>Full Acces Key Hash: $accessKeyHash</p>";
$curl = curl_init($service_url);
$curl_post_data = array(
'operation'=> 'login',
'username' => 'admin',
'accessKey' => $accessKeyHash
);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
curl_setopt($curl ,CURLOPT_SSL_VERIFYPEER, false);
$curl_response = curl_exec($curl);
curl_close($curl);
echo "<p> Second response: $curl_response<p>";
echo "<p> finished part 2 of php script</p>";
对此的输出是:
第一个响应:{"success":true,"result":{"token":"591432eb404da","serverTime":1494495979,"expireTime":1494496279}}
代币:591432eb404da
完成了 php 脚本的第 1 部分
代币:591432eb404da
用户访问密钥:x5pox9oihbjp1pna
令牌 + 用户访问密钥:591432eb404dax5pox9oihbjp1pna
完全访问密钥哈希:07700eafa6aea78c2602d84fc83b3f73
第二个响应:{"success":false,"error":{"code":"INVALID_AUTH_TOKEN","message":"Specified token is invalid or expired"}}
完成了 php 脚本的第 2 部分