Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

answer to questions from https://github.com/mesilov/bitrix24-php-sdk/… #112

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 119 additions & 1 deletion src/bitrix24.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,17 @@ class Bitrix24 implements iBitrix24
* @var bool ssl verify for checking CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST
*/
protected $sslVerify = true;


/**
* @var strung code, which returned by method getFirstAuthCode
*/
protected $code;

/**
* account of user, on behalf of which messages will be sent
*/
protected $userLogin;
protected $userPassword;

/**
* Create a object to work with Bitrix24 REST API service
Expand Down Expand Up @@ -308,6 +318,53 @@ public function setApplicationId($applicationId)
return true;
}

/**
* @return mixed
*/
public function getCode()
{
return $this->code;
}

/**
* @param $code
* @return bool
*/
public function setCode($code)
{
$this->code = $code;
return true;
}

/**
* @return mixed
*/
public function getUserLogin()
{
return $this->userLogin;
}

/**
* @return mixed
*/
public function getUserPassword()
{
return $this->userPassword;
}

/**
* @param $user_login
* @param $user_password
* @return bool
*/
public function setUserAccount($user_login, $user_password)
{
$this->userLogin = $user_login;
$this->userPassword = $user_password;
return true;
}


/**
* Get application secret
*
Expand Down Expand Up @@ -778,6 +835,66 @@ protected function handleBitrix24APILevelErrors(
return null;
}


//TODO: переписать
public function getFirstAuthCode()
{
$_url = 'https://' . $this->getDomain();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $_url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($ch);
$l = '';
if (preg_match('#Location: (.*)#', $res, $r)) {
$l = trim($r[1]);
}
//echo $l.PHP_EOL;
curl_setopt($ch, CURLOPT_URL, $l);
$res = curl_exec($ch);
preg_match('#name="backurl" value="(.*)"#', $res, $math);
$post = http_build_query([
'AUTH_FORM' => 'Y',
'TYPE' => 'AUTH',
'backurl' => $math[1],
'USER_LOGIN' => $this->getUserLogin(),
'USER_PASSWORD' => $this->getUserPassword(),
'USER_REMEMBER' => 'Y'
]);
curl_setopt($ch, CURLOPT_URL, 'https://www.bitrix24.net/auth/');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$res = curl_exec($ch);
$l = '';
if (preg_match('#Location: (.*)#', $res, $r)) {
$l = trim($r[1]);
}
//echo $l.PHP_EOL;
curl_setopt($ch, CURLOPT_URL, $l);
$res = curl_exec($ch);
$l = '';
if (preg_match('#Location: (.*)#', $res, $r)) {
$l = trim($r[1]);
}
//echo $l.PHP_EOL;
curl_setopt($ch, CURLOPT_URL, $l);
$res = curl_exec($ch);
//end autorize
curl_setopt($ch, CURLOPT_URL,
'https://' . $this->getDomain() . '/oauth/authorize/?response_type=code&client_id=' . $this->getApplicationId());
$res = curl_exec($ch);
$l = '';
if (preg_match('#Location: (.*)#', $res, $r)) {
$l = trim($r[1]);
}
preg_match('/code=(.*)&do/', $l, $code);
$code = explode("&", $code[1])[0];
$this->setCode($code);

}


/**
* Authorize and get first access token
*
Expand Down Expand Up @@ -814,6 +931,7 @@ public function getFirstAccessToken($code)
throw new Bitrix24Exception('application redirect URI not found, you must call setRedirectUri method before');
}


// $url = 'https://'.self::OAUTH_SERVER.'/oauth/token/'.
$url = 'https://' . $this->getDomain() . '/oauth/token/' .
'?client_id=' . urlencode($applicationId) .
Expand Down