Witam. chciałem zalogować się do aplikacji ewelink. Założyłem tymczasowe konto demo. więc śmiało można się logować. Napisałem pewien kod ale nie loguje. Chcę potem dodać do zadań crona aby co godzinę wywoływać. Tu jest odpowiedź serwera przy logowaniu przez przeglądarkę. Oczywiście z udanym zalogowaniem się.
scheme https
host eu-apia.coolkit.cc
filename /v2/user/login
Adres 3.66.241.255:443
Stan 200OK
Wersja HTTP/2
Przesłano 683 B (o rozmiarze 443 B)
Zasada polecającego strict-origin-when-cross-origin
Priorytet żądania Highest
access-control-allow-credentials true
access-control-allow-origin https://web.ewelink.cc
content-length 443
content-type application/json
date Wed, 14 Dec 2022 10:16:19 GMT
server awselb/2.0
X-Firefox-Spdy h2
Accept application/json, text/plain, */*
Accept-Encoding gzip, deflate, br
Accept-Language pl,en-US;q=0.7,en;q=0.3
Authorization Sign pTBgLB1qL0RaUUozITN6EXQnuJCRUMY+qN45GKsLlLI=
Connection keep-alive
Content-Length 91
Content-Type application/json
Host eu-apia.coolkit.cc
Origin https://web.ewelink.cc
Referer https://web.ewelink.cc/
Sec-Fetch-Dest empty
Sec-Fetch-Mode cors
Sec-Fetch-Site cross-site
TE trailers
User-Agent Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0
X-CK-Appid vcMG8oLY9CMf3CGg7g8tKlvatvPnRw84
X-CK-Nonce PORLXeyS
A tutaj jest mój kod PHP
<?php
ini_set( 'display_errors', 'On' );
error_reporting( E_ALL );
$random_string= substr(md5(time()), 0, 8);
define('USER_AGENT', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:106.0) Gecko/20100101 Firefox/106.0'); // Set a user agent.
define('COOKIE_FILE','/home/pi/ewe.cookie');
define('LOGIN_FORM_URL', 'https://eu-apia.coolkit.cc/'); // 16-06-2022: URL of the login form.
$continue=true;
$HEADER = array(
'Content-Type' => 'application/json',
'Accept' => 'application/json, text/plain, */*',
'Accept-language' =>'pl,en-US;q=0.7,en;q=0.3',
'Referer'=>'https://web.ewelink.cc/',
'Authorization'=>'Sign pTBgLB1qL0RaUUozITN6EXQnuJCRUMY+qN45GKsLlLI=',
'X-CK-Appid'=>'vcMG8oLY9CMf3CGg7g8tKlvatvPnRw84',
'Host'=>'eu-apia.coolkit.cc',
'X-CK-Nonce'=>$random_string
);
// var_dump($HEADER);
$postValues = array(
'lang' => 'en',
'countryCode' => '+48',
'password' =>'1Zxcvbnm1,',
'email'=>'[email protected]'
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_COOKIELIST, "ALL");
curl_setopt($curl, CURLOPT_URL, 'https://eu-apia.coolkit.cc/v2/user/login'); // Set the URL that we want to send our POST request to. In this case, it's the action URL of the login form.
curl_setopt($curl, CURLOPT_POST, true); // Tell cURL that we want to carry out a POST request.
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($postValues)); // Set our post fields / date (from the array above).
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // We don't want any HTTPS errors.
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // We don't want any HTTPS errors.
curl_setopt($curl, CURLOPT_COOKIEJAR, COOKIE_FILE); // Where our cookie details are saved.
// This is typically required for authentication, as the session ID is usually saved in the cookie file.
curl_setopt($curl, CURLOPT_HTTPHEADER, $HEADER);
curl_setopt($curl, CURLOPT_COOKIEFILE, COOKIE_FILE);
curl_setopt($curl, CURLOPT_USERAGENT, USER_AGENT); // Sets the user agent. Some websites will attempt to block bot user agents. //Hence the reason I gave it a Chrome user agent.
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Tells cURL to return the output once the request has been executed.
curl_setopt($curl, CURLOPT_REFERER, LOGIN_FORM_URL); // Allows us to set the referer header. In this particular case,
// we are fooling the server into thinking that we were referred by the login form.
curl_setopt ($curl, CURLOPT_SSLVERSION, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
$result=curl_exec($curl); // Execute the login request.
if(curl_errno($curl)){
switch ($http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE)) {
case 200: $continue=true;# OK
echo $http_code;
break;
case 302: $continue=true;# OK
echo $http_code;
break;
default: $continue=false;
echo $http_code;
}
}
curl_close($curl);
echo $result;
?>