我试图自动登录Zoho CRM。我正在尝试使用我的数据在http调用中登录,但看起来它不起作用。我想知道是否有人实现了这一点。
我尝试了什么:
张贴到https://accounts.zoho.com/login
身体:
{
LOGIN_ID: "username",
PASSWORD: "password",
IS_AJAX: "true",
remember :-1,
servicename: "ZohoCRM"
}
我收到的回复:状态200
showErrorAndReload('Please\x20reload\x20the\x20page\x20and\x20try\x20again.');
我最近不得不做大量的研究和试验和错误来解决这个问题。一定要使用Postman或其他东西来测试你的应用程序。
iamcsr
从您收到的cookie获取https://accounts.zoho.com/
值
Here is what the value looks like
注意:您无法重复使用或硬编码该值。您的应用必须在每次登录时生成它。POST
它。
login_id
=您的Zoho帐户登录
password
=您的Zoho帐户密码
unix_timestamp
=生成当前的unix时间戳,以毫秒为单位
iamcsr
=从cookie收到的价值
remember
,servicename
和serviceurl
的参数值始终保持不变。
https://accounts.zoho.com/signin/auth?LOGIN_ID={login_id}&PASSWORD={password}&cli_time={unix_timestamp}&remember=2592000&iamcsrcoo={iamcsr}&servicename=AaaServer&serviceurl=https://accounts.zoho.com/u/
要验证您是否已成功登录,您将收到以下响应:
showsuccess('https\x3A\x2F\x2Faccounts.zoho.com\x2Fu\x2F',"",'', '', '-1', 'dXM\x3D');
这将引导您完成登录部分,并将验证您的进一步操作,假设您的应用程序已存储当前会话的Cookie。
我根据Christian Barahona的回答制作了一个Php脚本:
$useragent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36';
$cookie_file_path = 'cookie.txt';
$curl = curl_init('https://accounts.zoho.com/signin?servicename=AaaServer&serviceurl=%2Fu%2Fh/');
curl_setopt($curl, CURLOPT_USERAGENT, $useragent);
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl,CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_COOKIEJAR,
$cookie_file_path);
curl_exec($curl);
//Read cookies file
$cookies = curl_getinfo($curl, CURLINFO_COOKIELIST);
foreach ($cookies as $cookie){
$splitted=preg_split('/\s+/',$cookie);
if($splitted[0]=="accounts.zoho.com"){
if($splitted[sizeof($splitted)-2]=="iamcsr"){
$iamscr=$splitted[sizeof($splitted)-1];
}
}
}
//return current unix timestamp in milliseconds
function milliseconds() {
$mt = explode(' ', microtime());
return ((int)$mt[1]) * 1000 + ((int)round($mt[0] * 1000));
}
$postValues = array(
'LOGIN_ID' => '*******',
'PASSWORD' => '*******',
'cli_time'=> milliseconds(),
'remember'=> '2592000',
'iamcsrcoo'=> $iamscr,
'servicename'=> 'AaaServer',
'serviceurl'=> 'https://accounts.zoho.com/u/h'
);
$postValuesFormatted = http_build_query($postValues);
curl_setopt($curl, CURLOPT_URL, 'https://accounts.zoho.com/signin/auth');
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postValuesFormatted);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_exec($curl);
curl_setopt($curl, CURLOPT_URL, 'https://accounts.zoho.com/u/h');
curl_setopt($curl, CURLOPT_POST, false);
$result = curl_exec($curl);