bjb-uim.php 4.99 KB
<?php
// irul @ 20200522

/**
 * Fake bjb UIM
 * Dibuat berdasarkan Draft Spesifikasi API UIM v1.0
 */

class bjbUIM
{
    public static function login()
    {
        // PAYLOAD:
        // {
        //     "userId": "I816",
        //     "password": "eyJpdiI6IjQzK2N6NXpxVTFiTEJ0ajR0WVwva2tnPT0iLCJ2YWx1ZSI6InlyeEU4M1BibHNNTXg1XC9xU3NwS3NBUjBMXC9jdUtwejBQc0hoQU1WdnB0ST0iLCJtYWMiOiIzNDdiY2Q5MGFmZjViNGY0YWVmNDNiNzNkN2EyZmMwYzc0NzdlMjUzODRmMDlkOGM4ZDVlZWVhMGY0MGNlODA0In0=",
        //     "appId": 148
        // }

        $rawData = file_get_contents("php://input");
        $payload = json_decode($rawData, true);
        if (!$payload) {
            self::echo_json(self::error_response());
        } else {
            extract($payload);
            if (!isset($userId) || !isset($password) || !isset($appId)) {
                self::echo_json(self::error_response());
            } else {
                self::echo_json(self::login_response());
            }
        }
    }

    private static function login_response()
    {
        $fake_response = array(
            'status'   => 'success',
            'rc'       => '00',
            'response' => array(
                'nama'             => 'ANDRI MUHAMAD RAMADHAN SATRIA RASPATI',
                'nip'              => '15.88.9871',
                'userId'           => 'I816',
                'kodeCabang'       => 'P060',
                'namaCabang'       => 'GRUP HEAD OFFICE APPLICATION',
                'kodeInduk'        => 'P009',
                'namaInduk'        => 'DIVISI TEKNOLOGI INFORMASI',
                'kodeKanwil'       => 'K001',
                'namaKanwil'       => 'KANWIL 1',
                'jabatan'          => 'STAF G4',
                'posisiPenempatan' => '-',
                'hp'               => '085624203225',
                'email'            => 'araspati@bankbjb.co.id',
                'kodeGrade'        => '0085',
                'namaGrade'        => 'G4',
                'idFungsi'         => '495',
                'fungsiTambahan'   => '-',
                'limitDebet'       => '0',
                'limitKredit'      => '0',
                'id'               => '20151002103451P0938539',
            ),
            'message'  => 'Transaction success.',
        );

        return $fake_response;
    }

    private static function error_response()
    {
        // error required user id
        $error[] = array(
            'status'   => 'warning',
            'rc'       => '62',
            'response' => array(
                'userId' => array(
                    0 => 'The user id field is required.',
                ),
            ),
            'message'  => 'Expect required condition(s) but not given in the request parameter(s).',
        );

        // error required password
        $error[] = array(
            'status'   => 'warning',
            'rc'       => '62',
            'response' => array(
                'password' => array(
                    0 => 'The password field is required when user id is present.',
                ),
            ),
            'message'  => 'Expect required condition(s) but not given in the request parameter(s).',
        );

        // error required app id
        $error[] = array(
            'status'   => 'warning',
            'rc'       => '62',
            'response' => array(
                'appId' => array(
                    0 => 'The app id field is required.',
                ),
            ),
            'message'  => 'Expect required condition(s) but not given in the request parameter(s).',
        );

        // error wrong password
        $error[] = array(
            'status'   => 'warning',
            'rc'       => '63',
            'response' => 'not_valid_credentials',
            'message'  => 'Credentials is not valid. Please provide a correct credentials.',
        );

        // error app id is not found
        $error[] = array(
            'status'   => 'info',
            'rc'       => '44',
            'response' => array(),
            'message'  => 'The requested resource is not found.',
        );

        // error client not registered yet
        $error[] = array(
            'status'   => 'warning',
            'rc'       => '52',
            'response' => 'client_server_not_registered',
            'message'  => 'Unregister client server trying to access server.',
        );

        // error client got blacklist
        $error[] = array(
            'status'   => 'warning',
            'rc'       => '43',
            'response' => 'server_blacklisted',
            'message'  => ' Cannot continue the transaction. Forbidden Access.',
        );

        $random_number = rand(0, count($error) - 1);
        return $error[$random_number];
    }

    private static function echo_json($data = array())
    {
        header('Content-type: application/json');
        echo json_encode($data) . PHP_EOL;
    }

    private static function echo_text($data = '')
    {
        header('Content-type: text/html; charset=UTF-8');
        echo $data . PHP_EOL;
    }
}