N
N
NiCnameqqww2019-07-15 20:25:52
Laravel
NiCnameqqww, 2019-07-15 20:25:52

Laravel integration with 1s?

Hello, does anyone know how to integrate laravel c 1c.
I tried to upload goods to the site according to the 1c documentation, initialization does not go through the routes, so far I have done it without routes and a controller in a simple php file, but I would like to do everything through the controller. If anyone has experienced this before, please help.
Here is my controller (in which only the first two requests checkauth and init work)

public function exchange(Request $request) {
        $cookieName = config('session.cookie');
        $cookieID = Session::getId();
        $csrf = csrf_token();
        $date = date('Y-m-d H:m:s');
       
        if($request->get('type') == 'catalog')
        {
            switch ($request->mode)
            {
                case 'checkauth':
                    $user = $_SERVER['PHP_AUTH_USER'];
                    $pass = $_SERVER['PHP_AUTH_PW'];
                    if(Auth::attempt(['email' => $user, 'password' => $pass]))
                    {
                        return response("success\n$cookieName\n$cookieID\n$csrf\n$date")
                            ->header("Content-Type" ,"text/plane; charset=UTF-8");
                    };
                case "init":

                    return response("no\nfile_limit=100000000000\nsessid=$cookieID\nversion=3.1")
                        ->header("Content-Type" ,"text/plane; charset=UTF-8");

                case "file":
                    
                    $filename = $request->get('filename');
                    $file_content = file_get_contents('php://input');
                    Storage::disk('public')->put('file.txt', 'Contents');
            }
        }
       
    }

this is my controller route
Route::any('/1c_exchange.php', '[email protected]');

and this is my 1c_exchange.php file in which everything works
<?php
$user	= "admin";
$pass	= "admin";
$path	= "upload/";

if (!isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER["PHP_AUTH_PW"]) && !isset($_REQUEST["type"])) {
    header('WWW-Authenticate: Basic realm="1C-Exchange"');
    header('HTTP/1.0 401 Unauthorized');
    $_SESSION["login"] = false;
    die("failure");
}

if (($_SERVER["PHP_AUTH_USER"] == $user && $_SERVER["PHP_AUTH_PW"] == $pass) || $_SESSION["login"]) {
    $_SESSION["login"] = true;
    if ($_REQUEST["type"] == "catalog") {
        switch ($_REQUEST["mode"]):
            case "checkauth":
                die("success");
                break;
            case "init":
                die("zip=no" . "\r\n" . "file_limit=0");
                break;
            case "file":
                $filename = (strpos($_REQUEST["filename"], ".") == 0) ? substr($_REQUEST["filename"], 1) : $_REQUEST["filename"];
                $dirname = dirname($path . $filename);
                if (!is_dir($dirname))
                    mkdir($dirname, 0755, true);
                $file = fopen($path . $filename, 'ab') or die("failure");
                fwrite($file, file_get_contents('php://input'));
                fclose($file);
                die("success");
                break;
        endswitch;
    }
    if ($_REQUEST["type"] == "sale") {

    }
} else {
    header('WWW-Authenticate: Basic realm="1C-Exchange"');
    header('HTTP/1.0 401 Unauthorized');
    $_SESSION["login"] = false;
    die("failure");
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Melnikov, 2019-07-15
@Mi11er

What's the problem ?
You make API either on the 1C side or on the site side.
Upload in any convenient format and life is good =)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question