Your IP : 3.14.248.199


Current Path : /var/www/u0635749/data/bitrix24.hobbyclick.ru/smstraffic-sms/commands/
Upload File :
Current File : /var/www/u0635749/data/bitrix24.hobbyclick.ru/smstraffic-sms/commands/addMessageService.php

<?php

require_once __DIR__ .  "/../vendor/autoload.php";
require_once __DIR__ .  "/../config/mainConfig.php";
require_once __DIR__ .  "/../loggerInit.php";

$b24Config = json_decode(file_get_contents(__DIR__ . "/../config/b24Config.json"), true);

try {
    $obB24App = new \Bitrix24\Bitrix24(false, $logger);
    $obB24App->setApplicationId($b24Config["applicationId"]);
    $obB24App->setApplicationSecret($b24Config["applicationCode"]);
    $obB24App->setApplicationScope($b24Config["applicationScope"]);
    $obB24App->setDomain($b24Config["b24name"] . ".bitrix24.ru");
    $obB24App->setMemberId($b24Config["memberId"]);
    $obB24App->setAccessToken($b24Config["accessToken"]);
    $obB24App->setRefreshToken($b24Config["refreshToken"]);
    $obB24App->setRedirectUri($b24Config["redirectUri"]);
    
    if ($obB24App->isAccessTokenExpire()) {
        $requestResult = $obB24App->getNewAccessToken();
        $obB24App->setAccessToken($requestResult["access_token"]);

        $b24Config["accessToken"] = $requestResult["access_token"];
        $b24Config["refreshToken"] = $requestResult["refresh_token"];

        file_put_contents(__DIR__ . "/../config/b24Config.json", json_encode($b24Config));
    }

    $messageServiceObj = new \Bitrix24\MessageService\MessageService($obB24App);
    $messageServiceParams = [
        'CODE' => 'smstraffic',
        'TYPE' => 'SMS',
        'HANDLER' => $messageServiceHandlerUrl,
        'NAME' => 'СМС (smstraffic.ru)',
        'DESCRIPTION' => 'Отправка СМС через провайдера www.smstraffic.ru'
    ];
    $b24Response = $messageServiceObj->add($messageServiceParams);

    print_r($b24Response);

    $logger->debug('B24 messageservice add response', ['response' => $b24Response]);
	$logger->debug('log request1', print_r(['b24Config' => $b24Config,"get"=>$_GET, "post"=>$_POST],true));
}
catch (\Bitrix24\Exceptions\Bitrix24TokenIsExpiredException $e) {
    $errorMsg = 'Истек срок действия access и refresh токенов';
    $logger->error($errorMsg, ['b24Config' => $b24Config]);
} 
catch (Exception $e) {
    $errorMsg = $e->getMessage();
    $logger->error($errorMsg, []);
}