$login = $options->vkLogin;
$password = $options->vkPassword;
$groupId = $options->vkGroupId;
if (!$login || !$password || !$groupId)
{
return;
}
$client = $this->app->http()->client();
try
{
$response = \GuzzleHttp\json_decode($client->request(
'GET',
"https://oauth.vk.com/token?grant_type=password&scope=wall&client_id=2274003&client_secret=hHbZxrka2uZ6jB1inYsH&2fa_supported=0&username={$login}&password={$password}"
)->getBody()->getContents(), true);
}
catch(\GuzzleHttp\Exception\RequestException $e)
{
\XF::logException($e, false, "Error post message to VK group: ");
return;
}
if (isset($response['access_token']))
{
$token = $response['access_token'];
}
else
{
return;
}
$message = \XF::phrase('vk_message');
$vk = new VKApiClient('5.92');
try
{
$vk->wall()->post($token, [
'owner_id' => (substr($groupId, 0, 1) != '-') ? '-' . $groupId : $groupId,
'message' => $message,
'from_group' => 1
]);
}
catch(\VK\Exceptions\VKClientException $e)
{
\XF::logException($e, false, "Error post message to VK group: ");
return;
}