ตัวอย่างการใช้งาน API

PHP

                                $url = 'URL';
                                $apiKey = "Your Access Token";
                                $saltKey = "Your Text Salt";

                                $ch = curl_init($url);

                                $data =json_encode(
                                    [
                                        'citizen_id'=>'3349900198397',
                                        'salt'=> $saltKey,
                                        'cipher'=>'AES-256-CBC'
                                    ]
                                );

                                curl_setopt($ch,CURLOPT_POST, true);
                                curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

                                $headers = [];
                                $headers[] = 'Content-Type:application/json';
                                $headers[] = "Authorization: Bearer ".$apiKey;
                                curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

                                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

                                $result = curl_exec($ch);

                                curl_close($ch);

                                echo $result;

                                function ApiDecrypt($getCipher, $getSalt, $encrypted)
                                {
                                    $frameware = $encrypted;
                                    $encrypt_method = $getCipher;
                                    $secret_key = $getSalt;
                                    $secret_iv = $getSalt;

                                    $key = hash('sha256', $secret_key);

                                    $iv = substr(hash('sha256', $secret_iv), 0, 16);

                                    $decryptToken = openssl_decrypt(base64_decode($frameware), $encrypt_method, $key, 0, $iv);
                                    return $decryptToken;

                                    // กรณีต้องการข้อมูลรูปแบบ Array
                                    $decryptTokenArray = json_decode($decryptToken, 1);
                                    return $decryptTokenArray;
                                }
                            
ติดต่อสอบถามข้อมูล

กระทรวงแรงงาน
ถนนมิตรไมตรี แขวงดินแดง เขตดินแดง กรุงเทพมหานคร 10400
Email: e-office@mol.mail.go.th
โทรศัพท์: 0 2232 1462-3, 1467