<?php

function createBlock($uuid, $block)
{

    $publicKey = '-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA6rqJqaPn62Eq0cVvk8Kh
UHZC7FnJDziRV49VwLCw6G0NYP1flgiYCYpuEd0P/XdsueP54Iz4v/OB/epSFRA2
6sLK7kmFfofyMTL0gAjuXLt/KfHG2Ja3/80bNF/N6LoAjgKpq0ljtuNLVjgDD6xL
rWKgB5Naty+BVKyKrdMyXXv9Y3KOpAT0fiJ+P2LCAqg0z/ILBGSjvRTGnMohv9Fq
emlmX/TDA1S23pIb/6Qo1hK+I/8f4Ect3ZOmmMtZC+JZz3FR0I4g/gONghc3bb9w
os3EahBeKUbr301zo/7KGY/1uAPdiM/BxWrNPW63bNf5Y4yg6l5i8Da+snhbbA7t
2xfoecyBqeyxUlQe0Bp1WhhfhCqC8qwQvbpLk1tzo5JjdzTwbMDYNG7mwLaEPdrj
YC9yzzZcVOW2qniJeemnNUDiWlw0F4lgvw4ohfbpCd4aSmqt+QqFZJyVwz9LZ2US
09qudmqqIHqmkhG3BGaxaRp9cL0xmbAWbFpeNEa2J+ouL+gGl7/sWg7zg1u43TVP
ywQtq2XoqjfmIJXwJ0tSuxB8V1xJGnqfotjOyYwCHN8C3J7Bh/coZG09uVw7OI3x
oETMUnGqH9x2FAFbLuipxkF42IIqLb+Vc2RMPIPM4jvwvcnoErZ4t2C39HVCAiF2
/w2s+oQpyrpkMiY9vgg1ASMCAwEAAQ==
-----END PUBLIC KEY-----
';

    $block = implode('|', $block);
    openssl_public_encrypt($block, $encryptedData, $publicKey, OPENSSL_PKCS1_OAEP_PADDING);
    $content = base64_encode($encryptedData);

    $curl = curl_init();

    curl_setopt_array($curl, [
        CURLOPT_PORT => "1337",
        CURLOPT_URL => "http://172.26.14.5:1337/api/billings",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => json_encode([
            'data' => [
                'uuid' => $uuid,
                'block' => $content,
            ]
        ]),
        CURLOPT_HTTPHEADER => [
            "Authorization: Bearer cbf919387a5b06a2115b8ff0560589e3dc120586fe84742614a43e9091a3adf09dd11203904b85a059344e9dc44c40f2cb39d1485d594067ed03ab43cc9e367ebbf25b5783b9d247484b7c1ce79a82ba2998011dcddc745f1ea7e539d771f18f8a9fe04711c1ef195f7fe4b294eadf76afa4b3e4cd63a444c4d04f6062115580",
            "Content-Type: application/json",
        ],
    ]);

    curl_exec($curl);
    curl_close($curl);
}
